1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/galette_ynh.git synced 2024-09-03 18:36:28 +02:00
galette_ynh/scripts/upgrade

189 lines
6.4 KiB
Text
Raw Normal View History

2015-11-03 23:22:02 +01:00
#!/bin/bash
2018-02-27 22:35:57 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? db_user=$db_name
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
#REMOVEME? phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#REMOVEME? database=$(ynh_app_setting_get --app=$app --key=database)
2021-07-22 15:51:13 +02:00
timezone="$(cat /etc/timezone)"
2021-01-05 23:31:12 +01:00
#=================================================
# CHECK VERSION
#=================================================
2022-04-13 20:36:45 +02:00
ynh_script_progression --message="Checking version..."
2021-01-05 23:31:12 +01:00
upgrade_type=$(ynh_check_app_version_changed)
2021-07-22 15:51:13 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
2021-07-22 15:51:13 +02:00
# Backup the current version of the app
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
2021-07-22 15:51:13 +02:00
# Restore it if the upgrade fails
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_restore_upgradebackup
2021-07-22 15:51:13 +02:00
}
# Exit if an error occurs during the execution of the script
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_abort_if_errors
2021-07-22 15:51:13 +02:00
2022-04-13 20:36:45 +02:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2021-07-22 15:51:13 +02:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=2
2022-06-26 14:53:49 +02:00
# Cleaning legacy permissions
2023-11-11 14:01:42 +01:00
#REMOVEME? if ynh_legacy_permissions_exists; then
#REMOVEME? ynh_legacy_permissions_delete_all
2022-06-26 14:53:49 +02:00
ynh_app_setting_delete --app=$app --key=is_public
fi
# If db_name doesn't exist, create it
if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid "$app")
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi
2022-04-15 01:28:38 +02:00
# If db_pwd doesn't exist, create it
if [ -z "$db_pwd" ]; then
2023-11-11 14:01:42 +01:00
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#REMOVEME? ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
fi
2023-11-11 14:01:42 +01:00
# If install_dir doesn't exist, create it
if [ -z "$install_dir" ]; then
#REMOVEME? install_dir="/var/www/$app"
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
fi
2022-06-26 14:53:49 +02:00
# If database doesn't exist, create it
if [ -z "$database" ]; then
database="pgsql"
ynh_app_setting_set --app=$app --key=database --value=$database
2021-07-22 15:51:13 +02:00
fi
2021-06-15 22:16:38 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
2021-06-15 22:16:38 +02:00
# Create a dedicated user (if not existing)
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
2021-06-15 22:16:38 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2021-07-22 15:51:13 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2022-04-13 20:36:45 +02:00
ynh_script_progression --message="Upgrading source files..."
2021-07-22 15:51:13 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2023-11-11 14:01:42 +01:00
mv "$install_dir" "$install_dir.old"
2018-05-20 15:49:02 +02:00
2023-11-11 14:01:42 +01:00
ynh_setup_source --dest_dir="$install_dir"
2018-05-20 15:49:02 +02:00
2021-07-22 15:51:13 +02:00
# when running automatic tests, there is no config.inc.php
2023-11-11 14:01:42 +01:00
if [ -e "$install_dir.old/galette/config/config.inc.php" ]; then
cp "$install_dir.old/galette/config/config.inc.php" "$install_dir/galette/config/config.inc.php"
cp -r "$install_dir.old/galette/data" "$install_dir/galette/data"
cp -r "$install_dir.old/galette/plugins" "$install_dir/galette/plugins"
2021-07-22 15:51:13 +02:00
fi
2018-05-20 15:49:02 +02:00
2021-07-22 15:51:13 +02:00
# delete temp directory
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_secure_remove "$install_dir.old"
2021-07-22 15:51:13 +02:00
fi
2023-11-11 14:01:42 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
2021-07-23 07:46:48 +02:00
2021-07-22 15:41:21 +02:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1
2021-07-22 15:41:21 +02:00
2022-04-14 19:39:41 +02:00
if [ $database == "pgsql" ]
then
2023-11-11 14:01:42 +01:00
#REMOVEME? pkg_dependencies="$pkg_dependencies $pgsql_pkg_dependencies"
2022-04-14 19:39:41 +02:00
fi
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
2021-07-22 15:41:21 +02:00
2019-09-25 22:51:37 +02:00
#=================================================
2021-01-05 23:31:12 +01:00
# PHP-FPM CONFIGURATION
2019-09-25 22:51:37 +02:00
#=================================================
2021-01-05 23:31:12 +01:00
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=2
2019-09-25 22:51:37 +02:00
2021-01-05 23:31:12 +01:00
# Create a dedicated PHP-FPM config
2021-11-14 15:32:27 +01:00
ynh_add_fpm_config
2019-09-25 22:51:37 +02:00
2022-06-26 14:53:49 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
2023-11-11 14:01:42 +01:00
chown "$app" "$install_dir/galette/config"
chmod 750 "$install_dir/galette/config"
for folder in attachments cache exports files imports logs photos templates_c tempimages
do
2023-11-11 14:01:42 +01:00
chown "$app" "$install_dir/galette/data/$folder"
chmod 775 "$install_dir/galette/data/$folder"
done
2021-01-05 23:31:12 +01:00
#=================================================
# GENERIC FINALIZATION
2022-04-13 20:36:45 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# RELOAD NGINX
#=================================================
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=2
2023-11-11 14:01:42 +01:00
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
2021-01-05 23:31:12 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last