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

74 lines
2.9 KiB
Text
Raw Normal View History

2016-03-23 19:30:43 +01:00
#! /bin/bash
2016-09-05 21:11:16 +02:00
# Exit on command errors and treat unset variables as an error
set -eu
# Source YunoHost helpers
source /usr/share/yunohost/helpers
2016-04-04 22:35:43 +02:00
2016-04-26 20:17:50 +02:00
# retrieve arguments
2016-10-11 20:16:36 +02:00
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
is_public=$(ynh_app_setting_get "$app" is_public)
filesize=$(ynh_app_setting_get "$app" filesize)
2016-04-26 20:17:50 +02:00
# definie useful vars
2016-04-04 20:01:54 +02:00
parent_path=/var/www
2016-10-11 20:16:36 +02:00
data_path=/home/yunohost.app/"$app"
final_path=$parent_path/"$app"
2016-10-11 20:34:08 +02:00
if [ -z "$filesize" ]
2016-10-11 20:16:36 +02:00
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.*(?=;)')
ynh_app_setting_set "$app" filesize "$filesize"
fi
2016-03-23 19:30:43 +01:00
2016-09-05 21:11:16 +02:00
# add required packages
2016-10-11 20:16:36 +02:00
ynh_package_install_from_equivs ../conf/"$app"-deps.control || ynh_die "Unable to install dependencies"
2016-09-05 21:11:16 +02:00
# download upstream_version version of bozon
2016-10-11 21:44:13 +02:00
upstream_version=$(cat ../conf/upstream_version)
2016-10-11 20:16:36 +02:00
wget -nc --quiet https://github.com/broncowdd/BoZoN/archive/"$upstream_version".zip -P /tmp
sudo unzip -oq /tmp/"$upstream_version".zip -d /tmp
2016-10-11 20:34:08 +02:00
sudo rsync -avz --exclude="config.php" --exclude=".htaccess" /tmp/BoZoN-"$upstream_version"/* "$final_path"
2016-04-26 20:17:50 +02:00
# configure nginx settings
2016-10-11 20:16:36 +02:00
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
sed -i "s@YNH_EXAMPLE_PATH@${path}@g" ../conf/nginx.conf
sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/nginx.conf
sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/nginx.conf
sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf "$nginx_conf"
2016-03-23 19:30:43 +01:00
2016-05-23 20:59:08 +02:00
# copy and set php-fpm configuration
2016-10-11 20:16:36 +02:00
postsize=${filesize%?}.1${filesize: -1}
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
2016-05-23 20:59:08 +02:00
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
2016-10-11 20:16:36 +02:00
sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf
2016-05-23 20:59:08 +02:00
sudo sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf
## copy final and set permissions
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
2016-10-11 20:16:36 +02:00
sudo chown root: "$phpfpm_conf"
sudo chmod 644 "$phpfpm_conf"
2016-05-23 20:59:08 +02:00
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
2016-10-11 20:16:36 +02:00
ynh_app_setting_delete "$app" unprotected_uris
ynh_app_setting_set "$app" unprotected_regex \
"${domainluaregex}${pathluaregex}/index.php%?f=.+$", \
"${domainluaregex}${pathluaregex}/index.php%?zipfolder=.+$", \
"${domainluaregex}${pathluaregex}/private/temp/.+%.zip$", \
"${domainluaregex}${pathluaregex}/core/js/.*$", \
"${domainluaregex}${pathluaregex}/templates/.*$"
2016-04-26 20:17:50 +02:00
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