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

152 lines
5 KiB
Text
Raw Normal View History

#!/bin/bash
2016-03-23 19:30:43 +01:00
2020-01-05 19:49:24 +01:00
#=================================================
2022-07-28 03:39:57 +02:00
# GENERIC START
2020-01-05 19:49:24 +01:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2022-07-28 03:39:57 +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
#=================================================
2022-09-18 03:17:45 +02:00
ynh_script_progression --message="Loading installation settings..." --weight=1
2022-07-28 03:39:57 +02:00
2016-10-13 06:51:38 +02:00
app=$YNH_APP_INSTANCE_NAME
2016-04-26 20:17:50 +02:00
2022-07-28 03:39:57 +02:00
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)
2020-01-05 19:49:24 +01:00
#=================================================
# CHECK VERSION
#=================================================
2022-09-18 03:17:45 +02:00
ynh_script_progression --message="Checking version..." --weight=1
2022-07-28 15:28:59 +02:00
2020-01-05 19:49:24 +01:00
upgrade_type=$(ynh_check_app_version_changed)
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
2022-07-28 03:39:57 +02:00
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
2020-01-05 19:49:24 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2016-04-26 20:39:15 +02:00
#=================================================
2022-07-28 03:39:57 +02:00
# STANDARD UPGRADE STEPS
#=================================================
2022-07-28 03:39:57 +02:00
# 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
2022-07-28 03:39:57 +02:00
# 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
2020-01-05 19:49:24 +01:00
#=================================================
2022-07-28 03:39:57 +02:00
# CREATE DEDICATED USER
#=================================================
2022-09-18 03:17:45 +02:00
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
2022-07-28 03:39:57 +02:00
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
2020-01-05 19:49:24 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2022-07-28 03:39:57 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2020-01-05 19:49:24 +01:00
# 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
2020-11-09 16:07:27 +01:00
[ -e "$tmpdir/config.php" ] && ynh_secure_remove "$tmpdir/config.php"
2020-01-05 19:49:24 +01:00
cp -a "$tmpdir/." "$final_path"
2020-11-09 16:07:27 +01:00
ynh_secure_remove "$tmpdir"
2020-01-05 19:49:24 +01:00
fi
2016-04-26 20:17:50 +02:00
2022-07-28 03:39:57 +02:00
## set permissions
myynh_set_permissions
2016-03-23 19:30:43 +01:00
2020-01-05 19:49:24 +01:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2020-11-27 07:20:16 +01:00
ynh_script_progression --message="Upgrading dependencies..." --weight=1
2020-01-05 19:49:24 +01:00
2022-07-28 03:39:57 +02:00
ynh_install_app_dependencies $pkg_dependencies
2020-01-05 19:49:24 +01:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
2022-09-18 03:17:45 +02:00
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
2022-07-28 03:39:57 +02:00
# Create a dedicated PHP-FPM config
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
#=================================================
2022-07-28 03:39:57 +02:00
# NGINX CONFIGURATION
2020-01-05 19:49:24 +01:00
#=================================================
2022-09-18 03:17:45 +02:00
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1
2022-07-28 03:39:57 +02:00
if [ "$path_url" != "/" ]; then
ynh_replace_string --match_string="^#sub_path_only" --replace_string="" --target_file="../conf/nginx.conf"
2016-04-26 20:17:50 +02:00
fi
2022-07-28 03:39:57 +02:00
ynh_add_nginx_config
2016-03-23 19:30:43 +01:00
2022-07-28 03:39:57 +02:00
#=================================================
# SPECIFIC UPGRADE
2020-01-05 19:49:24 +01:00
#=================================================
# CLEAN PHP SESSIONS STORED IN /var/lib/phpx/sessions
#=================================================
2022-09-18 03:17:45 +02:00
ynh_script_progression --message="Cleaning php sessions stored..." --weight=1
2022-07-28 03:39:57 +02:00
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
2022-07-28 03:39:57 +02:00
#=================================================
# GENERIC FINALIZATION
2020-01-05 19:49:24 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2022-09-18 03:17:45 +02:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2022-07-28 03:39:57 +02:00
2020-01-05 19:49:24 +01:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2022-07-28 03:39:57 +02:00
2020-01-05 19:49:24 +01:00
ynh_script_progression --message="Upgrade of $app completed" --last