1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/yunomonitor_ynh.git synced 2024-09-03 17:46:11 +02:00
yunomonitor_ynh/scripts/upgrade

141 lines
5.1 KiB
Text
Raw Normal View History

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2020-10-04 22:11:03 +02:00
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# CHECK VERSION
#=================================================
2022-01-27 02:21:23 +01:00
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2020-10-04 22:11:03 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
2022-01-27 02:21:23 +01:00
# Backup the current version of the app
2020-10-04 22:11:03 +02:00
ynh_backup_before_upgrade
ynh_clean_setup () {
2022-01-27 02:21:23 +01:00
# Restore it if the upgrade fails
2020-10-04 22:11:03 +02:00
ynh_restore_upgradebackup
}
2022-01-27 02:21:23 +01:00
# Exit if an error occurs during the execution of the script
2020-10-04 22:11:03 +02:00
ynh_abort_if_errors
2022-01-27 02:21:23 +01:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if ! [ -f $final_path/conf/ignore_alert.csv ]; then
echo "method level server message target" > $final_path/conf/ignore_alert.csv
fi
2021-08-23 11:55:13 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2020-10-04 22:11:03 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
2021-08-23 11:55:13 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
chmod u+x $final_path/yunomonitor.py
2021-08-23 12:01:36 +02:00
chmod u+w $final_path/conf
chmod u+w $final_path/well-known
2021-08-23 11:55:13 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2021-08-23 09:13:30 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated nginx config
# Note: i don't use the helper because i need this file to be named "000-"
finalnginxconf="/etc/nginx/conf.d/$domain.d/000-$app.conf"
ynh_backup_if_checksum_is_different --file="$finalnginxconf"
cp ../conf/nginx.conf "$finalnginxconf"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalnginxconf"
ynh_store_file_checksum --file="$finalnginxconf"
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2020-10-04 22:11:03 +02:00
ynh_script_progression --message="Upgrading dependencies..." --weight=1
ynh_install_app_dependencies $pkg_dependencies
#=================================================
2022-01-27 02:21:23 +01:00
# SPECIFIC UPGRADE
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different --file="$final_path/conf/$app.yml"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$final_path/conf/$app.yml"
#=================================================
2022-01-27 02:21:23 +01:00
# SETUP SYSTEMD
#=================================================
2022-01-27 02:21:23 +01:00
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
2022-01-27 02:21:23 +01:00
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# START SYSTEMD SERVICE
#=================================================
2020-10-04 22:11:03 +02:00
ynh_script_progression --message="Reloading a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="reload" --log_path="/var/log/$app/$app.log"
2022-01-27 02:21:23 +01:00
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2020-10-04 22:11:03 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last