1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/bozon_ynh.git synced 2024-09-03 18:16:09 +02:00
bozon_ynh/scripts/upgrade
2016-04-26 21:04:46 +02:00

69 lines
2.8 KiB
Bash

#! /bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
# causes the shell to exit if you try to use an uninitialised variable
set -u
app=bozon
# retrieve arguments
path=$(sudo yunohost app setting $app path)
stable=$(sudo yunohost app setting $app version)
is_public=$(sudo yunohost app setting $app is_public)
filesize=$(sudo yunohost app setting $app filesize)
if [ "${#filesize}" -eq 0 ]
then # in old script filesize was not saved as an setting
domain=$(sudo yunohost app setting $app domain)
filesize=$(cat /etc/nginx/conf.d/$domain.d/$app.conf | grep -Po 'client_max_body_size \K.*(?=;)')
sudo yunohost app setting $app filesize -v "$filesize"
fi
# definie useful vars
parent_path=/var/www
data_path=/home/yunohost.app/$app
final_path=$parent_path/$path
# retrieve stable version of bozon
stable=$(cat ../BoZoN-stable)
# save app settings
sudo yunohost app setting $app version -v "$stable"
# download stable version of bozon
sudo wget https://github.com/broncowdd/BoZoN/archive/$stable.zip -O $parent_path/bozon-$stable.zip
sudo unzip $parent_path/bozon-$stable.zip -d $parent_path/
sudo rm $parent_path/bozon-$stable.zip
sudo rsync -avz --exclude="config.php" --exclude=".htaccess" $parent_path/BoZoN-$stable/* $final_path
sudo rm -R $parent_path/BoZoN-$stable
# configure nginx settings
## file upload size limit
postsize=${filesize%?}.1${filesize: -1}
sudo sed -i "s@YNH_FILE_SIZE@$filesize@g" ../conf/nginx.conf
sudo sed -i "s@YNH_POST_SIZE@$postsize@g" ../conf/nginx.conf
## path
folder_path=${path%/}
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
# if path is only / (without subfolder), add trailing slash to alias
alias_path=$final_path
[ "$path" == '/' ] && alias_path=$alias_path'/'
sudo sed -i "s@YNH_EXAMPLE_ALIAS@$alias_path@g" ../conf/nginx.conf
sudo sed -i "s@YNH_EXAMPLE_FOLDER@$folder_path@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# if app is private, remove url to SSOWat conf from skipped_uris
if [ "$is_public" = "No" ];
then
# escape magic chars in vars (lua magic chars are ().%+-*?[^$ according to https://www.lua.org/pil/20.2.html)
domainluaregex=$(echo "$domain" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
pathluaregex=$(echo "$path" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
# redirect to SSOwat login in
sudo yunohost app setting $app unprotected_uris -d
sudo yunohost app setting $app unprotected_regex -v "$domainluaregex$pathluaregex/index.php%?f=.+$","$domainluaregex$pathluaregex/index.php%?zipfolder=.+$","$domainluaregex$pathluaregex/private/temp/.+%.zip$","$domainluaregex$pathluaregex/core/js/.*$","$domainluaregex$pathluaregex/templates/.*$"
fi
# Restart services
sudo service nginx reload
sudo yunohost app ssowatconf