1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/synapse-admin_ynh.git synced 2024-09-03 20:26:34 +02:00
synapse-admin_ynh/scripts/upgrade

134 lines
4.5 KiB
Text
Raw Normal View History

2021-05-10 15:15:42 +02:00
#!/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=2
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
2022-02-26 22:44:20 +01:00
synapse_app=$(ynh_app_setting_get --app=$app --key=synapse_app)
2021-05-10 15:15:42 +02:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2023-04-10 17:46:43 +02:00
ynh_script_progression --message="Backing up $app before upgrading (may take a while)..." --weight=5
2021-05-10 15:15:42 +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
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2022-01-24 23:05:47 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
2022-02-21 13:59:39 +01:00
if ynh_compare_current_package_version --comparison le --version 0.8.3~ynh2
then
ynh_die --message="Upgrade from version 0.8.3 is not possible. You must uninstall and reinstall Synapse-admin package manually"
fi
2022-01-24 23:05:47 +01:00
# 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 synapse_app doesn't exist, create it and assume it is `synapse`
if [ -z "$synapse_app" ]; then
synapse_app="synapse"
ynh_app_setting_set --app=$app --key=synapse_app --value=$synapse_app
fi
# Delete service and nodejs dependencies
if ynh_compare_current_package_version --comparison lt --version 0.8.7~ynh1
then
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
yunohost service remove $app
ynh_remove_nodejs
ynh_remove_logrotate
ynh_remove_app_dependencies
ynh_app_setting_delete --app=$app --key=synapse_port
ynh_app_setting_delete --app=$app --key=port
fi
# Reload and store Synapse's settings, in case of they changed
synapse_domain=$(ynh_app_setting_get --app=$synapse_app --key=domain)
synapse_port=$(ynh_app_setting_get --app=$synapse_app --key=synapse_port)
2022-02-26 22:44:20 +01:00
ynh_app_setting_set --app=$app --key=synapse_domain --value=$synapse_domain
ynh_app_setting_set --app=$app --key=synapse_port --value=$synapse_port
2021-05-10 15:15:42 +02:00
#=================================================
# STANDARD UPGRADE STEPS
2021-08-06 20:11:14 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
2021-05-10 15:15:42 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2023-04-10 17:46:43 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=2
2021-05-10 15:15:42 +02:00
ynh_setup_source --dest_dir="$final_path"
2021-05-10 15:15:42 +02:00
fi
2021-08-06 20:11:14 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2021-05-10 15:15:42 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2023-04-10 17:46:43 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
2021-05-10 15:15:42 +02:00
# Create a dedicated nginx config
ynh_add_nginx_config
2022-02-26 22:44:20 +01:00
# Create NGINX config to access /_synapse/admin endpoint
2022-03-01 11:39:34 +01:00
ynh_add_config --template="endpoint.nginx.conf" --destination="/etc/nginx/conf.d/${synapse_domain}.d/$app.endpoint.conf"
2022-02-26 22:44:20 +01:00
2021-05-10 15:15:42 +02:00
#=================================================
# 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