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

121 lines
3.8 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
2020-06-15 01:58:37 +02:00
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)
#=================================================
# CHECK VERSION
#=================================================
2020-06-15 01:58:37 +02:00
ynh_script_progression --message="Checking version..."
2016-06-13 22:03:33 +02:00
upgrade_type=$(ynh_check_app_version_changed)
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
final_path=/var/www/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
2021-03-16 21:25:15 +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
2020-06-03 23:41:51 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2020-06-04 05:36:19 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
2020-06-03 23:41:51 +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
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2020-06-04 05:36:19 +02:00
ynh_script_progression --message="Upgrading source files..."
2020-06-03 23:41:51 +02:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
2020-06-03 23:41:51 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-06-04 05:36:19 +02:00
ynh_script_progression --message="Upgrading nginx web server configuration..."
2016-06-13 22:03:33 +02:00
2020-06-15 01:58:37 +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
ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
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
2020-06-03 23:41:51 +02:00
# unprotected_uris allows SSO credentials to be passed anyway.
2021-03-16 21:25:15 +01:00
ynh_permission_update --permission="main" --add="visitors"
2020-06-04 05:36:19 +02:00
# activate read-only
2020-06-03 23:41:51 +02:00
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
#=================================================
2020-06-04 06:27:02 +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"