2017-10-26 13:01:33 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2017-10-26 13:01:33 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
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)
|
2017-10-26 13:01:33 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
# CHECK VERSION
|
2017-10-26 13:01:33 +02:00
|
|
|
#=================================================
|
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2017-10-26 13:01:33 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=5
|
2017-10-26 13:01:33 +02:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
2021-02-13 18:14:54 +01:00
|
|
|
# Restore it if the upgrade fails
|
2017-10-26 13:01:33 +02:00
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
2017-10-26 13:01:33 +02:00
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=10
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2017-10-26 13:01:33 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
# SPECIFIC UPGRADE
|
2017-10-26 13:01:33 +02:00
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
# MODIFY A CONFIG FILE
|
2017-10-26 13:01:33 +02:00
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
ynh_script_progression --message="Configuring Mosquitto Password..." --weight=1
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
# Verify the checksum and backup the file if it's different.
|
|
|
|
ynh_backup_if_checksum_is_different --file="$password_file"
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
cp ../conf/passwd "$password_file"
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
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"
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
# Recalculate and store the checksum of the file for the next upgrade.
|
|
|
|
ynh_store_file_checksum --file="$password_file"
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
ynh_script_progression --message="Configuring Mosquitto..." --weight=1
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
# Verify the checksum and backup the file if it's different.
|
|
|
|
ynh_backup_if_checksum_is_different --file="$config_file"
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
cp ../conf/mosquitto.conf "$config_file"
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
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"
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
# Recalculate and store the checksum of the file for the next upgrade.
|
|
|
|
ynh_store_file_checksum --file="$config_file"
|
2017-10-26 13:01:33 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
# RESTART SYSTEMD SERVICE
|
2017-10-26 13:01:33 +02:00
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
ynh_script_progression --message="Restarting systemd service..." --weight=1
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action=restart
|
2017-10-26 13:01:33 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
2017-10-26 13:01:33 +02:00
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
2017-10-26 13:01:33 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2017-10-26 13:01:33 +02:00
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
yunohost service add $app --description="Allows MQTT clients to send/receive data" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port"
|
2017-10-26 13:01:33 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
# UPGRADE FAIL2BAN
|
2017-10-26 13:01:33 +02:00
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1
|
2017-10-26 13:01:33 +02:00
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
# 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"
|
2017-10-26 13:01:33 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-02-13 18:14:54 +01:00
|
|
|
# END OF SCRIPT
|
2017-10-26 13:01:33 +02:00
|
|
|
#=================================================
|
|
|
|
|
2021-02-13 18:14:54 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|