diff --git a/scripts/backup b/scripts/backup index d1a193f..c518beb 100755 --- a/scripts/backup +++ b/scripts/backup @@ -54,7 +54,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service" # BACKUP VARIOUS FILES #================================================= -[[ "$mqtt_domain" != "$domain" ]] && ynh_backup --src_path="/etc/mosquitto/conf.d" --not_mandatory +[[ ! -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" diff --git a/scripts/install b/scripts/install index dfdfb00..d108c12 100755 --- a/scripts/install +++ b/scripts/install @@ -20,6 +20,11 @@ else api_path=/api_"$path" fi +if [ "$domain" == "$mqtt_domain" ]; then + mqtt_domain="" + #pacakging v2 : settings are automatically stored. We don't want mqtt_domain in this case + ynh_app_setting_delete --app="$app" --key=mqtt_domain +fi #================================================= # STORE SETTINGS FROM MANIFEST @@ -30,25 +35,11 @@ ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app="$app" --key=OS --value="$os" ynh_app_setting_set --app="$app" --key=mach --value="$mach" -#path used by api & mqtt to read/update domoticz +#path used by api to read/update domoticz ynh_app_setting_set --app="$app" --key=api_path --value="$api_path" -[[ "$mqtt_domain" != "$domain" ]] && ynh_app_setting_set --app="$app" --key=mqtt_domain --value="$mqtt_domain" - #================================================= # STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -if [ "$mqtt_domain" != "$domain" ]; then - ynh_script_progression --message="Finding available ports for Mosquitto..." - mqtt_port=$(ynh_find_port --port="$default_mqtt_port") - ynh_app_setting_set --app="$app" --key=mqtt_port --value="$mqtt_port" - - mqtt_websocket_port=$(ynh_find_port --port="$default_mqtt_websocket_port") - ynh_app_setting_set --app="$app" --key=mqtt_websocket_port --value="$mqtt_websocket_port" -fi - #================================================= # CREATE DEDICATED USER #================================================= @@ -87,10 +78,18 @@ chown -R "$app":"$app" "$install_dir" #================================================= # SET MOSQUITTO SETTINGS #================================================= -if [ "$mqtt_domain" != "$domain" ]; then +if [ ! -z "$mqtt_domain" ]; then ynh_script_progression --message="Setting up mosquitto..." --weight=5 + ynh_script_progression --message="Finding available ports for Mosquitto..." + mqtt_port=$(ynh_find_port --port="$default_mqtt_port") + ynh_app_setting_set --app="$app" --key=mqtt_port --value="$mqtt_port" + + mqtt_websocket_port=$(ynh_find_port --port="$default_mqtt_websocket_port") + ynh_app_setting_set --app="$app" --key=mqtt_websocket_port --value="$mqtt_websocket_port" + + #Installing packages ynh_install_extra_app_dependencies --repo="deb https://repo.mosquitto.org/debian buster main" --package="$extra_pkg_dependencies" --key="http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key" @@ -113,7 +112,7 @@ fi #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=2 -[[ "$mqtt_domain" != "$domain" ]] && ynh_add_config --template="../conf/mqtt_nginx.conf" --destination="/etc/nginx/conf.d/"$mqtt_domain".d/mqtt_"$app".conf" +[[ ! -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/ @@ -145,7 +144,7 @@ chown -R domoticz: /var/log/"$app" # Use logrotate to manage application logfile(s) ynh_use_logrotate -[[ "$mqtt_domain" != "$domain" ]] && ynh_use_logrotate --logfile="/var/log/mosquitto" +[[ ! -z "$mqtt_domain" ]] && ynh_use_logrotate --logfile="/var/log/mosquitto" #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -153,7 +152,7 @@ ynh_use_logrotate ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add "$app" --description="Domotique open sources" --log="/var/log/$app/$app.log" -[[ "$mqtt_domain" != "$domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log" +[[ ! -z "$mqtt_domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log" #================================================= @@ -165,7 +164,7 @@ ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name="$app" --action="start" #Restarting mosquitto to take changes into account -[[ "$mqtt_domain" != "$domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart" +[[ ! -z "$mqtt_domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart" #================================================= # SETUP FAIL2BAN @@ -182,17 +181,18 @@ fi # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="$log_file" --failregex="^.*Error: Failed login attempt from .*$" --max_retry=5 -ynh_print_info --message="If you wish for Fail2ban to work, set up your local address in Setup/Settings/System/Local Networks as per documentation" +#Not required in 2023.1 anymore +#ynh_print_info --message="If you wish for Fail2ban to work, set up your local address in Setup/Settings/System/Local Networks as per documentation" #================================================= # SETUP SSOWAT #================================================= -#REMOVEME? ynh_script_progression --message="Configuring permissions..." +ynh_script_progression --message="Configuring permissions..." #API & MQTT should stay publicly accessible. -ynh_permission_create --permission="domoticz_API" --label="api" --url="$domain$api_path" --allowed="visitors" --show_tile="false" --protected="true" -[[ "$mqtt_domain" != "$domain" ]] && ynh_permission_create --permission="domoticz_MQTT" --label="MQTT" --url="$mqtt_domain" --allowed="visitors" --show_tile="false" --protected="true" +#ynh_permission_create --permission="domoticz_API" --label="api" --url="$domain$api_path" --allowed="visitors" --show_tile="false" --protected="true" +[[ ! -z "$mqtt_domain" ]] && ynh_permission_create --permission="domoticz_MQTT" --label="MQTT" --url="$mqtt_domain" --allowed="visitors" --show_tile="false" --protected="true" #================================================= diff --git a/scripts/remove b/scripts/remove index efe8618..2e5b416 100755 --- a/scripts/remove +++ b/scripts/remove @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers # REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -if [ "$mqtt_domain" != "$domain" ]; then +if [ ! -z "$mqtt_domain" ]; then ynh_script_progression --message="Removing system configurations related to Mosquitto..." --weight=1 yunohost service remove mosquitto ynh_secure_remove --file="/etc/mosquitto/conf.d" diff --git a/scripts/restore b/scripts/restore index 4c88e4d..8c328ea 100755 --- a/scripts/restore +++ b/scripts/restore @@ -66,7 +66,7 @@ chown -R "$app":"$app" "$install_dir" #================================================= # SET MOSQUITTO SETTINGS #================================================= -if [ "$mqtt_domain" != "$domain" ]; then +if [ ! -z "$mqtt_domain" ]; then ynh_script_progression --message="Reinstalling up mosquitto..." --weight=5 #Installing packages @@ -89,7 +89,7 @@ systemctl enable "$app".service --quiet ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add "$app" --description="Domotique open sources" --log="/var/log/$app/$app.log" -[[ "$mqtt_domain" != "$domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log" +[[ ! -z "$mqtt_domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log" #================================================= @@ -100,7 +100,7 @@ ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #Restarting mosquitto to take changes into account -[[ "$mqtt_domain" != "$domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart" +[[ ! -z "$mqtt_domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart" #================================================= # RESTORE THE LOGROTATE CONFIGURATION diff --git a/scripts/upgrade b/scripts/upgrade index 1b44a65..9a65e80 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -99,7 +99,7 @@ fi #================================================= # CREATE DEDICATED USER #================================================= -#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." +ynh_script_progression --message="Checking dedicated user permissions..." #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 @@ -134,7 +134,7 @@ chown -R "$app":"$app" "$install_dir" #================================================= # SET MOSQUITTO SETTINGS #================================================= -if [ "$mqtt_domain" != "$domain" ]; then +if [ ! -z "$mqtt_domain" ]; then ynh_script_progression --message="Setting up mosquitto..." --weight=5 #Installing packages @@ -161,7 +161,7 @@ fi #================================================= ynh_script_progression --message="Upgrading NGINX web server configuration..." -[[ "$mqtt_domain" != "$domain" ]] && ynh_add_config --template="../conf/mqtt_nginx.conf" --destination="/etc/nginx/conf.d/"$mqtt_domain".d/mqtt_"$app".conf" +[[ ! -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/ @@ -213,7 +213,8 @@ fi # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="$log_file" --failregex="^.*Error: Failed login attempt from .*$" --max_retry=5 -ynh_print_info --message="If you wish for Fail2ban to work, set up your local address in Setup/Settings/System/Local Networks as per documentation" +#not required in 2023.1 anymore +#ynh_print_info --message="If you wish for Fail2ban to work, set up your local address in Setup/Settings/System/Local Networks as per documentation" #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -221,7 +222,7 @@ ynh_print_info --message="If you wish for Fail2ban to work, set up your local ad ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add "$app" --description="Domotique open sources" --log="/var/log/$app/$app.log" -[[ "$mqtt_domain" != "$domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log" +[[ ! -z "$mqtt_domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log" #================================================= @@ -232,7 +233,7 @@ ynh_script_progression --message="Starting a systemd service..." --weight=3 ynh_systemd_action --service_name="$app" --action="start" #Restarting mosquitto to take changes from /etc/mosquitto/conf.d/*.conf into account -[[ "$mqtt_domain" != "$domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart" +[[ ! -z "$mqtt_domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart" #================================================= # END OF SCRIPT