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

Add mosquito services

Add mosquito service
solve package linter warning
This commit is contained in:
Krakinou 2022-04-24 23:58:20 +02:00
parent 0b16918389
commit e9ad40d581
14 changed files with 191 additions and 70 deletions

View file

@ -17,7 +17,7 @@
port_already_use=1
change_url=1
;;; Options
Email=
Email=nicolas@aubonalbanais.ovh
Notification=none
;;; Upgrade options
; commit=CommitHash

View file

@ -1,5 +1,5 @@
SOURCE_URL=http://www.domoticz.com/download.php?channel=release&type=release&system=__OS__&machine=__MACH__
SOURCE_SUM=__SHA256_SUM__
SOURCE_SUM=__SHA256__
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=false

View file

@ -0,0 +1,4 @@
listener __MQTT_PORT__
allow_anonymous false
password_file /etc/mosquitto/conf.d/credentials

View file

@ -16,13 +16,6 @@ location __PATH__/ {
#Allow upload until 10M to upload floorplan
client_max_body_size 10M;
# Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}
@ -63,9 +56,4 @@ location __API_PATH__/ {
return 403;
}
# Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
}

View file

@ -12,5 +12,38 @@ ExecStartPre=setcap 'cap_net_bind_service=+ep cap_net_raw=+eip' __FINALPATH__/do
Restart=on-failure
RestartSec=1m
#StandardOutput=null
# Sandboxing options to harden security
# Depending on specificities of your service/app, you may need to tweak these
# .. but this should be a good baseline
# Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
NoNewPrivileges=yes
PrivateTmp=yes
PrivateDevices=yes
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
DevicePolicy=closed
ProtectSystem=full
ProtectControlGroups=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
LockPersonality=yes
SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap
# Denying access to capabilities that should not be relevant for webapps
# Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html
CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD
CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_AUDIT_WRITE
CapabilityBoundingSet=~CAP_SYS_BOOT CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_PACCT
CapabilityBoundingSet=~CAP_LEASE CAP_LINUX_IMMUTABLE CAP_IPC_LOCK
CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_WAKE_ALARM
CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE
CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW
CapabilityBoundingSet=~CAP_SYS_ADMIN CAP_SYS_PTRACE CAP_SYSLOG
[Install]
WantedBy=multi-user.target

View file

@ -1,42 +1,42 @@
Domoticz est un système de domotique permettant de controler différents objets et de recevoir des données de divers senseurs
Il peut par exemple être utilisé avec :
Domoticz est un système de domotique permettant de controler différents objets et de recevoir des données de divers senseurs
Il peut par exemple être utilisé avec :
-des interrupteurs
-des senseurs de portes
-des sonnettes d'entrées
-des sonnettes d'entrées
-des systèmes de sécurité
-des systèmes de sécurité
-des stations météo pour les UV, la pluie, le vent...
-des stations météo pour les UV, la pluie, le vent...
-des sondes de températures
-des sondes de températures
-des sondes d'impulsions
-des voltmètres
-des voltmètres
-Et bien d'autres
**Version incluse :** Toujours la dernière version stable. La dernière version compilée est récupérée dans [ce répertoire](https://releases.domoticz.com/releases/?dir=./beta)
Une fois installée, **les mises à jour de l'application sont gérées depuis les menus de l'application elle même.**. Le script de mise à jour Yunohost mettra uniquement à jour de nouvelles version du package.
**Version incluse :** Toujours la dernière version stable. La dernière version compilée est récupérée dans [ce répertoire](https://releases.domoticz.com/releases/?dir=./beta)
Une fois installée, **les mises à jour de l'application sont gérées depuis les menus de l'application elle même.**. Le script de mise à jour Yunohost mettra uniquement à jour de nouvelles version du package.
## Configuration
### Senseurs, langue et ce genre de choses
Toute la configuration de l'application a lieu dans l'application elle même
Toute la configuration de l'application a lieu dans l'application elle même
Main configuration of the app take place inside the app itself.
### Accès et API
Par défaut, l'accès aux [API JSON](https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's) est autorisé sur cette URL `/votredomaine.tld/api_/chemindedomoticz`.
Donc, si vous accédez à domoticz par https://votredomaine.tld/domoticz, utilisez le chemin suivant pour l'api: `/votredomaine.tld/api_/domoticz/json.htm?votrecommandeapi`
### Accès et API
Par défaut, l'accès aux [API JSON](https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's) est autorisé sur cette URL `/votredomaine.tld/api_/chemindedomoticz`.
Donc, si vous accédez à domoticz par https://votredomaine.tld/domoticz, utilisez le chemin suivant pour l'api: `/votredomaine.tld/api_/domoticz/json.htm?votrecommandeapi`
Par défaut, seuls la mise à jour de senseur et les interrupteurs sont autorisés. Pour autoriser une nouvelle commande, vous devez (pour l'instant) manuellement éditer le fichier de configuration nginx :
Par défaut, seuls la mise à jour de senseur et les interrupteurs sont autorisés. Pour autoriser une nouvelle commande, vous devez (pour l'instant) manuellement éditer le fichier de configuration nginx :
````
sudo nano /etc/nginx/conf.d/yourdomain.tld.d/domoticz.conf
````
Puis éditer le bloc suivant en y ajoutant le regex de la commmande à autoriser :
Puis éditer le bloc suivant en y ajoutant le regex de la commmande à autoriser :
````
#set the list of authorized json command here in regex format
#you may retrieve the command from https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's
@ -45,7 +45,7 @@ Puis
set $api "1";
}
````
Par exemple, pour ajouter la commmande json pour retrouver le statut d'un équipement (/json.htm?type=devices&rid=IDX),il faut modifier la ligne comme ceci:
Par exemple, pour ajouter la commmande json pour retrouver le statut d'un équipement (/json.htm?type=devices&rid=IDX),il faut modifier la ligne comme ceci:
````
#set the list of authorized json command here in regex format
#you may retrieve the command from https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's
@ -55,15 +55,15 @@ Par exemple, pour ajouter la commmande json pour retrouver le statut d'un
}
````
Toutes les adresses IPv4 du réseau local (192.168.0.0/24) et toutes les adresses IPv6 sont autorisées pour l'API.
A ma connaissance, il n'y a pas moyen d'effectuer un filtre pour les adresses IPv6 sur le réseau local, vous pouvez donc retirer leur autorisation en enlevant ou en commentant la ligne suivante dans `/etc/nginx/conf.d/yourdomain.tld.d/domoticz.conf`:
Toutes les adresses IPv4 du réseau local (192.168.0.0/24) et toutes les adresses IPv6 sont autorisées pour l'API.
A ma connaissance, il n'y a pas moyen d'effectuer un filtre pour les adresses IPv6 sur le réseau local, vous pouvez donc retirer leur autorisation en enlevant ou en commentant la ligne suivante dans `/etc/nginx/conf.d/yourdomain.tld.d/domoticz.conf`:
````
allow ::/1;
````
Ceci autorisera seulement les adresses IPv4 local a accéder aux API de domoticz.
Vous pouvez ajouter des adresses IPv6 de la même façon.
Ceci autorisera seulement les adresses IPv4 local a accéder aux API de domoticz.
Vous pouvez ajouter des adresses IPv6 de la même façon.
## Limitations
* Pas de gestion d'utilisateurs ni d'intégration LDAP. L'application ne [prévoit pas de gérer les utilisateurs par LDAP](https://github.com/domoticz/domoticz/issues/838), donc le package non plus.
* Un backup ne peut pas être restauré sur un type de machine différente de celle d'origine (x86, arm...) car les sources compilées doivent être différente
* Pas de gestion d'utilisateurs ni d'intégration LDAP. L'application ne [prévoit pas de gérer les utilisateurs par LDAP](https://github.com/domoticz/domoticz/issues/838), donc le package non plus.
* Un backup ne peut pas être restauré sur un type de machine différente de celle d'origine (x86, arm...) car les sources compilées doivent être différentes

View file

@ -6,7 +6,7 @@
"en": "Very light weight open sources home automation system that lets you monitor and configure miscellaneous devices",
"fr": "Logiciel open sources et gratuit de domotique qui vous permet de configurer un grand nombre d'appareils"
},
"version": "2020.2~ynh3",
"version": "2020.2~ynh4",
"url": "https://www.domoticz.com",
"upstream": {
"license": "GPL-3.0-or-later",
@ -32,7 +32,6 @@
{
"name": "domain",
"type": "domain",
"example": "example.com"
},
{
"name": "path",

View file

@ -6,8 +6,10 @@
# dependencies used by the app
#python3-dev required as per https://www.domoticz.com/forum/viewtopic.php?f=65&t=16116&p=119747
#mosquitto and mosquitto-clients are required for mqtt
#other dependencies are from standard install script... seems quite useles...
pkg_dependencies="libudev-dev python3-dev"
extra_pkg_dependencies="mosquitto mosquitto-clients"
#ALL FOLLOWING LINE FROM THE upstream bash installation script
DEBIAN_ID=$(grep -oP '(?<=^ID=).+' /etc/*-release | tr -d '"')
@ -24,13 +26,13 @@ lowercase(){
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
}
OS=`lowercase \`uname -s\``
MACH=`uname -m`
if [ ${MACH} = "armv6l" ]
os=`lowercase \`uname -s\``
mach=`uname -m`
if [ ${mach} = "armv6l" ]
then
MACH="armv7l"
mach="armv7l"
fi
SHA256=$(wget -qO- https://releases.domoticz.com/releases/release/domoticz_${OS}_${MACH}.tgz.sha256sum | sed 's/ update.tgz//' | sed 's/ domoticz_linux_x86_64.tgz//')
sha256=$(wget -qO- https://releases.domoticz.com/releases/release/domoticz_${os}_${mach}.tgz.sha256sum | sed 's/ update.tgz//' | sed 's/ domoticz_linux_x86_64.tgz//')
#=================================================
# PERSONAL HELPERS

View file

@ -66,6 +66,8 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
ynh_backup --src_path="/etc/sudoers.d/$app"
ynh_backup --src_path="/etc/mosquitto/conf.d"
#=================================================
# END OF SCRIPT

View file

@ -30,15 +30,17 @@ ynh_script_progression --message="Loading installation settings..."
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
old_api=$(ynh_app_setting_get --app=$app --key=api_path)
old_mqtt=$(ynh_app_setting_get --app=$app --key=mqtt_path)
if [ "$new_path" == "/" ]; then
new_api=/api_/$app
new_mqtt=/mqtt/$app
else
new_api=/api_$new_path
new_mqtt=/mqtt$new_path
fi
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#=================================================
@ -98,6 +100,7 @@ then
domain="$old_domain"
path_url="$new_path"
api_path="$new_api"
mqtt_path="$new_mqtt"
# Create a dedicated NGINX config
ynh_add_nginx_config
fi
@ -124,6 +127,10 @@ ynh_app_setting_delete --app=$app --key="api_path"
ynh_app_setting_set --app=$app --key="api_path" --value=$new_api
ynh_permission_url --permission domoticz_API --url "$new_domain$new_api"
ynh_app_setting_delete --app=$app --key="mqtt_path"
ynh_app_setting_set --app=$app --key="mqtt_path" --value=$new_mqtt
ynh_permission_url --permission domoticz_MQTT --url "$new_domain$new_mqtt"
#=================================================
# GENERIC FINALISATION
#=================================================

View file

@ -32,8 +32,10 @@ app=$YNH_APP_INSTANCE_NAME
#Set dedicated variables
if [ "$path_url" == "/" ]; then
api_path=/api_/$app
mqtt_path=/mqtt/$app
else
api_path=/api_$path_url
mqtt_path=/mqtt$path_url
fi
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
@ -55,11 +57,12 @@ ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
#Will be used in restore script to check that we're restoring on the same OS/Board type
ynh_app_setting_set --app=$app --key=OS --value=$OS
ynh_app_setting_set --app=$app --key=mach --value=$MACH
ynh_app_setting_set --app=$app --key=OS --value=$os
ynh_app_setting_set --app=$app --key=mach --value=$mach
#path used by api to read/update domoticz
#path used by api & mqtt to read/update domoticz
ynh_app_setting_set --app=$app --key=api_path --value=$api_path
ynh_app_setting_set --app=$app --key=mqtt_path --value=$mqtt_path
#=================================================
# STANDARD MODIFICATIONS
@ -72,6 +75,9 @@ ynh_script_progression --message="Finding an available port..."
port=$(ynh_find_port --port=8080)
ynh_app_setting_set --app=$app --key=port --value=$port
mqtt_port=$(ynh_find_port --port=1883)
ynh_app_setting_set --app=$app --key=mqtt_port --value=$mqtt_port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
@ -99,9 +105,7 @@ if grep gpio -q < /etc/group; then
fi
#allow app user to restart service on startup
cp ../conf/sudoer ../conf/$app.conf
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/$app.conf"
mv ../conf/$app.conf /etc/sudoers.d/$app
ynh_add_config --template="../conf/sudoer" --destination="/etc/sudoers.d/$app"
chmod 440 /etc/sudoers.d/$app
#=================================================
@ -113,10 +117,7 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
# Create an app.src for the correct version of domoticz
# match string are fulfilled in _common.sh via the upstream bash installation script
cp ../conf/app.src.default ../conf/app.src
ynh_replace_string --match_string="__OS__" --replace_string="$OS" --target_file="../conf/app.src"
ynh_replace_string --match_string="__MACH__" --replace_string="$MACH" --target_file="../conf/app.src"
ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$SHA256" --target_file="../conf/app.src"
ynh_add_config --template="../conf/app.src.default" --destination="../conf/app.src"
ynh_setup_source --dest_dir="$final_path"
@ -130,6 +131,25 @@ chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# SET MOSQUITTO SETTINGS
#=================================================
ynh_script_progression --message="Setting up mosquitto..." --weight=5
#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"
#Setting up conf file for access
ynh_add_config --template="../conf/domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/domoticz_mosquitto.conf"
#Setting up user&pwd for mqtt access
ynh_app_setting_set --app=$app --key=mqtt_user --value=$(ynh_string_random --length=8)
ynh_app_setting_set --app=$app --key=mqtt_pwd --value=$(ynh_string_random)
echo $(ynh_app_setting_get --app=$app --key=mqtt_user):$(ynh_app_setting_get --app=$app --key=mqtt_pwd) > /etc/mosquitto/conf.d/credentials
mosquitto_passwd -U /etc/mosquitto/conf.d/credentials
ynh_print_info --message="The credential to the mosquitto server has been saved in the settings of the app"
#=================================================
# NGINX CONFIGURATION
#=================================================
@ -160,6 +180,8 @@ chown -R domoticz: /var/log/$app
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
ynh_use_logrotate --logfile="/var/log/mosquitto/"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
@ -167,6 +189,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"
yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
#=================================================
# START SYSTEMD SERVICE
@ -176,6 +199,9 @@ ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start"
#Restarting mosquitto to take changes into account
ynh_systemd_action --service_name=mosquitto --action="restart"
#=================================================
# SETUP SSOWAT
#=================================================
@ -189,8 +215,9 @@ then
ynh_permission_update --permission="main" --add="visitors"
fi
#API should stay publicly accessible.
#API & MQTT should stay publicly accessible.
ynh_permission_create --permission="domoticz_API" --url="$domain$api_path" --allowed="visitors"
ynh_permission_create --permission="domoticz_MQTT" --url="$domain$mqtt_path" --allowed="visitors"
#=================================================
# RELOAD NGINX

View file

@ -33,6 +33,7 @@ if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service integration..."
yunohost service remove $app
yunohost service remove mosquitto
fi
#=================================================
@ -85,6 +86,7 @@ ynh_script_progression --message="Removing various files..."
# Remove the log files
ynh_secure_remove --file="/var/log/$app"
ynh_secure_remove --file="/var/log/mosquitto"
#Delete the sudoer file
ynh_secure_remove --file="/etc/sudoers.d/$app"

View file

@ -33,24 +33,22 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
backup_OS=$(ynh_app_setting_get --app=$app --key=OS)
backup_mach=$(ynh_app_setting_get --app=$app --key=mach)
api_path=$(ynh_app_setting_get --app=$app --key=api_path)
mqtt_path=$(ynh_app_setting_get --app=$app --key=mqtt_path)
mqtt_user=$(ynh_app_setting_get --app=$app --key=mqtt_user)
mqtt_pwd=$(ynh_app_setting_get --app=$app --key=mqtt_pwd)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
#ynh_webpath_available --domain=$domain --path_url=$api_path \
# || ynh_die --message="Path not available: ${domain}${api_path}"
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#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 "$backup_OS" = "$OS" \
test "$backup_OS" = "$os" \
|| ynh_die --message="Cannot restore : previous OS is $backup_OS, current OS is $OS, please reinstall"
test "$backup_mach" = "$MACH" \
test "$backup_mach" = "$mach" \
|| ynh_die --message="Cannot restore : previous machine type is $backup_mach, current machine type is $MACH, please reinstall"
#=================================================
@ -105,6 +103,16 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=5
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SET MOSQUITTO SETTINGS
#=================================================
ynh_script_progression --message="Reinstalling up mosquitto..." --weight=5
#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"
#reinstalling settings
ynh_restore_file --origin_path="/etc/mosquitto/conf.d"
#=================================================
# RESTORE SYSTEMD
#=================================================
@ -119,6 +127,8 @@ 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"
yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
#=================================================
# START SYSTEMD SERVICE
@ -127,6 +137,9 @@ 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
ynh_systemd_action --service_name=mosquitto --action="restart"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
@ -136,6 +149,7 @@ mkdir -p /var/log/$app
chown -R domoticz: /var/log/$app
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_use_logrotate --logfile="/var/log/mosquitto/"
#=================================================
# GENERIC FINALIZATION

View file

@ -27,6 +27,7 @@ port=$(ynh_app_setting_get --app=$app --key=port)
current_OS=$(ynh_app_setting_get --app=$app --key=OS)
current_mach=$(ynh_app_setting_get --app=$app --key=mach)
api_path=$(ynh_app_setting_get --app=$app --key=api_path)
mqtt_path=$(ynh_app_setting_get --app=$app --key=mqtt_path)
#=================================================
# CHECK VERSION
@ -38,7 +39,7 @@ upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."0
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Ugly hack so that previous version backup script from "https://github.com/anubister/domoticz_ynh" works :
# It creates a dummy file in /etc/cron.d so that the backup do not fail.
@ -73,6 +74,7 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
@ -102,6 +104,17 @@ if [ -z "$api_path" ]; then
ynh_app_setting_set --app=$app --key=api_path --value=$api_path
fi
#Create a dedicated path for the api access
if [ -z "$mqtt_path" ]; then
if [ "$path_url" == "/" ]; then
mqtt_path=/mqtt/$app
else
mqtt_path=/mqtt$path_url
fi
ynh_app_setting_set --app=$app --key=mqtt_path --value=$mqtt_path
fi
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
@ -116,6 +129,14 @@ then
ynh_permission_create --permission="domoticz_API" --url="$domain$api_path" --allowed="visitors"
fi
# Create the permission "domoticz_MQTT" only if it doesn't exist.
if ! ynh_permission_exists --permission="domoticz_MQTT"
then
# API Authorization with dedicated URL
ynh_permission_create --permission="domoticz_MQTT" --url="$domain$mqtt_path" --allowed="visitors"
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
@ -136,9 +157,7 @@ if grep gpio -q < /etc/group; then
fi
#allow app user to restart service on startup
cp ../conf/sudoer ../conf/$app.conf
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/$app.conf"
mv ../conf/$app.conf /etc/sudoers.d/$app
ynh_add_config --template="../conf/sudoer" --destination="/etc/sudoers.d/$app"
chmod 440 /etc/sudoers.d/$app
#=================================================
@ -150,10 +169,7 @@ then
ynh_script_progression --message="Upgrading source files..." --weight=15
# Download, check integrity, uncompress and patch the source from app.src
cp ../conf/app.src.default ../conf/app.src
ynh_replace_string --match_string="__OS__" --replace_string="$OS" --target_file="../conf/app.src"
ynh_replace_string --match_string="__MACH__" --replace_string="$MACH" --target_file="../conf/app.src"
ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$SHA256" --target_file="../conf/app.src"
ynh_add_config --template="../conf/app.src.default" --destination="../conf/app.src"
ynh_setup_source --dest_dir="$final_path"
#Create the database file
if [ ! -f $final_path/domoticz.db ]; then
@ -166,6 +182,28 @@ chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# SET MOSQUITTO SETTINGS
#=================================================
ynh_script_progression --message="Setting up mosquitto..." --weight=5
#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"
#Setting up conf file for access
if [ ! -f "/etc/mosquitto/conf.d/domoticz_mosquitto.conf" ]
then
ynh_add_config --template="../conf/domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/domoticz_mosquitto.conf"
#Setting up user&pwd for mqtt access
ynh_app_setting_set --app=$app --key=mqtt_user --value=$(ynh_string_random --length=8)
ynh_app_setting_set --app=$app --key=mqtt_pwd --value=$(ynh_string_random)
echo $(ynh_app_setting_get --app=$app --key=mqtt_user):$(ynh_app_setting_get --app=$app --key=mqtt_pwd) > /etc/mosquitto/conf.d/credentials
mosquitto_passwd -U /etc/mosquitto/conf.d/credentials
ynh_print_info --message="The credential to the mosquitto server has been saved in the settings of the app"
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
@ -203,6 +241,7 @@ chown -R domoticz: /var/log/$app
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
ynh_use_logrotate --logfile="/var/log/mosquitto/" --non-append
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
@ -210,6 +249,7 @@ ynh_use_logrotate --non-append
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Domotique open sources" --log="/var/log/$app/$app.log"
yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
#=================================================
# START SYSTEMD SERVICE
@ -218,6 +258,9 @@ ynh_script_progression --message="Starting a systemd service..." --weight=3
ynh_systemd_action --service_name=$app --action="start"
#Restarting mosquitto to take changes into account
ynh_systemd_action --service_name=mosquitto --action="restart"
#=================================================
# RELOAD NGINX
#=================================================