mirror of
https://github.com/YunoHost-Apps/domoticz_ynh.git
synced 2024-09-03 18:26:17 +02:00
141 lines
5.7 KiB
Bash
Executable file
141 lines
5.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
|
source ../settings/scripts/_common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
current_os=`lowercase \`uname -s\``
|
|
current_mach=`uname -m`
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
#=================================================
|
|
#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" \
|
|
|| ynh_die "Cannot restore : previous OS is $OS, current OS is $current_os, please reinstall"
|
|
test "$mach" = "$current_mach" \
|
|
|| ynh_die "Cannot restore : previous machine type is $mach, current machine type is $current_mach, please reinstall"
|
|
|
|
ynh_app_setting_set --key=OS --value="$current_os"
|
|
ynh_app_setting_set --key=mach --value="$current_mach"
|
|
|
|
#=================================================
|
|
# STANDARD RESTORATION STEPS
|
|
#=================================================
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression "Restoring the NGINX web server configuration..."
|
|
|
|
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
ynh_restore "/etc/nginx/conf.d/${domain}.d/api_${app}.conf"
|
|
ynh_restore "/etc/nginx/conf.d/$mqtt_domain.d/mqtt_${app}.conf" || true
|
|
|
|
#=================================================
|
|
# RECREATE THE DEDICATED USER
|
|
#=================================================
|
|
#allow user to access USB / serial port to communicate with tools (RFXtrx, Z-wave dongle, etc.) & i2c bus
|
|
if grep dialout -q < /etc/group; then
|
|
usermod -a -G dialout "$app"
|
|
fi
|
|
if grep i2c -q < /etc/group; then
|
|
usermod -a -G i2c "$app"
|
|
fi
|
|
if grep gpio -q < /etc/group; then
|
|
usermod -a -G gpio "$app"
|
|
fi
|
|
|
|
#=================================================
|
|
# RESTORE THE APP MAIN DIR
|
|
#=================================================
|
|
ynh_script_progression "Restoring the app main directory..."
|
|
|
|
ynh_restore "$install_dir"
|
|
|
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
|
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
|
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app":"$app" "$install_dir"
|
|
#=================================================
|
|
# SET MOSQUITTO SETTINGS
|
|
#=================================================
|
|
if [ "$domain" != "$mqtt_domain" ]; then
|
|
ynh_script_progression "Reinstalling up mosquitto..."
|
|
ynh_restore "/etc/mosquitto/conf.d" || true
|
|
else
|
|
#If no MQTT have been set, we delete the mqtt permission.
|
|
ynh_permission_delete --permission="mqtt"
|
|
fi
|
|
|
|
#=================================================
|
|
# RESTORE SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression "Restoring $app's systemd service..."
|
|
|
|
ynh_restore "/etc/systemd/system/$app.service"
|
|
systemctl enable "$app".service --quiet
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression "Integrating service in YunoHost..."
|
|
|
|
yunohost service add "$app" --description="Domotique open sources" --log="/var/log/$app/$app.log"
|
|
[[ "$domain" != "$mqtt_domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression "Starting $app's systemd service..."
|
|
|
|
ynh_systemctl --service="$app" --action="start"
|
|
|
|
#Restarting mosquitto to take changes into account
|
|
[[ "$domain" != "$mqtt_domain" ]] && ynh_systemctl --service=mosquitto --action="restart"
|
|
|
|
#=================================================
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression "Restoring the logrotate configuration..."
|
|
|
|
mkdir -p /var/log/"$app"
|
|
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R domoticz: /var/log/"$app"
|
|
|
|
ynh_restore "/etc/logrotate.d/$app"
|
|
|
|
#=================================================
|
|
# RESTORE VARIOUS FILES
|
|
#=================================================
|
|
ynh_script_progression "Restoring various files..."
|
|
|
|
ynh_restore "/usr/share/yunohost/hooks/conf_regen/95-nginx_domoticz"
|
|
#yunohost tools regen-conf postfix
|
|
|
|
#=================================================
|
|
# RESTORE THE FAIL2BAN CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression "Restoring the Fail2Ban configuration..."
|
|
|
|
ynh_restore "/etc/fail2ban/jail.d/$app.conf"
|
|
ynh_restore "/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_systemctl --action=restart --service=fail2ban
|
|
|
|
#=================================================
|
|
# RELOAD NGINX AND PHP-FPM
|
|
#=================================================
|
|
ynh_script_progression "Reloading NGINX web server..."
|
|
|
|
ynh_systemctl --service=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression "Restoration completed for $app"
|