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

209 lines
7.2 KiB
Text
Raw Normal View History

#!/bin/bash
2018-03-13 21:49:11 +01:00
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2017-02-06 23:40:55 +01:00
source /usr/share/yunohost/helpers
source _common.sh
2018-03-13 21:49:11 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2021-07-12 12:11:43 +02:00
ynh_script_progression --message="Loading installation settings..." --weight=1
2017-02-06 23:40:55 +01:00
2021-07-12 12:11:43 +02:00
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=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
prefix=$(ynh_app_setting_get $app prefix)
2018-03-13 21:49:11 +01:00
#=================================================
# CHECK VERSION
#=================================================
2021-07-12 12:11:43 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2018-03-13 21:49:11 +01:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2021-07-12 12:11:43 +02:00
ynh_script_progression --message="Backing up $app before upgrading (may take a while)..." --weight=7
2018-03-13 21:49:11 +01:00
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
2021-07-12 12:11:43 +02:00
# restore it if the upgrade fails
ynh_restore_upgradebackup
2018-03-13 21:49:11 +01:00
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
2021-07-12 12:11:43 +02:00
# ENSURE DOWNWARD COMPATIBILITY
2018-03-13 21:49:11 +01:00
#=================================================
2021-07-12 12:11:43 +02:00
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
#
# N.B. : the followings setting migrations snippets are provided as *EXAMPLES*
# of what you may want to do in some cases (e.g. a setting was not defined on
# some legacy installs and you therefore want to initiaze stuff during upgrade)
#
# If db_name doesn't exist, create it
#if [ -z "$db_name" ]; then
# db_name=$(ynh_sanitize_dbid --db_name=$app)
# ynh_app_setting_set --app=$app --key=db_name --value=$db_name
#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 nobody installed your app before 4.1,
### then you may safely remove these lines
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
2018-03-13 21:49:11 +01:00
2021-07-12 12:11:43 +02:00
ynh_app_setting_delete --app=$app --key=is_public
fi
if ! ynh_permission_exists --permission="admin"; then
# Create the required permissions
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
fi
# Create a permission if needed
if ! ynh_permission_exists --permission="api"; then
ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
fi
2018-03-13 21:49:11 +01:00
#=================================================
# STEP Migrations
#=================================================
2021-07-12 12:11:43 +02:00
2018-03-13 21:49:11 +01:00
if ynh_version_le "2.0.5" ; then
is_public=${is_public:-0}
prefix=${prefix:-prefix_}
db_name=${db_name:-$app}
final_path=$(ynh_app_setting_get $app local_path)
ynh_install_app_dependencies $pkg_dependencies
# Move the upload dir to final_path if needed
2017-02-06 23:40:55 +01:00
# The upload dir can't be symlinked in home (not supported by LS)
upload_path=/home/yunohost.app/$app/upload
2018-03-13 21:49:11 +01:00
if [ -h $final_path/upload ]; then
rm $final_path/upload
mv $upload_path $final_path/
fi
2017-02-06 23:40:55 +01:00
ynh_app_setting_delete $app skipped_uris
2017-02-06 23:40:55 +01:00
ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts"
ynh_configure migrations/2.0.5.sql ./2.0.5.sql
2018-03-13 21:49:11 +01:00
mysql -u $app -p$db_pwd $db_name < ./2.0.5.sql
2017-02-06 23:40:55 +01:00
fi
2018-03-14 19:05:43 +01:00
if ynh_version_le "2.62.2-1" ; then
is_public=${is_public:-0}
prefix=${prefix:-prefix_}
db_name=${db_name:-$app}
final_path=$(ynh_app_setting_get $app local_path)
ynh_save_args path_url is_public prefix db_name final_path db_user
fi
if ynh_version_le "2.62.2-2" ; then
2018-03-14 19:05:43 +01:00
# Move old templates and themes in backup dir
mv $final_path/upload/templates /home/yunohost.backup/$app.bkp/old-templates
mkdir -p /home/yunohost.backup/$app.bkp/old-themes
mv $final_path/themes/* /home/yunohost.backup/$app.bkp/old-themes/
fi
2017-02-06 23:40:55 +01:00
2018-03-13 21:49:11 +01:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2017-02-06 23:40:55 +01:00
# Backup config, plugins and themes and delete previous files
2019-05-19 19:02:35 +02:00
ynh_keep_if_no_upgrade plugins/*
ynh_keep application/config/config.php
ynh_keep upload
2017-02-06 23:40:55 +01:00
# Copie new files and restore config, plugins, upload and themes
2018-03-13 21:49:11 +01:00
ynh_secure_remove $final_path
ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path
# Restore config, plugins and themes
2018-03-14 19:05:43 +01:00
ynh_restore_persistent
2018-03-13 21:49:11 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2021-07-12 12:11:43 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
2018-03-13 21:49:11 +01:00
2021-07-12 12:11:43 +02:00
# Create a dedicated NGINX config
2018-03-13 21:49:11 +01:00
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
2021-07-12 12:11:43 +02:00
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
2018-03-13 21:49:11 +01:00
2021-07-12 12:11:43 +02:00
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
2018-03-13 21:49:11 +01:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
2021-07-12 12:11:43 +02:00
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
2018-03-13 21:49:11 +01:00
2021-07-12 12:11:43 +02:00
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
2018-03-13 21:49:11 +01:00
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
2021-07-12 12:11:43 +02:00
2018-03-13 21:49:11 +01:00
set_permissions
#=================================================
# UPGRADE DB
#=================================================
2017-02-06 23:40:55 +01:00
# Migrate DB
2019-05-19 19:02:35 +02:00
cd $final_path
ynh_exec_as "$app" php application/commands/console.php updatedb
#=================================================
# Send message to the admin
#=================================================
if ynh_version_le "2.62.2-2" ; then
message="LimeSurvey has been upgraded from version to version 3, note this new version change completely the survey themes system. If you have added or created manually some templates they won't be available in your LimeSurvey, a copy of their source code has been done in /home/yunohost.backup/$app-old-templates/. See https://manual.limesurvey.org/New_Template_System_in_LS3.x"
ynh_warn "$message"
ynh_send_readme_to_admin "$message" "$admin"
fi
2021-07-12 12:11:43 +02:00
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --time --last