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

85 lines
3.3 KiB
Text
Raw Normal View History

2016-03-23 19:30:43 +01:00
#! /bin/bash
2016-04-04 22:35:43 +02:00
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
2016-04-26 20:17:50 +02:00
# causes the shell to exit if you try to use an uninitialised variable
set -u
2016-04-04 22:35:43 +02:00
2016-05-23 21:40:55 +02:00
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
2016-04-26 20:37:18 +02:00
2016-04-26 20:17:50 +02:00
# retrieve arguments
2016-05-23 21:40:55 +02:00
if [ $ynh_version = "2.4" ]; then
app=$YNH_APP_INSTANCE_NAME
else
app=bozon
fi
2016-04-26 20:17:50 +02:00
path=$(sudo yunohost app setting $app path)
stable=$(sudo yunohost app setting $app version)
is_public=$(sudo yunohost app setting $app is_public)
2016-04-26 20:59:30 +02:00
filesize=$(sudo yunohost app setting $app filesize)
2016-04-26 21:12:33 +02:00
domain=$(sudo yunohost app setting $app domain)
2016-04-26 20:59:30 +02:00
if [ "${#filesize}" -eq 0 ]
then # in old script filesize was not saved as an setting
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
2016-04-26 20:17:50 +02:00
# definie useful vars
2016-04-04 20:01:54 +02:00
parent_path=/var/www
2016-04-05 20:03:26 +02:00
data_path=/home/yunohost.app/$app
final_path=$parent_path/$app
2016-03-23 19:30:43 +01:00
2016-04-26 20:17:50 +02:00
# retrieve stable version of bozon
stable=$(cat ../BoZoN-stable)
2016-04-26 20:39:15 +02:00
# save app settings
sudo yunohost app setting $app version -v "$stable"
2016-04-26 20:17:50 +02:00
# 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
## path
folder_path=${path%/}
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
2016-05-23 20:59:08 +02:00
sudo sed -i "s@YNH_EXAMPLE_ALIAS@$final_path@g" ../conf/nginx.conf
sudo sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/nginx.conf
2016-05-23 20:59:08 +02:00
## file upload size limit
sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf
## copy final
2016-04-26 20:17:50 +02:00
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
2016-03-23 19:30:43 +01:00
2016-05-23 20:59:08 +02:00
# copy and set php-fpm configuration
## path
sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/php-fpm.conf
sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/php-fpm.conf
## file upload size limit
sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf
postsize=${filesize%?}.1${filesize: -1}
sudo sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf
## copy final and set permissions
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
sudo chown root: $phpfpm_conf
sudo chmod 644 $phpfpm_conf
2016-04-26 20:17:50 +02:00
# 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
2016-03-23 19:30:43 +01:00
# Restart services
2016-05-23 20:59:08 +02:00
sudo service php5-fpm restart || true
sudo service nginx restart || true
2016-03-23 19:30:43 +01:00
sudo yunohost app ssowatconf