mirror of
https://github.com/YunoHost-Apps/bozon_ynh.git
synced 2024-09-03 18:16:09 +02:00
151 lines
5 KiB
Bash
151 lines
5 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
admin_user=$(ynh_app_setting_get --app=$app --key=admin_user)
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
ynh_script_progression --message="Checking version..." --weight=1
|
|
|
|
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
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
# Restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
# Cleaning legacy permissions
|
|
if ynh_legacy_permissions_exists; then
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
fi
|
|
|
|
# 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 datadir doesn't exist, create it
|
|
if [ -z "$datadir" ]; then
|
|
datadir="/home/yunohost.app/$app"
|
|
ynh_app_setting_set --app="$app" --key=datadir --value="$datadir"
|
|
fi
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
|
|
|
# Create a dedicated user (if not existing)
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
#=================================================
|
|
# 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"
|
|
fi
|
|
|
|
## set permissions
|
|
myynh_set_permissions
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# PHP-FPM CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
|
|
|
|
# Create a dedicated PHP-FPM config
|
|
ynh_add_fpm_config
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1
|
|
|
|
if [ "$path_url" != "/" ]; then
|
|
ynh_replace_string --match_string="^#sub_path_only" --replace_string="" --target_file="../conf/nginx.conf"
|
|
fi
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# CLEAN PHP SESSIONS STORED IN /var/lib/phpx/sessions
|
|
#=================================================
|
|
ynh_script_progression --message="Cleaning php sessions stored..." --weight=1
|
|
|
|
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
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|