1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/domoticz_ynh.git synced 2024-09-03 18:26:17 +02:00
domoticz_ynh/scripts/restore

153 lines
5.8 KiB
Text
Raw Normal View History

2020-10-05 23:05:58 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2021-08-05 02:21:46 +02:00
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
2020-10-05 23:05:58 +02:00
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
2023-02-28 23:36:30 +01:00
current_os=`lowercase \`uname -s\``
current_mach=`uname -m`
2023-06-01 23:25:39 +02:00
2020-10-05 23:05:58 +02:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2020-11-08 15:24:23 +01:00
#As we are downloading compiled binaries for each system, we have to check if the restore occurs
#on the same system type. If we are restoring on another system type it won't work and in that
#case we must go through a reinstall process.
test "$OS" = "$current_os" \
2023-05-27 18:13:49 +02:00
|| ynh_die --message="Cannot restore : previous OS is $OS, current OS is $current_os, please reinstall"
test "$mach" = "$current_mach" \
2023-05-27 18:13:49 +02:00
|| ynh_die --message="Cannot restore : previous machine type is $mach, current machine type is $current_mach, please reinstall"
2020-10-05 23:05:58 +02:00
2023-06-01 23:25:39 +02:00
ynh_app_setting_set --app="$app" --key=OS --value="$current_os"
ynh_app_setting_set --app="$app" --key=mach --value="$current_mach"
2020-10-05 23:05:58 +02:00
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
2021-08-05 02:21:46 +02:00
ynh_script_progression --message="Restoring the NGINX web server configuration..."
2020-10-05 23:05:58 +02:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2024-01-31 22:51:02 +01:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/${domain}.d/api_${app}.conf"
ynh_restore_file --origin_path="/etc/nginx/conf.d/$mqtt_domain.d/mqtt_${app}.conf" --not_mandatory
2020-10-05 23:05:58 +02:00
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
2021-02-02 21:04:57 +01:00
#allow user to access USB / serial port to communicate with tools (RFXtrx, Z-wave dongle, etc.) & i2c bus
2021-02-05 23:24:45 +01:00
if grep dialout -q < /etc/group; then
2022-05-26 09:30:42 +02:00
usermod -a -G dialout "$app"
2021-02-05 23:24:45 +01:00
fi
if grep i2c -q < /etc/group; then
2022-05-26 09:30:42 +02:00
usermod -a -G i2c "$app"
2021-02-05 23:24:45 +01:00
fi
if grep gpio -q < /etc/group; then
2022-05-26 09:30:42 +02:00
usermod -a -G gpio "$app"
2021-02-05 23:24:45 +01:00
fi
2021-02-02 21:04:57 +01:00
2021-08-05 02:21:46 +02:00
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=5
2023-02-20 22:22:42 +01:00
ynh_restore_file --origin_path="$install_dir"
2021-08-05 02:21:46 +02:00
2023-02-20 22:22:42 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app":"$app" "$install_dir"
2020-10-05 23:05:58 +02:00
#=================================================
# SET MOSQUITTO SETTINGS
#=================================================
2023-05-27 18:13:49 +02:00
if [ "$domain" != "$mqtt_domain" ]; then
2022-05-22 19:15:23 +02:00
ynh_script_progression --message="Reinstalling up mosquitto..." --weight=5
ynh_restore_file --origin_path="/etc/mosquitto/conf.d" --not_mandatory
2024-01-21 17:11:51 +01:00
else
#If no MQTT have been set, we delete the mqtt permission.
ynh_permission_delete --permission="mqtt"
2022-05-22 19:15:23 +02:00
fi
2020-10-05 23:05:58 +02:00
#=================================================
# RESTORE SYSTEMD
#=================================================
2020-11-07 10:24:19 +01:00
ynh_script_progression --message="Restoring the systemd configuration..." --weight=3
2020-10-05 23:05:58 +02:00
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
2022-05-26 09:30:42 +02:00
systemctl enable "$app".service --quiet
2020-10-05 23:05:58 +02:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
2021-08-05 02:21:46 +02:00
ynh_script_progression --message="Integrating service in YunoHost..."
2020-10-05 23:05:58 +02:00
2022-05-26 09:30:42 +02:00
yunohost service add "$app" --description="Domotique open sources" --log="/var/log/$app/$app.log"
2023-05-27 18:13:49 +02:00
[[ "$domain" != "$mqtt_domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
2022-05-26 09:30:42 +02:00
2020-10-05 23:05:58 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2021-08-05 02:21:46 +02:00
ynh_script_progression --message="Starting a systemd service..."
2020-10-05 23:05:58 +02:00
2022-05-26 09:30:42 +02:00
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
2020-10-05 23:05:58 +02:00
#Restarting mosquitto to take changes into account
2023-05-27 18:13:49 +02:00
[[ "$domain" != "$mqtt_domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart"
2020-10-05 23:05:58 +02:00
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
2021-08-05 02:21:46 +02:00
ynh_script_progression --message="Restoring the logrotate configuration..."
2022-05-26 09:30:42 +02:00
mkdir -p /var/log/"$app"
chown -R domoticz: /var/log/"$app"
2020-10-05 23:05:58 +02:00
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
2022-06-17 19:09:19 +02:00
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..."
ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/95-nginx_domoticz"
2023-02-27 23:24:05 +01:00
#yunohost tools regen-conf postfix
2022-06-17 19:09:19 +02:00
#=================================================
# RESTORE THE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=7
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
log_file=/var/log/$app/$app.log
if [ ! -f "$log_file" ]; then
touch "$log_file"
chown $app: "$log_file"
fi
ynh_systemd_action --action=restart --service_name=fail2ban
2022-06-17 19:09:19 +02:00
2020-10-05 23:05:58 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
2021-08-05 02:21:46 +02:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=3
2020-10-05 23:05:58 +02:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2020-11-07 10:24:19 +01:00
ynh_script_progression --message="Restoration completed for $app" --last