1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mosquitto_ynh.git synced 2024-09-03 19:45:54 +02:00
mosquitto_ynh/scripts/upgrade
2021-02-15 09:27:16 +01:00

125 lines
4.6 KiB
Bash
Executable file

#!/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=1
app=$YNH_APP_INSTANCE_NAME
port=$(ynh_app_setting_get --app=$app --key=port)
username=$(ynh_app_setting_get --app=$app --key=username)
password=$(ynh_app_setting_get --app=$app --key=password)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=5
# 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
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=10
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC UPGRADE
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Configuring Mosquitto Password..." --weight=1
# Verify the checksum and backup the file if it's different.
ynh_backup_if_checksum_is_different --file="$password_file"
cp ../conf/passwd "$password_file"
ynh_replace_string --match_string="__USERNAME__" --replace_string="$username" --target_file="$password_file"
ynh_replace_string --match_string="__PASSWORD__" --replace_string="$password" --target_file="$password_file"
mosquitto_passwd -U "$password_file"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$password_file"
ynh_script_progression --message="Configuring Mosquitto..." --weight=1
# Verify the checksum and backup the file if it's different.
ynh_backup_if_checksum_is_different --file="$config_file"
cp ../conf/mosquitto.conf "$config_file"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_file"
ynh_replace_string --match_string="__PASSWORD_FILE__" --replace_string="$password_file" --target_file="$config_file"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$config_file"
#=================================================
# RESTART SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Restarting systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action=restart
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Allows MQTT clients to send/receive data" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port"
#=================================================
# UPGRADE FAIL2BAN
#=================================================
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1
# Create a dedicated Fail2Ban config
#ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last