diff --git a/scripts/backup b/scripts/backup index 5389cd0..b54794c 100755 --- a/scripts/backup +++ b/scripts/backup @@ -70,6 +70,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/sudoers.d/$app" [[ ! -z "$mqtt_domain" ]] && ynh_backup --src_path="/etc/mosquitto/conf.d" --not_mandatory +ynh_backup --src_path="/usr/share/yunohost/hooks/conf_regen/95-nginx_domoticz" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index c9dea0d..5aacdcf 100755 --- a/scripts/install +++ b/scripts/install @@ -169,6 +169,7 @@ if [ ! -z "$mqtt_domain" ]; then ynh_print_info --message="The credential to the mosquitto server has been saved in the settings of the app" fi + #================================================= # NGINX CONFIGURATION #================================================= @@ -176,6 +177,10 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=2 [[ ! -z "$mqtt_domain" ]] && ynh_add_config --template="../conf/mqtt_nginx.conf" --destination="/etc/nginx/conf.d/"$mqtt_domain".d/mqtt_"$app".conf" +#Set Hook for nginx domain +cp -R ../sources/hooks/conf_regen/95-nginx_domoticz /usr/share/yunohost/hooks/conf_regen/ +yunohost tools regen-conf nginx + # Create a dedicated NGINX config ynh_add_nginx_config diff --git a/scripts/remove b/scripts/remove index 5de3cbe..ba5b4b6 100755 --- a/scripts/remove +++ b/scripts/remove @@ -76,6 +76,11 @@ ynh_secure_remove --file="$final_path" #================================================= ynh_script_progression --message="Removing NGINX web server configuration..." +#remove hook for mqtt nginx +ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/95-nginx_domoticz" +yunohost tools regen-conf postfix + + # Remove the dedicated NGINX config [[ ! -z "$mqtt_domain" ]] && ynh_secure_remove --file="/etc/nginx/conf.d/"$mqtt_domain".d/mqtt_"$app".conf" diff --git a/scripts/restore b/scripts/restore index 0f94bd2..9054a91 100755 --- a/scripts/restore +++ b/scripts/restore @@ -151,6 +151,15 @@ chown -R domoticz: /var/log/"$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app" [[ ! -z "$mqtt_domain" ]] && ynh_use_logrotate --logfile="/var/log/mosquitto/" +#================================================= +# RESTORE VARIOUS FILES +#================================================= +ynh_script_progression --message="Restoring various files..." + +ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/95-nginx_domoticz" +yunohost tools regen-conf postfix + + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index b1d55a8..58bc0ea 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -224,6 +224,9 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." [[ ! -z "$mqtt_domain" ]] && ynh_add_config --template="../conf/mqtt_nginx.conf" --destination="/etc/nginx/conf.d/"$mqtt_domain".d/mqtt_"$app".conf" +#Set Hook for nginx domain +cp -R ../sources/hooks/conf_regen/95-nginx_domoticz /usr/share/yunohost/hooks/conf_regen/ +yunohost tools regen-conf nginx # Create a dedicated NGINX config ynh_add_nginx_config diff --git a/sources/hooks/conf_regen/95-nginx_domoticz b/sources/hooks/conf_regen/95-nginx_domoticz new file mode 100644 index 0000000..72fb234 --- /dev/null +++ b/sources/hooks/conf_regen/95-nginx_domoticz @@ -0,0 +1,22 @@ +#!/bin/bash + +action=$1 +pending_dir=$4 +nginx_conf=$pending_dir/../nginx/etc/nginx + +[[ $action == "pre" ]] || exit 0 + +#Il ne peut y avoir qu'une seule instance de l'apps sur un système, donc pas à besoin de regarder quelle id utiliser +mqtt_port=$(yunohost app setting domoticz mqtt_websocket_port) +mqtt_domain=$(yunohost app setting domoticz mqtt_domain) +domain=$(yunohost app setting domoticz domain) +nginx_mqtt="$nginx_conf"/conf.d/"$mqtt_domain".conf + +[[ ! -z $mqtt_domain ]] || exit 0 +[[ -e $nginx_mqtt ]] || exit 0 + + +if [[ "$mqtt_domain" != "domain" ]]; then +#single quote pour ne pas étendre les variables du fichier de config nginx et doubles quote pour les variables à étendre + sed -i '/map $http_upgrade $connection_upgrade {/i upstream '"${mqtt_domain}"' {\n server localhost:'"${mqtt_port}"';\n}\n' $nginx_mqtt +fi