From b8b3bbe0ffd5a19b09745183ea536835b18f33b2 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 20 Jun 2022 01:41:47 +0200 Subject: [PATCH] Apply last example_ynh --- .../ISSUE_TEMPLATE.md | 4 +- .github/PULL_REQUEST_TEMPLATE.md | 16 +++++ check_process | 3 + conf/mosquitto.conf | 2 +- doc/.gitkeep | 0 doc/DESCRIPTION.md | 1 + doc/DESCRIPTION_fr.md | 1 + doc/DISCLAIMER.md | 3 + doc/DISCLAIMER_fr.md | 3 + doc/screenshots/.gitkeep | 0 manifest.json | 13 +++- pull_request_template.md | 16 ----- scripts/_common.sh | 10 +-- scripts/backup | 12 +--- scripts/install | 44 ++++--------- scripts/remove | 31 +++------ scripts/restore | 56 +++++++---------- scripts/upgrade | 63 +++++++------------ 18 files changed, 110 insertions(+), 168 deletions(-) rename issue_template.md => .github/ISSUE_TEMPLATE.md (94%) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 doc/.gitkeep create mode 100644 doc/DESCRIPTION.md create mode 100644 doc/DESCRIPTION_fr.md create mode 100644 doc/DISCLAIMER.md create mode 100644 doc/DISCLAIMER_fr.md create mode 100644 doc/screenshots/.gitkeep delete mode 100644 pull_request_template.md diff --git a/issue_template.md b/.github/ISSUE_TEMPLATE.md similarity index 94% rename from issue_template.md rename to .github/ISSUE_TEMPLATE.md index 3e89c39..2729a6b 100644 --- a/issue_template.md +++ b/.github/ISSUE_TEMPLATE.md @@ -8,7 +8,7 @@ about: When creating a bug report, please use the following template to provide 1. *Read this whole template first.* 2. *Determine if you are on the right place:* - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!* - - *Otherwise, the issue may be due to mosquitto itself. Refer to its documentation or repository for help.* + - *Otherwise, the issue may be due to the app itself. Refer to its documentation or repository for help.* - *When in doubt, post here and we will figure it out together.* 3. *Delete the italic comments as you write over them below, and remove this guide.* --- @@ -31,7 +31,7 @@ about: When creating a bug report, please use the following template to provide - *If you performed a command from the CLI, the command itself is enough. For example:* ```sh - sudo yunohost app install mosquitto + sudo yunohost app install the_app ``` - *If you used the webadmin, please perform the equivalent command from the CLI first.* - *If the error occurs in your browser, explain what you did:* diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..ef70e18 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,16 @@ +## Problem + +- *Description of why you made this PR* + +## Solution + +- *And how do you fix that problem* + +## PR Status + +- [ ] Code finished and ready to be reviewed/tested +- [ ] The fix/enhancement were manually tested (if applicable) + +## Automatic tests + +Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ *after creating the PR*, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization) diff --git a/check_process b/check_process index 3048d3a..3d91424 100644 --- a/check_process +++ b/check_process @@ -7,7 +7,10 @@ pkg_linter=1 setup_nourl=1 upgrade=1 + # 1.5.7~ynh1 upgrade=1 from_commit=3423395180264623342ee41946d10f30cd38e471 + # 2.0.8~ynh1 + upgrade=1 from_commit=74185f9e1fb58a91271cfc24630029da662b6111 backup_restore=1 port_already_use=1 (1883) ;;; Options diff --git a/conf/mosquitto.conf b/conf/mosquitto.conf index 75ac11a..fe46dfa 100644 --- a/conf/mosquitto.conf +++ b/conf/mosquitto.conf @@ -1,4 +1,4 @@ listener __PORT__ allow_anonymous false -password_file __PASSWORD_FILE__ +password_file /etc/mosquitto/passwd diff --git a/doc/.gitkeep b/doc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..b034ad2 --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1 @@ +[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). diff --git a/doc/DESCRIPTION_fr.md b/doc/DESCRIPTION_fr.md new file mode 100644 index 0000000..33d82ac --- /dev/null +++ b/doc/DESCRIPTION_fr.md @@ -0,0 +1 @@ +[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). diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md new file mode 100644 index 0000000..2a8b9dd --- /dev/null +++ b/doc/DISCLAIMER.md @@ -0,0 +1,3 @@ +## TODO + +- [ ] Add MQTTS (MQTT with TLS) diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md new file mode 100644 index 0000000..2a4c3bf --- /dev/null +++ b/doc/DISCLAIMER_fr.md @@ -0,0 +1,3 @@ +## A faire + +- [ ] Ajouter MQTTS (MQTT avec TLS) diff --git a/doc/screenshots/.gitkeep b/doc/screenshots/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/manifest.json b/manifest.json index d7886b0..06204b0 100644 --- a/manifest.json +++ b/manifest.json @@ -8,18 +8,26 @@ }, "version": "2.0.8~ynh1", "url": "https://mosquitto.org/", + "upstream": { + "license": "MIT", + "website": "https://mosquitto.org", + "demo": "https://demo.example.com", + "admindoc": "https://mosquitto.org/documentation/", + "userdoc": "https://yunohost.org/apps", + "code": "https://some.forge.com/example/example" + }, "license": "MIT", "maintainer": { "name": "Grena", "email": "grena+mosquitto@grenabox.fr" }, "requirements": { - "yunohost": ">= 4.1.0" + "yunohost": ">= 4.3.0" }, "multi_instance": false, "services": [], "arguments": { - "install" : [ + "install": [ { "name": "username", "type": "string", @@ -42,4 +50,3 @@ ] } } - diff --git a/pull_request_template.md b/pull_request_template.md deleted file mode 100644 index 6c28fc5..0000000 --- a/pull_request_template.md +++ /dev/null @@ -1,16 +0,0 @@ -## Problem -- *Description of why you made this PR* - -## Solution -- *And how do you fix that problem* - -## PR Status -- [ ] Code finished. -- [ ] Tested with Package_check. -- [ ] Fix or enhancement tested. -- [ ] Upgrade from last version tested. -- [ ] Can be reviewed and tested. - -## Package_check results ---- -* An automatic package_check will be launch at https://ci-apps-dev.yunohost.org/, when you add a specific comment to your Pull Request: "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!"* diff --git a/scripts/_common.sh b/scripts/_common.sh index 25159c0..617436e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,16 +4,8 @@ # COMMON VARIABLES #================================================= -# files used by the app -password_file="/etc/mosquitto/passwd" -config_file="/etc/mosquitto/conf.d/default.conf" - -# extra repository used by the app -extra_repo="deb https://repo.mosquitto.org/debian buster main" -extra_repo_key="http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key" - # dependencies used by the app -pkg_dependencies="mosquitto" +extra_pkg_dependencies="mosquitto" #================================================= # PERSONAL HELPERS diff --git a/scripts/backup b/scripts/backup index cc00390..eee2ccf 100755 --- a/scripts/backup +++ b/scripts/backup @@ -33,13 +33,6 @@ password=$(ynh_app_setting_get --app=$app --key=password) #================================================= ynh_print_info --message="Declaring files to be backed up..." -#================================================= -# BACKUP FAIL2BAN CONFIGURATION -#================================================= - -#ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" -#ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" - #================================================= # SPECIFIC BACKUP #================================================= @@ -53,14 +46,13 @@ ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= # Backup the passwd file -ynh_backup --src_path="$password_file" +ynh_backup --src_path="/etc/mosquitto/passwd" # Backup the config file -ynh_backup --src_path="$config_file" +ynh_backup --src_path="/etc/mosquitto/conf.d/default.conf" #================================================= # END OF SCRIPT #================================================= ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." - diff --git a/scripts/install b/scripts/install index eb48700..9af97f0 100644 --- a/scripts/install +++ b/scripts/install @@ -20,11 +20,11 @@ ynh_abort_if_errors # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -app=$YNH_APP_INSTANCE_NAME - username=$YNH_APP_ARG_USERNAME password=$YNH_APP_ARG_PASSWORD +app=$YNH_APP_INSTANCE_NAME + #================================================= # STORE SETTINGS FROM MANIFEST #================================================= @@ -53,38 +53,19 @@ ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port #================================================= ynh_script_progression --message="Installing dependencies..." --weight=20 -ynh_install_extra_app_dependencies --repo="$extra_repo" --package="$pkg_dependencies" --key="$extra_repo_key" --name="$app" +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" --name="$app" #================================================= # SPECIFIC SETUP #================================================= -# CONFIGURE MOSQUITTO +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Configuring Mosquitto Password..." --weight=1 +ynh_script_progression --message="Adding a configuration file..." --weight=1 -cp ../conf/passwd "$password_file" +ynh_add_config --template="../conf/passwd" --destination="/etc/mosquitto/passwd" +mosquitto_passwd -U "/etc/mosquitto/passwd" -ynh_replace_string --match_string="__USERNAME__" --replace_string="$username" --target_file="$password_file" -ynh_replace_string --match_string="__PASSWORD__" --replace_string="$password" --target_file="$password_file" -mosquitto_passwd -U "$password_file" - -ynh_store_file_checksum --file="$password_file" - -ynh_script_progression --message="Configuring Mosquitto..." --weight=1 - -cp ../conf/mosquitto.conf "$config_file" - -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_file" -ynh_replace_string --match_string="__PASSWORD_FILE__" --replace_string="$password_file" --target_file="$config_file" - -ynh_store_file_checksum --file="$config_file" - -#================================================= -# RESTART SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Restarting systemd service..." --weight=1 - -ynh_systemd_action --service_name="$app" --action=restart +ynh_add_config --template="../conf/mosquitto.conf" --destination="/etc/mosquitto/conf.d/default.conf" #================================================= # GENERIC FINALIZATION @@ -104,16 +85,15 @@ 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" #================================================= -# SETUP FAIL2BAN +# START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Configuring Fail2Ban..." --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=1 -# Create a dedicated Fail2Ban config -#ynh_add_fail2ban_config --logpath="/var/log/$app/$app.log" --ports="$port" --failregex="Regex to match into the log for a failed login" +# Start a systemd service +ynh_systemd_action --service_name=$app --action="restart" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last - diff --git a/scripts/remove b/scripts/remove index b659066..e0de391 100755 --- a/scripts/remove +++ b/scripts/remove @@ -17,8 +17,6 @@ ynh_script_progression --message="Loading installation settings..." --weight=2 app=$YNH_APP_INSTANCE_NAME port=$(ynh_app_setting_get --app=$app --key=port) -username=$(ynh_app_setting_get --app=$app --key=username) -password=$(ynh_app_setting_get --app=$app --key=password) #================================================= # STANDARD REMOVE @@ -41,14 +39,6 @@ ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=6 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= @@ -57,6 +47,14 @@ ynh_script_progression --message="Removing logrotate configuration..." --weight= # 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 #================================================= @@ -67,14 +65,6 @@ then ynh_exec_warn_less yunohost firewall disallow TCP $port fi -#================================================= -# REMOVE FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression --message="Removing Fail2ban configuration..." --weight=1 - -# Remove the dedicated Fail2Ban config -#ynh_remove_fail2ban_config - #================================================= # SPECIFIC REMOVE #================================================= @@ -86,14 +76,13 @@ ynh_script_progression --message="Removing various files..." --weight=1 ynh_secure_remove --file="/var/log/$app/$app.log" # Remove the passwd file -ynh_secure_remove --file="$password_file" +ynh_secure_remove --file="/etc/mosquitto/passwd" # Remove the config file -ynh_secure_remove --file="$config_file" +ynh_secure_remove --file="/etc/mosquitto/conf.d/default.conf" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Removal of $app completed" --last - diff --git a/scripts/restore b/scripts/restore index 1596751..f261028 100755 --- a/scripts/restore +++ b/scripts/restore @@ -28,17 +28,6 @@ port=$(ynh_app_setting_get --app=$app --key=port) username=$(ynh_app_setting_get --app=$app --key=username) password=$(ynh_app_setting_get --app=$app --key=password) -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RESTORE FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1 - -#ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" -#ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" -#ynh_systemd_action --action=restart --service_name=fail2ban - #================================================= # SPECIFIC RESTORATION #================================================= @@ -46,7 +35,25 @@ ynh_script_progression --message="Restoring the Fail2Ban configuration..." --wei #================================================= ynh_script_progression --message="Reinstalling dependencies..." --weight=20 -ynh_install_extra_app_dependencies --repo="$extra_repo" --package="$pkg_dependencies" --key="$extra_repo_key" --name="$app" +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" --name="$app" + +#================================================= +# RESTORE VARIOUS FILES +#================================================= +ynh_script_progression --message="Restoring various files..." --weight=1 + +# Restore the passwd file +ynh_restore_file --origin_path="/etc/mosquitto/passwd" + +# Restore the config file +ynh_restore_file --origin_path="/etc/mosquitto/conf.d/default.conf" + +#================================================= +# 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 @@ -56,33 +63,16 @@ 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" #================================================= -# RESTORE VARIOUS FILES +# START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Restoring the Mosquitto configuration..." --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=1 -# Restore the passwd file -ynh_restore_file --origin_path="$password_file" - -# Restore the config file -ynh_restore_file --origin_path="$config_file" +ynh_systemd_action --service_name=$app --action="restart" #================================================= -# RESTART SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Restarting systemd service..." --weight=1 - -ynh_systemd_action --service_name="$app" --action=restart - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the log rotation..." --weight=1 - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - +# GENERIC FINALIZATION #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Restoration completed for $app" --last - diff --git a/scripts/upgrade b/scripts/upgrade index 7392630..fb44682 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -23,14 +23,10 @@ password=$(ynh_app_setting_get --app=$app --key=password) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# ENSURE DOWNWARD COMPATIBILITY -#================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -47,51 +43,37 @@ ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." + +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="$extra_repo" --package="$pkg_dependencies" --key="$extra_repo_key" --name="$app" +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" --name="$app" #================================================= # SPECIFIC UPGRADE #================================================= -# MODIFY A CONFIG FILE +# UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Configuring Mosquitto Password..." --weight=1 +ynh_script_progression --message="Updating a configuration file..." --weight=1 -# Verify the checksum and backup the file if it's different. -ynh_backup_if_checksum_is_different --file="$password_file" +ynh_add_config --template="../conf/passwd" --destination="/etc/mosquitto/passwd" +mosquitto_passwd -U "/etc/mosquitto/passwd" -cp ../conf/passwd "$password_file" +ynh_add_config --template="../conf/mosquitto.conf" --destination="/etc/mosquitto/conf.d/default.conf" -ynh_replace_string --match_string="__USERNAME__" --replace_string="$username" --target_file="$password_file" -ynh_replace_string --match_string="__PASSWORD__" --replace_string="$password" --target_file="$password_file" -mosquitto_passwd -U "$password_file" - -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$password_file" - -ynh_script_progression --message="Configuring Mosquitto..." --weight=1 - -# Verify the checksum and backup the file if it's different. -ynh_backup_if_checksum_is_different --file="$config_file" - -cp ../conf/mosquitto.conf "$config_file" - -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_file" -ynh_replace_string --match_string="__PASSWORD_FILE__" --replace_string="$password_file" --target_file="$config_file" - -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$config_file" - -#================================================= -# RESTART SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Restarting systemd service..." --weight=1 - -ynh_systemd_action --service_name="$app" --action=restart #================================================= # GENERIC FINALIZATION @@ -111,12 +93,11 @@ 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" #================================================= -# UPGRADE FAIL2BAN +# START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=1 -# Create a dedicated Fail2Ban config -#ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" +ynh_systemd_action --service_name=$app --action="restart" #================================================= # END OF SCRIPT