diff --git a/conf/systemd.service b/conf/systemd.service index 9d04cef..d40db54 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -5,34 +5,33 @@ After=network.target [Service] User=__APP__ Group=__APP__ -ExecStart=__FINALPATH__/domoticz -www __PORT__ -sslwww 0 -log /var/log/__APP__/__APP__.log -loglevel normal,status,error -WorkingDirectory=__FINALPATH__/ +ExecStart=__INSTALL_DIR__/domoticz -www __PORT__ -sslwww 0 -log /var/log/__APP__/__APP__.log -loglevel normal,status,error +WorkingDirectory=__INSTALL_DIR__/ PermissionsStartOnly=true -ExecStartPre=setcap 'cap_net_bind_service=+ep cap_net_raw=+eip' __FINALPATH__/domoticz +ExecStartPre=setcap 'cap_net_bind_service=+ep cap_net_raw=+eip' __INSTALL_DIR__/domoticz 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 +# Most of the options are disabled as they prevent domoticz to correctly update +#NoNewPrivileges=yes PrivateTmp=yes #Private device restrict access to device in /dev/, so to any devices like razberry, zigate, etc. #PrivateDevices=yes -RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 -RestrictNamespaces=yes -RestrictRealtime=yes +#RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 +#RestrictNamespaces=yes +#RestrictRealtime=yes #Same : restrict access to devices #DevicePolicy=closed ProtectSystem=full ProtectControlGroups=yes -ProtectKernelModules=yes -ProtectKernelTunables=yes -LockPersonality=yes +#ProtectKernelModules=yes +#ProtectKernelTunables=yes +#LockPersonality=yes #@setuid prevent system call such as ping or other command lines -SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @swap +#SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @swap #SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap # Denying access to capabilities that should not be relevant for webapps diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..27a6209 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,72 @@ +packaging_format = 2 + +id = "domoticz" +name = "Domoticz" +description.en = "Home automation system that lets you monitor and configure miscellaneous devices" +description.fr = "Logiciel de domotique qui vous permet de configurer un grand nombre d'appareils" + +version = "2020.2~ynh8" + +maintainers = ["Krakinou"] + +[upstream] +license = "GPL-3.0-or-later" +website = "https://domoticz.com/" +admindoc = "https://www.domoticz.com/wiki/Main_Page" +userdoc = "https://www.domoticz.com/DomoticzManual.pdf" +code = "https://github.com/domoticz/domoticz" +cpe = "???" # FIXME: optional but recommended if relevant, this is meant to contain the Common Platform Enumeration, which is sort of a standard id for applications defined by the NIST. In particular, Yunohost may use this is in the future to easily track CVE (=security reports) related to apps. The CPE may be obtained by searching here: https://nvd.nist.gov/products/cpe/search. For example, for Nextcloud, the CPE is 'cpe:2.3:a:nextcloud:nextcloud' (no need to include the version number) +fund = "???" # FIXME: optional but recommended (or remove if irrelevant / not applicable). This is meant to be an URL where people can financially support this app, especially when its development is based on volunteers and/or financed by its community. YunoHost may later advertise it in the webadmin. + +[integration] +yunohost = ">= 11.0.0" +architectures = "all" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"] +multi_instance = false +ldap = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "sso" key : the "ldap" key corresponds to wether or not a user *can* login on the app using its YunoHost credentials. +sso = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "ldap" key : the "sso" key corresponds to wether or not a user is *automatically logged-in* on the app when logged-in on the YunoHost portal. +disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... +ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... + +[install] + [install.domain] + # this is a generic question - ask strings are automatically handled by Yunohost's core + type = "domain" + + [install.path] + # this is a generic question - ask strings are automatically handled by Yunohost's core + type = "path" + default = "/domoticz" + + [install.init_main_permission] + help.fr = "Attention, cette application n'a pas de gestion d'utilisateur par défaut, si vous la mettez public, n importe qui y aura accès!" + help.en = "Beware, there is no user management by default. If it's set as public, anyone will have access!" + type = "group" + default = false + + [install.mqtt_domain] + ask.fr = "Domaine MQTT" + ask.en = "MQTT domain" + help.fr = "Domaine pour le serveur MQTT. Remettez le domaine principal si vous ne souhaitez pas l'utiliser. Lire la documentation pour plus d'informations" + help.en = "MQTT server domain. Set the main domain if you don't wish to use it. See the doc for more info" + type = "domain" + optional = true + +[resources] + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + main.url = "/" + + [resources.ports] + main.default = 8080 + + [resources.apt] + packages = "libudev-dev, python3-dev, mosquitto, mosquitto-clients, $pkg_dependencies, $add_dep" + + [[resources.apt.extras]] + repo = "deb https://repo.mosquitto.org/debian buster main" + key = "http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key" + packages = "#FIXME#$extra_pkg_dependencies \ No newline at end of file diff --git a/scripts/_common.sh b/scripts/_common.sh index abc64c6..b8f6638 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -8,8 +8,8 @@ #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" +#REMOVEME? pkg_dependencies="libudev-dev python3-dev" +#REMOVEME? extra_pkg_dependencies="mosquitto mosquitto-clients" default_mqtt_port=1883 default_mqtt_websocket_port=8883 @@ -23,7 +23,7 @@ then else add_dep="libcurl4 libusb-0.1-4" fi; -pkg_dependencies="$pkg_dependencies $add_dep" +#REMOVEME? pkg_dependencies="$pkg_dependencies $add_dep" lowercase(){ echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" diff --git a/scripts/backup b/scripts/backup index ff2c423..0c62fca 100755 --- a/scripts/backup +++ b/scripts/backup @@ -14,22 +14,22 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +#REMOVEME? ynh_clean_setup () { ynh_clean_check_starting -} +#} # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info --message="Loading installation settings..." +#REMOVEME? ynh_print_info --message="Loading installation settings..." -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -domain=$(ynh_app_setting_get --app=$app --key=domain) -mqtt_domain=$(ynh_app_setting_get --app=$app --key=mqtt_domain) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? mqtt_domain=$(ynh_app_setting_get --app=$app --key=mqtt_domain) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -40,7 +40,7 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/install b/scripts/install index 23e8a5f..6e83340 100755 --- a/scripts/install +++ b/scripts/install @@ -13,42 +13,42 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +#REMOVEME? ynh_clean_setup () { ynh_clean_check_starting -} +#} # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -domain="$YNH_APP_ARG_DOMAIN" -path_url="$YNH_APP_ARG_PATH" -is_public="$YNH_APP_ARG_IS_PUBLIC" -mqtt_domain="$YNH_APP_ARG_MQTT_DOMAIN" +#REMOVEME? domain="$YNH_APP_ARG_DOMAIN" +#REMOVEME? path="$YNH_APP_ARG_PATH" +#REMOVEME? is_public="$YNH_APP_ARG_IS_PUBLIC" +#REMOVEME? mqtt_domain="$YNH_APP_ARG_MQTT_DOMAIN" -app="$YNH_APP_INSTANCE_NAME" +#REMOVEME? app="$YNH_APP_INSTANCE_NAME" #Set dedicated variables -if [ "$path_url" == "/" ]; then +if [ "$path" == "/" ]; then api_path=/api_/"$app" else - api_path=/api_"$path_url" + api_path=/api_"$path" fi #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_script_progression --message="Validating installation parameters..." +#REMOVEME? ynh_script_progression --message="Validating installation parameters..." -final_path=/opt/yunohost/"$app" -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" +#REMOVEME? install_dir=/opt/yunohost/"$app" +#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder" # Register (book) web path -ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url" +#REMOVEME? ynh_webpath_register --app="$app" --domain="$domain" --path="$path" #impossible de booker plusieurs webpath #if [ ! -z $mqtt_domain ]; then -# ynh_webpath_register --app=mqtt_$app --domain=$mqtt_domain --path_url="/" +#REMOVEME? # ynh_webpath_register --app=mqtt_$app --domain=$mqtt_domain --path="/" #fi if [ "$domain" == "$mqtt_domain" ]; then @@ -58,18 +58,18 @@ fi #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." +#REMOVEME? ynh_script_progression --message="Storing installation settings..." -ynh_app_setting_set --app="$app" --key=domain --value="$domain" -ynh_app_setting_set --app="$app" --key=path --value="$path_url" +#REMOVEME? ynh_app_setting_set --app="$app" --key=domain --value="$domain" +#REMOVEME? ynh_app_setting_set --app="$app" --key=path --value="$path" #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" #path used by api & mqtt to read/update domoticz -ynh_app_setting_set --app="$app" --key=api_path --value="$api_path" -[[ ! -z "$mqtt_domain" ]] && ynh_app_setting_set --app="$app" --key=mqtt_domain --value="$mqtt_domain" +#REMOVEME? ynh_app_setting_set --app="$app" --key=api_path --value="$api_path" +#REMOVEME? [[ ! -z "$mqtt_domain" ]] && ynh_app_setting_set --app="$app" --key=mqtt_domain --value="$mqtt_domain" #================================================= @@ -80,32 +80,32 @@ ynh_app_setting_set --app="$app" --key=api_path --value="$api_path" ynh_script_progression --message="Finding available port..." # Find an available port -port=$(ynh_find_port --port=8080) -ynh_app_setting_set --app="$app" --key=port --value="$port" +#REMOVEME? port=$(ynh_find_port --port=8080) +#REMOVEME? ynh_app_setting_set --app="$app" --key=port --value="$port" if [ ! -z "$mqtt_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" +#REMOVEME? mqtt_port=$(ynh_find_port --port="$default_mqtt_port") +#REMOVEME? 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" +#REMOVEME? mqtt_websocket_port=$(ynh_find_port --port="$default_mqtt_websocket_port") +#REMOVEME? ynh_app_setting_set --app="$app" --key=mqtt_websocket_port --value="$mqtt_websocket_port" fi #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=15 +#REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=15 -ynh_install_app_dependencies "$pkg_dependencies" +#REMOVEME? ynh_install_app_dependencies "$pkg_dependencies" #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user..." +#REMOVEME? ynh_script_progression --message="Configuring system user..." # Create a system user -ynh_system_user_create --username="$app" --home_dir="$final_path" +#REMOVEME? ynh_system_user_create --username="$app" --home_dir="$install_dir" #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 @@ -127,23 +127,23 @@ chmod 440 /etc/sudoers.d/"$app" #================================================= ynh_script_progression --message="Setting up source files..." --weight=5 -ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" +#REMOVEME? ynh_app_setting_set --app="$app" --key=install_dir --value="$install_dir" # 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 ynh_add_config --template="../conf/app.src.default" --destination="../conf/app.src" -ynh_setup_source --dest_dir="$final_path" +ynh_setup_source --dest_dir="$install_dir" #Create the database file -if [ ! -f "$final_path"/domoticz.db ]; then - touch "$final_path"/domoticz.db - chmod 640 "$final_path"/domoticz.db +if [ ! -f "$install_dir"/domoticz.db ]; then + touch "$install_dir"/domoticz.db + chmod 640 "$install_dir"/domoticz.db fi -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R "$app":"$app" "$final_path" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R "$app":"$app" "$install_dir" #================================================= @@ -154,7 +154,7 @@ if [ ! -z "$mqtt_domain" ]; then 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" +#REMOVEME? 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/"$app"_mosquitto.conf" @@ -163,7 +163,7 @@ if [ ! -z "$mqtt_domain" ]; then #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/"$app"_credentials" +#REMOVEME? echo $(ynh_app_setting_get --app="$app" --key=mqtt_user):$(ynh_app_setting_get --app="$app" --key=mqtt_pwd) > "/etc/mosquitto/conf.d/"$app"_credentials" mosquitto_passwd -U "/etc/mosquitto/conf.d/"$app"_credentials" ynh_print_info --message="The credential to the mosquitto server has been saved in the settings of the app" @@ -249,27 +249,27 @@ ynh_print_info --message="If you wish for Fail2ban to work, set up your local ad #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring permissions..." +#REMOVEME? ynh_script_progression --message="Configuring permissions..." # Make app public if necessary -if [ "$is_public" -eq 1 ] +#REMOVEME? if [ "$is_public" -eq 1 ] then # Everyone can access the app. # The "main" permission is automatically created before the install script. - ynh_permission_update --permission="main" --add="visitors" +#REMOVEME? ynh_permission_update --permission="main" --add="visitors" fi #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" -[[ ! -z "$mqtt_domain" ]] && ynh_permission_create --permission="domoticz_MQTT" --label="MQTT" --url="$mqtt_domain" --allowed="visitors" --show_tile="false" --protected="true" +#REMOVEME? ynh_permission_create --permission="domoticz_API" --label="api" --url="$domain$api_path" --allowed="visitors" --show_tile="false" --protected="true" +#REMOVEME? [[ ! -z "$mqtt_domain" ]] && ynh_permission_create --permission="domoticz_MQTT" --label="MQTT" --url="$mqtt_domain" --allowed="visitors" --show_tile="false" --protected="true" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." +#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." -ynh_systemd_action --service_name=nginx --action=reload +#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 9304492..376d7df 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,14 +12,14 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +#REMOVEME? ynh_script_progression --message="Loading installation settings..." -app="$YNH_APP_INSTANCE_NAME" +#REMOVEME? app="$YNH_APP_INSTANCE_NAME" -domain=$(ynh_app_setting_get --app="$app" --key=domain) -port=$(ynh_app_setting_get --app="$app" --key=port) -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) -mqtt_domain=$(ynh_app_setting_get --app="$app" --key=mqtt_domain) +#REMOVEME? domain=$(ynh_app_setting_get --app="$app" --key=domain) +#REMOVEME? port=$(ynh_app_setting_get --app="$app" --key=port) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app="$app" --key=install_dir) +#REMOVEME? mqtt_domain=$(ynh_app_setting_get --app="$app" --key=mqtt_domain) #================================================= # STANDARD REMOVE @@ -57,19 +57,19 @@ fi #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." --weight=3 +#REMOVEME? ynh_script_progression --message="Removing dependencies..." --weight=3 # Remove metapackage and its dependencies [[ ! -z "$mqtt_domain" ]] && ynh_secure_remove --file="/etc/mosquitto/conf.d" -ynh_remove_app_dependencies +#REMOVEME? ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." --weight=3 +#REMOVEME? ynh_script_progression --message="Removing app main directory..." --weight=3 # Remove the app directory securely -ynh_secure_remove --file="$final_path" +#REMOVEME? ynh_secure_remove --file="$install_dir" #================================================= # REMOVE NGINX CONFIGURATION @@ -122,13 +122,13 @@ ynh_secure_remove --file="/etc/sudoers.d/$app" #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user..." +#REMOVEME? ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user -ynh_system_user_delete --username="$app" +#REMOVEME? ynh_system_user_delete --username="$app" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression --message="Removal of $app completed" --last \ No newline at end of file diff --git a/scripts/restore b/scripts/restore index d6e51db..13a9e59 100755 --- a/scripts/restore +++ b/scripts/restore @@ -14,32 +14,32 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +#REMOVEME? ynh_clean_setup () { ynh_clean_check_starting -} +#} # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +#REMOVEME? ynh_script_progression --message="Loading installation settings..." -app="$YNH_APP_INSTANCE_NAME" +#REMOVEME? app="$YNH_APP_INSTANCE_NAME" -domain=$(ynh_app_setting_get --app="$app" --key=domain) -path_url=$(ynh_app_setting_get --app="$app" --key=path) -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) -mqtt_domain=$(ynh_app_setting_get --app="$app" --key=mqtt_domain) +#REMOVEME? domain=$(ynh_app_setting_get --app="$app" --key=domain) +#REMOVEME? path=$(ynh_app_setting_get --app="$app" --key=path) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app="$app" --key=install_dir) +#REMOVEME? backup_OS=$(ynh_app_setting_get --app="$app" --key=OS) +#REMOVEME? backup_mach=$(ynh_app_setting_get --app="$app" --key=mach) +#REMOVEME? mqtt_domain=$(ynh_app_setting_get --app="$app" --key=mqtt_domain) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." -test ! -d "$final_path" \ - || ynh_die --message="There is already a directory: $final_path " +#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." +#REMOVEME? test ! -d "$install_dir" \ + || ynh_die --message="There is already a directory: $install_dir " #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. @@ -62,10 +62,10 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$mqtt_domain.d/mqtt_$app.conf" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." +#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." # Create the dedicated user (if not existing) -ynh_system_user_create --username="$app" --home_dir="$final_path" +#REMOVEME? ynh_system_user_create --username="$app" --home_dir="$install_dir" #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 @@ -86,21 +86,21 @@ ynh_restore_file --origin_path="/etc/sudoers.d/$app" #================================================= ynh_script_progression --message="Restoring the app main directory..." --weight=5 -ynh_restore_file --origin_path="$final_path" +ynh_restore_file --origin_path="$install_dir" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R "$app":"$app" "$final_path" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R "$app":"$app" "$install_dir" #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=5 +#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=5 # Define and install dependencies -ynh_install_app_dependencies "$pkg_dependencies" +#REMOVEME? ynh_install_app_dependencies "$pkg_dependencies" #================================================= # SET MOSQUITTO SETTINGS @@ -109,7 +109,7 @@ if [ ! -z "$mqtt_domain" ]; then 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" +#REMOVEME? 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" --not_mandatory fi diff --git a/scripts/upgrade b/scripts/upgrade index f2c0390..e165e1b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -16,20 +16,20 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +#REMOVEME? ynh_script_progression --message="Loading installation settings..." -app="$YNH_APP_INSTANCE_NAME" +#REMOVEME? app="$YNH_APP_INSTANCE_NAME" -domain=$(ynh_app_setting_get --app="$app" --key=domain) -path_url=$(ynh_app_setting_get --app="$app" --key=path) -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) -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_domain=$(ynh_app_setting_get --app="$app" --key=mqtt_domain) -mqtt_port=$(ynh_app_setting_get --app="$app" --key=mqtt_port) -mqtt_websocket_port=$(ynh_app_setting_get --app="$app" --key=mqtt_websocket_port) +#REMOVEME? domain=$(ynh_app_setting_get --app="$app" --key=domain) +#REMOVEME? path=$(ynh_app_setting_get --app="$app" --key=path) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app="$app" --key=install_dir) +#REMOVEME? port=$(ynh_app_setting_get --app="$app" --key=port) +#REMOVEME? current_OS=$(ynh_app_setting_get --app="$app" --key=OS) +#REMOVEME? current_mach=$(ynh_app_setting_get --app="$app" --key=mach) +#REMOVEME? api_path=$(ynh_app_setting_get --app="$app" --key=api_path) +#REMOVEME? mqtt_domain=$(ynh_app_setting_get --app="$app" --key=mqtt_domain) +#REMOVEME? mqtt_port=$(ynh_app_setting_get --app="$app" --key=mqtt_port) +#REMOVEME? mqtt_websocket_port=$(ynh_app_setting_get --app="$app" --key=mqtt_websocket_port) #================================================= # CHECK VERSION @@ -41,7 +41,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)..." +#REMOVEME? 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. @@ -52,12 +52,12 @@ if version_gt "4.9701" "$current_upstream_version" && version_gt "2" "$current_p fi # Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { +#REMOVEME? ynh_backup_before_upgrade +#REMOVEME? ynh_clean_setup () { ynh_clean_check_starting # Restore it if the upgrade fails - ynh_restore_upgradebackup -} +#REMOVEME? ynh_restore_upgradebackup +#} #remove ugly hack if [ -f /etc/cron.d/"$app" ]; then @@ -65,7 +65,7 @@ if [ -f /etc/cron.d/"$app" ]; then fi # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS @@ -89,20 +89,20 @@ if [ -z "$current_mach" ]; then ynh_app_setting_set --app="$app" --key=mach --value="$MACH" fi -# If final_path doesn't exist, create it -if [ -z "$final_path" ]; then - final_path=/var/www/"$app" - ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" +# If install_dir doesn't exist, create it +if [ -z "$install_dir" ]; then +#REMOVEME? install_dir=/var/www/"$app" +#REMOVEME? ynh_app_setting_set --app="$app" --key=install_dir --value="$install_dir" fi #Create a dedicated path for the api access if [ -z "$api_path" ]; then - if [ "$path_url" == "/" ]; then + if [ "$path" == "/" ]; then api_path=/api_/"$app" else - api_path=/api_"$path_url" + api_path=/api_"$path" fi - ynh_app_setting_set --app="$app" --key=api_path --value="$api_path" +#REMOVEME? ynh_app_setting_set --app="$app" --key=api_path --value="$api_path" fi #Create a dedicated path for the mqtt access @@ -112,38 +112,39 @@ fi #Port to listen for MQTT internal if [[ -z "$mqtt_port" && ! -z "$mqtt_domain" ]]; then - mqtt_port=$(ynh_find_port --port="$default_mqtt_port") - ynh_app_setting_set --app="$app" --key=mqtt_port --value="$mqtt_port" +#REMOVEME? mqtt_port=$(ynh_find_port --port="$default_mqtt_port") +#REMOVEME? ynh_app_setting_set --app="$app" --key=mqtt_port --value="$mqtt_port" fi #Port to listen for MQTT websocket if [[ -z "$mqtt_websocket_port" && ! -z "$mqtt_domain" ]]; then - 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" +#REMOVEME? mqtt_websocket_port=$(ynh_find_port --port="$default_mqtt_websocket_port") +#REMOVEME? ynh_app_setting_set --app="$app" --key=mqtt_websocket_port --value="$mqtt_websocket_port" fi + # Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all +#REMOVEME? if ynh_legacy_permissions_exists; then +#REMOVEME? ynh_legacy_permissions_delete_all ynh_app_setting_delete --app="$app" --key=is_public fi # Create the permission "domoticz_API" only if it doesn't exist. -if ! ynh_permission_exists --permission="domoticz_API" +#REMOVEME? if ! ynh_permission_exists --permission="domoticz_API" then # API Authorization with dedicated URL - ynh_permission_create --permission="domoticz_API" --label="api" --url="$domain$api_path" --allowed="visitors" --show_tile="false" --protected="true" +#REMOVEME? ynh_permission_create --permission="domoticz_API" --label="api" --url="$domain$api_path" --allowed="visitors" --show_tile="false" --protected="true" fi # Create the permission "domoticz_MQTT" only if it doesn't exist. if [ ! -z "$mqtt_domain" ]; then - if ! ynh_permission_exists --permission="domoticz_MQTT" +#REMOVEME? if ! ynh_permission_exists --permission="domoticz_MQTT" then # API Authorization with dedicated URL - ynh_permission_create --permission="domoticz_MQTT" --label="MQTT" --url="$mqtt_domain" --allowed="visitors" --show_tile="false" --protected="true" +#REMOVEME? ynh_permission_create --permission="domoticz_MQTT" --label="MQTT" --url="$mqtt_domain" --allowed="visitors" --show_tile="false" --protected="true" fi fi @@ -155,10 +156,10 @@ fi #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." +#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) -ynh_system_user_create --username="$app" --home_dir="$final_path" +#REMOVEME? ynh_system_user_create --username="$app" --home_dir="$install_dir" #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 @@ -185,17 +186,17 @@ then # Download, check integrity, uncompress and patch the source from app.src ynh_add_config --template="../conf/app.src.default" --destination="../conf/app.src" - ynh_setup_source --dest_dir="$final_path" + ynh_setup_source --dest_dir="$install_dir" #Create the database file - if [ ! -f "$final_path"/domoticz.db ]; then - touch "$final_path"/domoticz.db - chmod 644 "$final_path"/domoticz.db + if [ ! -f "$install_dir"/domoticz.db ]; then + touch "$install_dir"/domoticz.db + chmod 644 "$install_dir"/domoticz.db fi fi -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R "$app":"$app" "$final_path" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R "$app":"$app" "$install_dir" #================================================= # SET MOSQUITTO SETTINGS @@ -204,7 +205,7 @@ if [ ! -z "$mqtt_domain" ]; then 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" +#REMOVEME? 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/"$app"_mosquitto.conf" ] @@ -215,7 +216,7 @@ if [ ! -z "$mqtt_domain" ]; then #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/"$app"_credentials" +#REMOVEME? echo $(ynh_app_setting_get --app="$app" --key=mqtt_user):$(ynh_app_setting_get --app="$app" --key=mqtt_pwd) > "/etc/mosquitto/conf.d/"$app"_credentials" mosquitto_passwd -U "/etc/mosquitto/conf.d/"$app"_credentials" ynh_print_info --message="The credential to the mosquitto server has been saved in the settings of the app" @@ -245,9 +246,9 @@ ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=5 +#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=5 -ynh_install_app_dependencies "$pkg_dependencies" +#REMOVEME? ynh_install_app_dependencies "$pkg_dependencies" #================================================= # SPECIFIC UPGRADE @@ -310,9 +311,9 @@ ynh_systemd_action --service_name="$app" --action="start" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." +#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." -ynh_systemd_action --service_name=nginx --action=reload +#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT