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

183 lines
6.3 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)
# Reload 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)
2021-05-10 15:15:42 +02:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up $app before upgrading (may take a while)..." --weight=20
# 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
2022-02-26 22:44:20 +01:00
# Store Synapse's settings, in case of they changed
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
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
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
ynh_script_progression --message="Upgrading source files..." --weight=160
2022-02-21 13:59:39 +01: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
#=================================================
2021-05-10 15:26:09 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
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
ynh_add_config --template="synapse.nginx.conf" --destination="/etc/nginx/conf.d/${synapse_domain}.d/synapse-admin.conf"
2021-05-10 15:15:42 +02:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=18
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
# Install Yarn
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# SPECIFIC UPGRADE
#==============================================
# INSTALL CODIMD
#==============================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=60
2021-08-06 20:11:14 +02:00
pushd "$final_path"
2021-05-10 15:15:42 +02:00
ynh_use_nodejs
ynh_exec_warn_less yarn install
2021-12-13 17:07:26 +01:00
ynh_exec_warn_less yarn build
2021-08-06 20:11:14 +02:00
popd
2021-05-10 15:15:42 +02:00
fi
2022-02-05 15:45:50 +01:00
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_add_config --template="../conf/.env" --destination="$final_path/.env"
chown -R $app:www-data "$final_path"
2022-01-24 23:05:47 +01:00
2021-05-10 15:15:42 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=2
2022-02-05 15:45:50 +01:00
env_path="$PATH"
2021-05-10 15:15:42 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description "UI admin for Synapse" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
2022-01-24 23:05:47 +01:00
ynh_systemd_action --service_name=$app --action=start --log_path=systemd #--line_match="HTTP Server listening"
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