mirror of
https://github.com/YunoHost-Apps/bozon_ynh.git
synced 2024-09-03 18:16:09 +02:00
138 lines
5.5 KiB
Bash
138 lines
5.5 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC STARTING
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
set -eu
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
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)
|
|
|
|
#=================================================
|
|
# 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"
|
|
fi
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
#=================================================
|
|
# 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" ] && ynh_secure_remove "$tmpdir/config.php"
|
|
cp -a "$tmpdir/." "$final_path"
|
|
ynh_secure_remove "$tmpdir"
|
|
## set permissions
|
|
myynh_set_permissions
|
|
fi
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading nginx web server configuration..."
|
|
if [ "$path_url" != "/" ]; then
|
|
ynh_replace_string --match_string="^#sub_path_only" --replace_string="" --target_file="../conf/nginx.conf"
|
|
fi
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# 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..."
|
|
ynh_add_fpm_config
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading SSOwat configuration..."
|
|
if [ $is_public -eq 0 ]; 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=$([ "$path_url" == "/" ] || echo "$path_url" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
|
|
regexList="${domainluaregex}${pathluaregex}/index%.php$","${domainluaregex}${pathluaregex}/index%.php%?p=.*$"
|
|
ynh_app_setting_set --app="$app" --key=protected_regex --value="$regexList"
|
|
else
|
|
ynh_app_setting_set --app="$app" --key=unprotected_uris --value="/"
|
|
fi
|
|
|
|
#=================================================
|
|
# CLEAN PHP SESSIONS STORED IN /var/lib/phpx/sessions
|
|
#=================================================
|
|
ynh_script_progression --message="Cleaning php sessions stored..."
|
|
if [ -d "/usr/lib/php5" ]; then
|
|
[ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean
|
|
elif [ -d "/usr/lib/php" ]; then
|
|
[ -x /usr/lib/php/sessionclean ] && /usr/lib/php/sessionclean
|
|
fi
|
|
|
|
#=================================================
|
|
# 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
|