2017-01-08 12:17:57 +01:00
|
|
|
#!/bin/bash
|
2016-03-23 19:30:43 +01:00
|
|
|
|
2020-01-05 19:49:24 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2017-07-26 21:32:00 +02:00
|
|
|
set -eu
|
2017-07-03 21:07:56 +02:00
|
|
|
source _common.sh
|
2016-10-13 06:51:38 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2016-04-26 20:37:18 +02:00
|
|
|
|
2020-01-05 19:49:24 +01:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2016-10-13 06:51:38 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2020-01-05 19:49:24 +01:00
|
|
|
domain=$(ynh_app_setting_get --app="$app" --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app="$app" --key=path)
|
|
|
|
is_public=$(ynh_app_setting_get --app="$app" --key=is_public)
|
|
|
|
admin_user=$(ynh_app_setting_get --app="$app" --key=admin_user)
|
|
|
|
backup_core_only=$(ynh_app_setting_get --app="$app" --key=backup_core_only)
|
|
|
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
|
|
|
data_path=$(ynh_app_setting_get --app="$app" --key=data_path)
|
2016-04-26 20:17:50 +02:00
|
|
|
|
2020-01-05 19:49:24 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
|
|
|
|
# If final_path doesn't exist, create it
|
|
|
|
if [ -z "$final_path" ]; then
|
|
|
|
final_path="/var/www/$app"
|
|
|
|
ynh_app_setting_set --app="$app" --key=final_path --value="$final_path"
|
|
|
|
fi
|
|
|
|
# If data_path doesn't exist, create it
|
|
|
|
if [ -z "$data_path" ]; then
|
|
|
|
data_path="/home/yunohost.app/$app"
|
|
|
|
ynh_app_setting_set --app="$app" --key=data_path --value="$data_path"
|
2017-07-03 21:07:56 +02:00
|
|
|
fi
|
|
|
|
|
2020-01-05 19:49:24 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2017-07-03 21:07:56 +02:00
|
|
|
|
2020-01-05 19:49:24 +01:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3
|
|
|
|
if [ -f "/etc/yunohost/apps/$app/scripts/backup" ]; then
|
|
|
|
ynh_backup_before_upgrade # Backup the current version of the app
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2016-04-26 20:39:15 +02:00
|
|
|
|
2020-01-05 19:49:24 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]; then
|
|
|
|
# download & unpack bozon
|
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=2
|
|
|
|
## download source
|
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
ynh_setup_source --dest_dir="$tmpdir"
|
|
|
|
## clean & copy files needed to final folder
|
|
|
|
myynh_clean_source
|
|
|
|
[ -e "$tmpdir/config.php" ] && rm "$tmpdir/config.php"
|
|
|
|
cp -a "$tmpdir/." "$final_path"
|
|
|
|
rm -R "$tmpdir"
|
|
|
|
## set permissions
|
|
|
|
myynh_set_permissions
|
|
|
|
fi
|
2016-04-26 20:17:50 +02:00
|
|
|
|
2020-01-05 19:49:24 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading nginx web server configuration..."
|
2018-05-26 14:44:52 +02:00
|
|
|
if [ "$path_url" != "/" ]; then
|
2020-01-05 19:49:24 +01:00
|
|
|
ynh_replace_string --match_string="^#sub_path_only" --replace_string="" --target_file="../conf/nginx.conf"
|
2018-05-26 14:44:52 +02:00
|
|
|
fi
|
2018-05-26 13:17:41 +02:00
|
|
|
ynh_add_nginx_config
|
2016-03-23 19:30:43 +01:00
|
|
|
|
2020-01-05 19:49:24 +01:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
ynh_system_user_create --username="$app"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading php-fpm configuration..."
|
2018-05-26 13:17:41 +02:00
|
|
|
ynh_add_fpm_config
|
2016-05-23 20:59:08 +02:00
|
|
|
|
2020-01-05 19:49:24 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading SSOwat configuration..."
|
|
|
|
if [ $is_public -eq 0 ]; then
|
2017-07-03 21:07:56 +02:00
|
|
|
# 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=$([ "$path_url" == "/" ] || echo "$path_url" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
|
|
|
|
regexList="${domainluaregex}${pathluaregex}/index%.php$","${domainluaregex}${pathluaregex}/index%.php%?p=.*$"
|
2020-01-05 19:49:24 +01:00
|
|
|
ynh_app_setting_set --app="$app" --key=protected_regex --value="$regexList"
|
2017-07-03 21:07:56 +02:00
|
|
|
else
|
2020-01-05 19:49:24 +01:00
|
|
|
ynh_app_setting_set --app="$app" --key=unprotected_uris --value="/"
|
2016-04-26 20:17:50 +02:00
|
|
|
fi
|
2016-03-23 19:30:43 +01:00
|
|
|
|
2020-01-05 19:49:24 +01:00
|
|
|
#=================================================
|
|
|
|
# CLEAN PHP SESSIONS STORED IN /var/lib/phpx/sessions
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Cleaning php sessions stored..."
|
2018-05-26 13:17:41 +02:00
|
|
|
if [ -d "/usr/lib/php5" ]; then
|
2020-01-05 19:49:24 +01:00
|
|
|
[ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean
|
2018-05-26 13:17:41 +02:00
|
|
|
elif [ -d "/usr/lib/php" ]; then
|
2020-01-05 19:49:24 +01:00
|
|
|
[ -x /usr/lib/php/sessionclean ] && /usr/lib/php/sessionclean
|
2018-05-26 13:17:41 +02:00
|
|
|
fi
|
2020-01-05 19:49:24 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading nginx web server..."
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|