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

133 lines
4.3 KiB
Text
Raw Normal View History

2016-06-13 22:03:33 +02:00
#!/bin/bash
2020-06-03 23:41:51 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2020-06-15 01:58:37 +02:00
source _common.sh
2020-06-03 23:41:51 +02:00
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2020-06-04 06:27:02 +02:00
ynh_script_progression --message="Loading installation settings..."
2020-06-15 01:58:37 +02:00
2016-06-13 22:03:33 +02:00
app=$YNH_APP_INSTANCE_NAME
2020-06-03 23:41:51 +02:00
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)
2021-03-28 18:22:10 +02:00
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
2020-06-03 23:41:51 +02:00
#=================================================
# CHECK VERSION
#=================================================
2022-07-29 02:04:07 +02:00
ynh_script_progression --message="Restoring the NGINX web server configuration..."
2016-06-13 22:03:33 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2021-11-12 13:04:10 +01:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
2022-07-29 02:04:07 +02:00
# Restore it if the upgrade fails
ynh_restore_upgradebackup
2021-11-12 13:04:10 +01:00
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2020-06-03 23:41:51 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-06-04 05:36:19 +02:00
ynh_script_progression --message="Ensuring downward compatibility..."
2020-06-03 23:41:51 +02:00
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
2022-07-29 02:04:07 +02:00
final_path=/var/www/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2020-06-03 23:41:51 +02:00
fi
2021-03-16 21:25:15 +01:00
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
2022-07-29 02:04:07 +02:00
ynh_legacy_permissions_delete_all
2021-03-16 21:25:15 +01:00
2022-07-29 02:04:07 +02:00
ynh_app_setting_delete --app=$app --key=is_public
2021-03-16 21:25:15 +01:00
fi
2021-11-12 13:03:18 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
2020-06-03 23:41:51 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2022-07-29 02:04:07 +02:00
ynh_script_progression --message="Upgrading source files..."
2022-07-29 02:04:07 +02:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
2021-11-12 13:03:18 +01:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2020-06-03 23:41:51 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2021-03-28 18:43:58 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..."
2016-06-13 22:03:33 +02:00
2022-07-29 02:04:07 +02:00
# Create a dedicated NGINX config
2020-06-03 23:57:07 +02:00
ynh_add_nginx_config
2020-06-03 23:41:51 +02:00
if [ "$path_url" != "/" ]
then
2022-07-29 02:04:07 +02:00
ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
2020-06-03 23:41:51 +02:00
fi
2016-06-13 22:03:33 +02:00
2020-06-03 23:41:51 +02:00
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
2020-06-15 01:58:37 +02:00
ynh_script_progression --message="Securing files and directories..."
2020-06-03 23:41:51 +02:00
# Set permissions on app files
2020-06-04 00:45:35 +02:00
chown -R www-data: $final_path
2020-06-03 23:41:51 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2021-03-16 21:25:15 +01:00
ynh_script_progression --message="Upgrading configuring permissions..."
2020-06-03 23:41:51 +02:00
# If app is public, add url to SSOWat conf as skipped_uris and read-only mode
2016-06-13 22:03:33 +02:00
if [[ $is_public -eq 1 ]]; then
2022-07-29 02:04:07 +02:00
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_permission_update --permission="main" --add="visitors"
# activate read-only
ynh_replace_string --match_string='"readonly": false,' --replace_string='"readonly": true,' --target_file="$final_path/config.js"
2016-06-13 22:03:33 +02:00
fi
2020-06-03 23:41:51 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2021-03-28 18:43:58 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2020-06-03 23:41:51 +02:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2020-06-15 01:58:37 +02:00
ynh_script_progression --message="Upgrade of $app completed"