diff --git a/README.md b/README.md index adc7d68..9b1e2d1 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in [Mosquitto](https://mosquitto.org/) gives you interconnect your objects and applications with an open source MQTT broker. Client can publish or subscribe after authentication (username, password). -**Shipped version:** 2.0.14~ynh1 +**Shipped version:** 2.0.14~ynh2 **Demo:** https://test.mosquitto.org ## Documentation and resources diff --git a/README_fr.md b/README_fr.md index e096cd4..58b2916 100644 --- a/README_fr.md +++ b/README_fr.md @@ -19,7 +19,7 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po [Mosquitto](https://mosquitto.org/) vous permet d'interconnecter vos objets et applications avec un broker MQTT open source. Le client peut publier ou s'abonner après authentification (nom d'utilisateur, mot de passe). -**Version incluse :** 2.0.14~ynh1 +**Version incluse :** 2.0.14~ynh2 **Démo :** https://test.mosquitto.org ## Documentations et ressources diff --git a/check_process b/check_process deleted file mode 100644 index 47b83d8..0000000 --- a/check_process +++ /dev/null @@ -1,16 +0,0 @@ -;; Test complet - ; Manifest - username="mosquitto" - userpass="mosquitto" - port="1883" - ; Checks - pkg_linter=1 - setup_nourl=1 - upgrade=1 - # 2.0.12~ynh1 - upgrade=1 from_commit=eb74d6d63a8bc8561d124429c9fa3bdb8f6af7a0 - backup_restore=1 - port_already_use=1 (1883) -;;; Options -Email=grena+mosquitto@grenabox.fr -Notification=yes diff --git a/manifest.json b/manifest.json deleted file mode 100644 index c4b8e52..0000000 --- a/manifest.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "Mosquitto", - "id": "mosquitto", - "packaging_format": 1, - "description": { - "en": "Interconnect your objects and applications with an open source MQTT broker", - "fr": "Interconnecter vos objets et vos applications grâce à un serveur MQTT open source" - }, - "version": "2.0.14~ynh1", - "url": "https://mosquitto.org/", - "upstream": { - "license": "MIT", - "website": "https://mosquitto.org", - "demo": "https://test.mosquitto.org", - "admindoc": "https://mosquitto.org/documentation/", - "code": "https://github.com/eclipse/mosquitto", - "cpe": "cpe:2.3:a:eclipse:mosquitto" - }, - "license": "MIT", - "maintainer": { - "name": "Grena", - "email": "grena+mosquitto@grenabox.fr" - }, - "requirements": { - "yunohost": ">= 11.0.0" - }, - "multi_instance": false, - "services": [], - "arguments": { - "install": [ - { - "name": "username", - "type": "string", - "ask": { - "en": "Set the username for client authentication", - "fr": "Définissez le nom d'utilisateur pour l'authentification du client" - }, - "example": "mosquitto", - "default": "mosquitto" - }, - { - "name": "userpass", - "type": "password", - "ask": { - "en": "Set the password for client authentication", - "fr": "Définissez le mot de passe pour l'authentification du client" - } - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..9cbd3e9 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,62 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "mosquitto" +name = "Mosquitto" +description.en = "Interconnect your objects and applications with an open source MQTT broker" +description.fr = "Interconnecter vos objets et vos applications grâce à un serveur MQTT open source" + +version = "2.0.14~ynh2" + +maintainers = ["Grena"] + +[upstream] +license = "MIT" +website = "https://mosquitto.org" +demo = "https://test.mosquitto.org" +admindoc = "https://mosquitto.org/documentation/" +code = "https://github.com/eclipse/mosquitto" +cpe = "cpe:2.3:a:eclipse:mosquitto" + +[integration] +yunohost = ">= 11.0.0" +architectures = "all" +multi_instance = false +ldap = false +sso = false +disk = "50M" +ram.build = "100M" +ram.runtime = "10M" + +[install] + [install.username] + ask.en = "Set the username for client authentication" + ask.fr = "Définissez le nom d'utilisateur pour l'authentification du client" + type = "string" + example = "mosquitto" + default = "mosquitto" + + [install.userpass] + ask.en = "Set the password for client authentication" + ask.fr = "Définissez le mot de passe pour l'authentification du client" + type = "password" + +[resources] + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + + [resources.ports] + main.default = 1883 + main.exposed = "TCP" + + [resources.apt] + packages = "mosquitto" + + [resources.apt.extras.mosquitto] + repo = "deb https://repo.mosquitto.org/debian bullseye main" + key = "http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key" + packages = ["mosquitto"] diff --git a/scripts/_common.sh b/scripts/_common.sh index 617436e..944a65e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,9 +4,6 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -extra_pkg_dependencies="mosquitto" - #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 10637f0..030a73e 100755 --- a/scripts/backup +++ b/scripts/backup @@ -10,24 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -port=$(ynh_app_setting_get --app=$app --key=port) -username=$(ynh_app_setting_get --app=$app --key=username) -userpass=$(ynh_app_setting_get --app=$app --key=userpass) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -51,6 +33,8 @@ ynh_backup --src_path="/etc/mosquitto/passwd" # Backup the config file ynh_backup --src_path="/etc/mosquitto/conf.d/default.conf" +ynh_backup --src_path="/var/log/$app/" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index b9f40a8..fe9c6e0 100644 --- a/scripts/install +++ b/scripts/install @@ -10,50 +10,11 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INITIALIZE AND STORE SETTINGS #================================================= -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -username=$YNH_APP_ARG_USERNAME -userpass=$YNH_APP_ARG_USERPASS - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." --weight=1 - -ynh_app_setting_set --app=$app --key=username --value=$username -ynh_app_setting_set --app=$app --key=userpass --value=$userpass - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -ynh_script_progression --message="Finding an available port..." --weight=1 - -# Find an available port -port=$(ynh_find_port --port=1883) -ynh_app_setting_set --app=$app --key=port --value=$port - -# Open the port -ynh_script_progression --message="Configuring firewall..." --weight=1 -ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port - -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=20 - -ynh_install_extra_app_dependencies --repo="deb https://repo.mosquitto.org/debian bullseye main" --package="$extra_pkg_dependencies" --key="http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key" --name="$app" +# Passwords aren't saved by default +ynh_app_setting_set --app="$app" --key=userpass --value="$userpass" #================================================= # SPECIFIC SETUP @@ -62,28 +23,24 @@ ynh_install_extra_app_dependencies --repo="deb https://repo.mosquitto.org/debian #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 -ynh_add_config --template="../conf/passwd" --destination="/etc/mosquitto/passwd" +ynh_add_config --template="mosquitto.conf" --destination="/etc/mosquitto/conf.d/default.conf" +ynh_add_config --template="passwd" --destination="/etc/mosquitto/passwd" + mosquitto_passwd -U "/etc/mosquitto/passwd" ynh_store_file_checksum --file="/etc/mosquitto/passwd" -ynh_add_config --template="../conf/mosquitto.conf" --destination="/etc/mosquitto/conf.d/default.conf" +# Hard coded username because deb package creates the user +chown -R "mosquitto" "/etc/mosquitto" #================================================= -# GENERIC FINALIZATION +# SYSTEM CONFIGURATION #================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=1 +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 # Use logrotate to manage application logfile(s) ynh_use_logrotate -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description="Allows MQTT clients to send/receive data" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port" +yunohost service add "$app" --description="Allows MQTT clients to send/receive data" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port" #================================================= # START SYSTEMD SERVICE @@ -91,7 +48,7 @@ yunohost service add $app --description="Allows MQTT clients to send/receive dat ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="restart" +ynh_systemd_action --service_name="$app" --action="restart" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index e0de391..90333b3 100755 --- a/scripts/remove +++ b/scripts/remove @@ -10,61 +10,24 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=2 - -app=$YNH_APP_INSTANCE_NAME - -port=$(ynh_app_setting_get --app=$app --key=port) - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null -then - ynh_script_progression --message="Removing $app service integration..." --weight=1 - yunohost service remove $app +if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then + yunohost service remove "$app" fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 - # Remove the dedicated systemd config +# It seems the simple stop is not enough… +ynh_systemd_action --service_name="$app" --action="stop" +pkill -u "$app" || true ynh_remove_systemd_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 - # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=6 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $port$" -then - ynh_script_progression --message="Closing port $port..." --weight=2 - ynh_exec_warn_less yunohost firewall disallow TCP $port -fi - #================================================= # SPECIFIC REMOVE #================================================= @@ -73,7 +36,7 @@ fi ynh_script_progression --message="Removing various files..." --weight=1 # Remove the log files -ynh_secure_remove --file="/var/log/$app/$app.log" +ynh_secure_remove --file="/var/log/$app" # Remove the passwd file ynh_secure_remove --file="/etc/mosquitto/passwd" diff --git a/scripts/restore b/scripts/restore index bbb2a48..efa60c8 100755 --- a/scripts/restore +++ b/scripts/restore @@ -11,63 +11,34 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# RESTORE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors +ynh_restore_file --origin_path="/etc/logrotate.d/$app" -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -port=$(ynh_app_setting_get --app=$app --key=port) -username=$(ynh_app_setting_get --app=$app --key=username) -userpass=$(ynh_app_setting_get --app=$app --key=userpass) - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=20 - -ynh_install_extra_app_dependencies --repo="deb https://repo.mosquitto.org/debian bullseye main" --package="$extra_pkg_dependencies" --key="http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key" --name="$app" +yunohost service add "$app" --description="Allows MQTT clients to send/receive data" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port" #================================================= # RESTORE VARIOUS FILES #================================================= ynh_script_progression --message="Restoring various files..." --weight=1 -# Restore the passwd file +ynh_restore_file --origin_path="/etc/mosquitto/conf.d/default.conf" ynh_restore_file --origin_path="/etc/mosquitto/passwd" -# Restore the config file -ynh_restore_file --origin_path="/etc/mosquitto/conf.d/default.conf" +ynh_restore_file --origin_path="/var/log/$app/" -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description="Allows MQTT clients to send/receive data" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port" +# Hard coded username because deb package creates the user +chown -R "mosquitto" "/etc/mosquitto" +chown -R "mosquitto" "/var/log/$app/" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="restart" +ynh_systemd_action --service_name="$app" --action="restart" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index bb6c716..516bae8 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,45 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -port=$(ynh_app_setting_get --app=$app --key=port) -username=$(ynh_app_setting_get --app=$app --key=username) -userpass=$(ynh_app_setting_get --app=$app --key=userpass) - -# Transfer and delete the old "password" key -if [ -z "$userpass" ]; then - ynh_app_setting_set --app=$app --key=userpass --value=$(ynh_app_setting_get --app=$app --key=password) - ynh_app_setting_delete --app=$app --key=password - userpass=$(ynh_app_setting_get --app=$app --key=userpass) -fi - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." - -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)..." --weight=5 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -55,19 +16,19 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Stopping a systemd service..." -ynh_systemd_action --service_name=$app --action="stop" +ynh_systemd_action --service_name="$app" --action="stop" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=10 - -ynh_install_extra_app_dependencies --repo="deb https://repo.mosquitto.org/debian bullseye main" --package="$extra_pkg_dependencies" --key="http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key" --name="$app" +# Transfer and delete the old "password" key +if [ -z "${userpass:-}" ]; then + userpass="$password" + ynh_app_setting_set --app="$app" --key="userpass" --value="$userpass" + ynh_app_setting_delete --app="$app" --key="password" +fi #================================================= # SPECIFIC UPGRADE @@ -76,36 +37,32 @@ ynh_install_extra_app_dependencies --repo="deb https://repo.mosquitto.org/debian #================================================= ynh_script_progression --message="Updating a configuration file..." --weight=1 -ynh_add_config --template="../conf/passwd" --destination="/etc/mosquitto/passwd" +ynh_add_config --template="mosquitto.conf" --destination="/etc/mosquitto/conf.d/default.conf" + +ynh_delete_file_checksum --file="/etc/mosquitto/passwd" +ynh_add_config --template="passwd" --destination="/etc/mosquitto/passwd" mosquitto_passwd -U "/etc/mosquitto/passwd" ynh_store_file_checksum --file="/etc/mosquitto/passwd" -ynh_add_config --template="../conf/mosquitto.conf" --destination="/etc/mosquitto/conf.d/default.conf" - +# Hard coded username because deb package creates the user +chown -R "mosquitto" "/etc/mosquitto" #================================================= -# GENERIC FINALIZATION +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description="Allows MQTT clients to send/receive data" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port" +yunohost service add "$app" --description="Allows MQTT clients to send/receive data" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="restart" +ynh_systemd_action --service_name="$app" --action="restart" #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..a339f15 --- /dev/null +++ b/tests.toml @@ -0,0 +1,13 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + + args.username = "mosquitto" + args.userpass = "mosquitto" + + [default.test_upgrade_from.eb74d6d63a8bc8561d124429c9fa3bdb8f6af7a0] + name = "2.0.12~ynh1" + args.username = "mosquitto" + args.userpass = "mosquitto"