From 4de2b227383d2cd63179404df4901e05005322d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 9 Jan 2024 17:31:18 +0100 Subject: [PATCH 01/11] manifestv2 --- CHANGELOG.md | 14 +- check_process | 69 ------- doc/ADMIN.md | 14 ++ doc/ADMIN_fr.md | 14 ++ doc/DISCLAIMER.md | 10 -- doc/DISCLAIMER_fr.md | 10 -- doc/POST_INSTALL.md | 10 ++ manifest.json | 96 ---------- manifest.toml | 88 +++++++++ scripts/_common.sh | 419 ++++++++++--------------------------------- scripts/backup | 6 +- scripts/install | 156 +--------------- scripts/remove | 16 -- scripts/restore | 8 +- scripts/upgrade | 34 ++-- tests.toml | 29 +++ 16 files changed, 282 insertions(+), 711 deletions(-) delete mode 100644 check_process create mode 100644 doc/ADMIN.md create mode 100644 doc/ADMIN_fr.md delete mode 100644 doc/DISCLAIMER.md delete mode 100644 doc/DISCLAIMER_fr.md create mode 100644 doc/POST_INSTALL.md delete mode 100644 manifest.json create mode 100644 manifest.toml create mode 100644 tests.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index 95e1e16..36a2402 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,51 +2,55 @@ Changelog ========= ## Unreleased + - Nothing for now... ## [1.0~ynh5](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13) - 2019-04-24 #### Added + * [Add a changelog](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/054a7f4e0c98e2ade70779a9f470ef1d0d50413e) - [New badges](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/477f7f3f178336ec03882fe3ec4e718c745ecda2) #### Fixed + - [Fix Buster](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/fa7afd13e1657948a07a3f05227e5b6d26bdd9de) #### Changed + - [Update to last standard](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/f7ad5779f7074bfaafd1bf4653bfeaf2ddc0880d) - [Update helpers](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/02e6b338b17ddd468875865edc8bd9c5ad741381) - [Update config-panel and actions](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/f37594eb5df701e70ce884354e4f5ad3371b3d8b) - [Global upgrade](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/74210eea818d76a35f1f9872029b267300ff5c46) - ## [1.0~ynh4](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/9) - 2019-02-03 #### Added + - [Add progression bar](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/9/commits/51a015f726f852bbb0dc8ceb4c463657803b1b8b) - [Changelog & html email](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/9/commits/f5c468947230dd2bcf8a82a0552548c6f6f61877) - ## [1.0~ynh3](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/8) - 2019-01-21 #### Changed + - [Update to last standart](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/8/commits/2093bcf70e8527066eb8e0750c17cc361dd9a408) - [Advertise config-panel and actions](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/8/commits/53132454227b9b972357ee694f79748f6a6bab93) - ## [1.0~ynh2](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/6) - 2018-09-30 #### Added -- [Panel-config + actions fully tested](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/6/commits/eb48bf36a6a792d80b553624f5a221495c0d29a5) +- [Panel-config + actions fully tested](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/6/commits/eb48bf36a6a792d80b553624f5a221495c0d29a5) ## [1.0~ynh2](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/5) - 2018-07-16 #### Changed -- [Upgrade helpers](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/5/commits/d7d56c2d88aeb2817b509dbd9aa23434a1480148) +- [Upgrade helpers](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/5/commits/d7d56c2d88aeb2817b509dbd9aa23434a1480148) ## [1.0~ynh1](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/1) - 2018-03-14 #### Changed + - [Update helpers](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/1/commits/5a359c6833a5415932ab427a80dbbdc6ca3c8e23) diff --git a/check_process b/check_process deleted file mode 100644 index edac46d..0000000 --- a/check_process +++ /dev/null @@ -1,69 +0,0 @@ -;; Test complet 1/3 - ; Manifest - upgrade_level="Security only" - ynh_update=1 - previous_apticron=1 - after_apticron=1 - unattended_mail="If an upgrade has been done" - unattended_verbosity="1" - ; Actions - ; Config_panel - main.unattended_configuration.upgrade_level=Security only|Security and updates - main.unattended_configuration.ynh_update=0|1 - main.unattended_configuration.unattended_mail=If an upgrade has been done|Only if there was an error|Never - main.apticron_configuration.previous_apticron=0|1 - main.apticron_configuration.previous_apticron_hour=21 - main.apticron_configuration.after_apticron=0|1 - main.apticron_configuration.after_apticron_hour=5 - main.periodic_configuration.unattended_verbosity=1|2|3 - main.overwrite_files.overwrite_periodic=0|1 - main.global_config.email_type=0|1 - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=0 - setup_nourl=1 - setup_private=0 - setup_public=0 - upgrade=1 - upgrade=1 from_commit=4e342d41ea448c4a9de2bbbc6b6cffe92320ef71 - backup_restore=1 - multi_instance=0 - port_already_use=0 - change_url=0 - actions=0 - config_panel=0 -;; Test complet 2/3 - ; Manifest - upgrade_level="Security and updates" - ynh_update=0 - previous_apticron=0 - after_apticron=1 - unattended_mail="Only if there was an error" - unattended_verbosity="2" - ; Checks - setup_sub_dir=0 - setup_root=0 - setup_nourl=1 - upgrade=1 - backup_restore=1 -;; Test complet 3/3 - ; Manifest - upgrade_level="Security only" - ynh_update=0 - previous_apticron=1 - after_apticron=0 - unattended_mail="Never" - unattended_verbosity="3" - ; Checks - setup_sub_dir=0 - setup_root=0 - setup_nourl=1 - upgrade=1 - backup_restore=1 -;;; Options -Email= -Notification=change -;;; Upgrade options - ; commit=4e342d41ea448c4a9de2bbbc6b6cffe92320ef71 - name=Merge pull request #16 from YunoHost-Apps/testing diff --git a/doc/ADMIN.md b/doc/ADMIN.md new file mode 100644 index 0000000..012891b --- /dev/null +++ b/doc/ADMIN.md @@ -0,0 +1,14 @@ +## Configuration + +Have a look to the following config files for Unattended-upgrades: + +* /etc/apt/apt.conf.d/50unattended-upgrades +* /etc/apt/apt.conf.d/02periodic + +And this one for Apticron: + +* /etc/apticron/apticron.conf + +With its cron file: + +* /etc/cron.d/apticron diff --git a/doc/ADMIN_fr.md b/doc/ADMIN_fr.md new file mode 100644 index 0000000..5f6a598 --- /dev/null +++ b/doc/ADMIN_fr.md @@ -0,0 +1,14 @@ +## Configuration + +Regardez les fichiers de configuration suivant pour Unattended-upgrades: + +* /etc/apt/apt.conf.d/50unattended-upgrades +* /etc/apt/apt.conf.d/02periodic + +Et celui-ci pour Apticron + +* /etc/apticron/apticron.conf + +Avec son cron: + +* /etc/cron.d/apticron diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index 55939ac..0000000 --- a/doc/DISCLAIMER.md +++ /dev/null @@ -1,10 +0,0 @@ -## Configuration - -Have a look to the following config files for Unattended-upgrades - * /etc/apt/apt.conf.d/50unattended-upgrades - * /etc/apt/apt.conf.d/02periodic - -And this one for Apticron - * /etc/apticron/apticron.conf -With its cron file - * /etc/cron.d/apticron diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md deleted file mode 100644 index 6731a1a..0000000 --- a/doc/DISCLAIMER_fr.md +++ /dev/null @@ -1,10 +0,0 @@ -## Configuration - -Regardez les fichiers de configuration suivant pour Unattended-upgrades - * /etc/apt/apt.conf.d/50unattended-upgrades - * /etc/apt/apt.conf.d/02periodic - -Et celui-ci pour Apticron - * /etc/apticron/apticron.conf -Avec son cron - * /etc/cron.d/apticron diff --git a/doc/POST_INSTALL.md b/doc/POST_INSTALL.md new file mode 100644 index 0000000..78eb156 --- /dev/null +++ b/doc/POST_INSTALL.md @@ -0,0 +1,10 @@ +To modify any option of unattended-upgrades, please have a look to `/etc/apt/apt.conf.d/50unattended-upgrades` and `/etc/apt/apt.conf.d/02periodic`. +Unattended-upgrades will be executed every day at midnight. + +To modify the configuration of apticron, please have a look to `/etc/apticron/apticron.conf`. +Apticron will be executed, depending of the requested configuration at 8 p.m. and 2 a.m. If you want to change this schedule, please have a look to the cron file /etc/cron.d/apticron. + +You can configure this app easily by using the experimental [config-panel feature](__ADMIN_PANEL__/config-panel). +You can also find some specific actions for this app by using the experimental [action feature](__ADMIN_PANEL__/actions). + +If you're facing an issue or want to improve this app, please open a new issue in this [project](https://github.com/YunoHost-Apps/unattended_upgrades_ynh). diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1e1baf6..0000000 --- a/manifest.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "name": "Unattended-upgrades", - "id": "unattended_upgrades", - "packaging_format": 1, - "description": { - "en": "Daily automatic upgrades", - "fr": "Mise à jour automatique quotidienne" - }, - "version": "1.0~ynh6", - "url": "https://wiki.debian.org/UnattendedUpgrades", - "upstream": { - "license": "GPL-2.0-or-later", - "website": "https://wiki.debian.org/UnattendedUpgrades", - "admindoc": "https://wiki.debian.org/UnattendedUpgrades", - "userdoc": "https://manpages.debian.org/stretch/apticron/apticron.1.en.html" - }, - "license": "GPL-2.0-or-later", - "maintainer": { - "name": "", - "email": "" - }, - "previous_maintainers": [{ - "name": "Maniack Crudelis", - "email": "maniackc_dev@crudelis.fr" - }], - "requirements": { - "yunohost": ">= 4.3.0" - }, - "multi_instance": false, - "services": [], - "arguments": { - "install" : [ - { - "name": "upgrade_level", - "type": "string", - "ask": { - "en": "Choose the sources of packages to automatically upgrade", - "fr": "Choisissez les sources des paquets à mettre à jour automatiquement" - }, - "choices": ["Security only", "Security and updates"], - "default": "Security only" - }, - { - "name": "ynh_update", - "type": "boolean", - "ask": { - "en": "Would you like to update YunoHost packages automatically?", - "fr": "Souhaitez-vous mettre à jour les paquets YunoHost automatiquement ?" - }, - "default": true - }, - { - "name": "previous_apticron", - "type": "boolean", - "ask": { - "en": "Would you like to receive an email to inform which upgrades need to be done?", - "fr": "Souhaitez-vous recevoir un email pour vous informer des mises à jour nécessaires ?" - }, - "default": true - }, - { - "name": "after_apticron", - "type": "boolean", - "ask": { - "en": "Would you like to receive an email to verify if there any upgrades left after each auto upgrade?", - "fr": "Souhaitez-vous recevoir un email pour vérifier s'il reste des mises à jour après chaque mise à niveau automatique ?" - }, - "default": true - }, - { - "name": "unattended_mail", - "type": "string", - "ask": { - "en": "Would you like to receive an email from Unattended-Upgrades?", - "fr": "Souhaitez-vous recevoir un email de Unattended-Upgrades ?" - }, - "choices": ["If an upgrade has been done", "Only if there was an error", "Never"], - "default": "If an upgrade has been done" - }, - { - "name": "unattended_verbosity", - "type": "string", - "ask": { - "en": "Choose the level of verbosity of Unattended-Upgrades mail", - "fr": "Choisir le niveau de verbosité du mail de Unattended-Upgrades" - }, - "help": { - "en": "1: Progress report only.
2: Progress report and command outputs.
3: Progress report and command outputs and trace.
", - "fr": "1: Rapport d'avancement seulement.
2: Rapport d'avancement et sortie de commandes.
3: Rapport d'avancement, sortie de commandes et trace." - }, - "choices": ["1", "2", "3"], - "default": "1" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..6f0387f --- /dev/null +++ b/manifest.toml @@ -0,0 +1,88 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "unattended_upgrades" +name = "Unattended-upgrades" +description.en = "Daily automatic upgrades" +description.fr = "Mise à jour automatique quotidienne" + +version = "1.0~ynh6" + +maintainers = [] + +[upstream] +license = "GPL-2.0-or-later" +website = "https://wiki.debian.org/UnattendedUpgrades" +admindoc = "https://wiki.debian.org/UnattendedUpgrades" +userdoc = "https://manpages.debian.org/stretch/apticron/apticron.1.en.html" + +[integration] +yunohost = ">= 4.3.0" +architectures = "all" +multi_instance = false +ldap = "not_relevant" +sso = "not_relevant" +disk = "50M" +ram.build = "5M" +ram.runtime = "50M" + +[install] + [install.upgrade_level] + ask.en = "Choose the sources of packages to automatically upgrade" + ask.fr = "Choisissez les sources des paquets à mettre à jour automatiquement" + type = "string" + choices.security_only = "Security only" + choices.security_and_updates = "Security and updates" + default = "security_only" + + [install.ynh_update] + ask.en = "Would you like to update YunoHost packages automatically?" + ask.fr = "Souhaitez-vous mettre à jour les paquets YunoHost automatiquement ?" + type = "boolean" + default = true + + [install.previous_apticron] + ask.en = "Would you like to receive an email to inform which upgrades need to be done?" + ask.fr = "Souhaitez-vous recevoir un email pour vous informer des mises à jour nécessaires ?" + type = "boolean" + default = true + + [install.after_apticron] + ask.en = "Would you like to receive an email to verify if there any upgrades left after each auto upgrade?" + ask.fr = "Souhaitez-vous recevoir un email pour vérifier s'il reste des mises à jour après chaque mise à niveau automatique ?" + type = "boolean" + default = true + + [install.unattended_mail] + ask.en = "Would you like to receive an email from Unattended-Upgrades?" + ask.fr = "Souhaitez-vous recevoir un email de Unattended-Upgrades ?" + type = "select" + choices.on_upgrade = "If an upgrade has been done" + choices.on_error = "Only if there was an error" + choices.never = "Never" + default = "on_upgrade" + + [install.unattended_verbosity] + ask.en = "Choose the level of verbosity of Unattended-Upgrades mail" + ask.fr = "Choisir le niveau de verbosité du mail de Unattended-Upgrades" + type = "select" + choices.v1 = "Progress report only" + choices.v2 = "Progress report and command outputs" + choices.v3 = "Progress report and command outputs and trace" + # help.fr = "1: Rapport d'avancement seulement.
2: Rapport d'avancement et sortie de commandes.
3: Rapport d'avancement, sortie de commandes et trace." + default = "v1" + +[resources] + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + + [resources.apt] + packages = [ + "apticron", + "unattended-upgrades", + "apt-listchanges", + ] diff --git a/scripts/_common.sh b/scripts/_common.sh index 2e332e6..f8b6193 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,48 +4,110 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -pkg_dependencies="apticron unattended-upgrades apt-listchanges" - #================================================= # PERSONAL HELPERS #================================================= +apticron_config="/etc/apticron/apticron.conf" +apticron_cron="/etc/cron.d/apticron" + +_apticron_set_config() { + # If the config file doesn't exist, copy the model + if [ ! -e "$apticron_config" ]; then + cp "/usr/lib/apticron/apticron.conf" "$apticron_config" + fi + + # Create a backup of the config file for the reset action + cp "$apticron_config" "/etc/yunohost/apps/$app/conf/apticron.conf.backup" + + ynh_replace_string --match_string="# CUSTOM_SUBJECT=.*" \ + --replace_string="&\nCUSTOM_SUBJECT=\'[apticron] \$SYSTEM: \$NUM_PACKAGES package update(s)\'" --target_file="$apticron_config" + ynh_replace_string --match_string="# CUSTOM_NO_UPDATES_SUBJECT=.*" \ + --replace_string="&\nCUSTOM_NO_UPDATES_SUBJECT=\'[apticron] \$SYSTEM: Up to date \\\\o/\'" --target_file="$apticron_config" + + # Create a backup of the cron file for the reset action + cp "$apticron_cron" "/etc/yunohost/apps/$app/conf/apticron.crond.backup" + + # Copy and comment the current cron + ynh_replace_string --match_string="^.* root if.*" --replace_string="#&\n&" --target_file="$apticron_cron" + # Modify the time to set at 20:00 every day + ynh_replace_string --match_string="^[[:digit:]].*\( root if.*\)" --replace_string="0 20 * * *\1" --target_file="$apticron_cron" + # Copy the new cron and set the time to 2:00 every night + ynh_replace_string --match_string="^0 20\(.*\)" --replace_string="&\n0 2\1" --target_file="$apticron_cron" + + if [ "$previous_apticron" -eq 0 ]; then + # Comment the first cron + ynh_replace_string --match_string="^0 20 .*" --replace_string="#&" --target_file="$apticron_cron" + fi + + if [ "$after_apticron" -eq 0 ]; then + # Comment the second cron + ynh_replace_string --match_string="^0 2 .*" --replace_string="#&" --target_file="$apticron_cron" + fi +} + +_apticron_restore_config() { + mv "/etc/yunohost/apps/$app/conf/apticron.conf.backup" "$apticron_config" + mv "/etc/yunohost/apps/$app/conf/apticron.crond.backup" "$apticron_cron" +} + + +unattended_upgrades_config="/etc/apt/apt.conf.d/50unattended-upgrades" + +_unattended_upgrades_set_config() { + # Make a backup of 50unattended-upgrades + cp "$unattended_upgrades_config" "/etc/yunohost/apps/$app/conf/50unattended-upgrades.backup" + + # Configure upgrade sources + # Allow other updates + if [ "$upgrade_level" = "security_and_updates" ]; then + ynh_replace_string --match_string="//\(.*\"o=Debian,a=stable\)" --replace_string="\1" --target_file="$unattended_upgrades_config" + ynh_replace_string --match_string="//\(.*\"o=Debian,a=stable-updates\)" --replace_string="\1" --target_file="$unattended_upgrades_config" + fi + + # Add YunoHost upgrade source + if [ $ynh_update -eq 1 ]; then + ynh_replace_string --match_string="origin=Debian,codename=\${distro_codename},label=Debian-Security\";" \ + --replace_string="&\n\n //YunoHost upgrade\n \"o=YunoHost,a=stable\";" --target_file="$unattended_upgrades_config" + fi + + # Allow MinimalSteps upgrading to reduce risk in case of reboot + ynh_replace_string --match_string="//\(Unattended-Upgrade::MinimalSteps\).*" --replace_string="\1 \"true\";" --target_file="$unattended_upgrades_config" + + # Configure Unattended Upgrades mailing + if [ "$unattended_mail" = "on_upgrade" ]; then + # Allow mail to root + ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$unattended_upgrades_config" + + # Send mail even if there's no errors + ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"false\";" --target_file="$unattended_upgrades_config" + + elif [ "$unattended_mail" = "on_error" ]; then + # Allow mail to root + ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$unattended_upgrades_config" + + # Send mail only if there's an error + ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"true\";" --target_file="$unattended_upgrades_config" + + else # "Never" + # Comment "Unattended-Upgrade::Mail" if it isn't already commented + ynh_replace_string --match_string="^\(Unattended-Upgrade::Mail \)" --replace_string="//\1" --target_file="$unattended_upgrades_config" + fi + +} + +_unattended_upgrades_restore_config() { + mv "/etc/yunohost/apps/$app/conf/50unattended-upgrades.backup" "$unattended_upgrades_config" +} + #================================================= # BACKUP #================================================= -HUMAN_SIZE () { # Transforme une taille en Ko en une taille lisible pour un humain - human=$(numfmt --to=iec --from-unit=1K $1) - echo $human -} - -CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant - file_to_analyse=$1 - backup_size=$(du --summarize "$file_to_analyse" | cut -f1) - free_space=$(df --output=avail "/home/yunohost.backup" | sed 1d) - - if [ $free_space -le $backup_size ] - then - ynh_print_err "Espace insuffisant pour sauvegarder $file_to_analyse." - ynh_print_err "Espace disponible: $(HUMAN_SIZE $free_space)" - ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)" - fi -} - #================================================= # PACKAGE CHECK BYPASSING... #================================================= -IS_PACKAGE_CHECK () { - if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ] - then - return 0 - else - return 1 - fi -} - #================================================= # FUTUR OFFICIAL HELPERS #================================================= @@ -54,228 +116,6 @@ IS_PACKAGE_CHECK () { # EXPERIMENTAL HELPERS #================================================= -# Send an email to inform the administrator -# -# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type] -# | arg: -m --app_message= - The file with the content to send to the administrator. -# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root -# example: "root admin@domain" -# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you -# example: "root admin@domain user1 user2" -# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade' -ynh_send_readme_to_admin() { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= ) - local app_message - local recipients - local type - # Manage arguments with getopts - - ynh_handle_getopts_args "$@" - app_message="${app_message:-}" - recipients="${recipients:-root}" - type="${type:-install}" - - # Get the value of admin_mail_html - admin_mail_html=$(ynh_app_setting_get $app admin_mail_html) - admin_mail_html="${admin_mail_html:-0}" - - # Retrieve the email of users - find_mails () { - local list_mails="$1" - local mail - local recipients=" " - # Read each mail in argument - for mail in $list_mails - do - # Keep root or a real email address as it is - if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@" - then - recipients="$recipients $mail" - else - # But replace an user name without a domain after by its email - if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null) - then - recipients="$recipients $mail" - fi - fi - done - echo "$recipients" - } - recipients=$(find_mails "$recipients") - - # Subject base - local mail_subject="☁️🆈🅽🅷☁️: \`$app\`" - - # Adapt the subject according to the type of mail required. - if [ "$type" = "backup" ]; then - mail_subject="$mail_subject has just been backup." - elif [ "$type" = "change_url" ]; then - mail_subject="$mail_subject has just been moved to a new URL!" - elif [ "$type" = "remove" ]; then - mail_subject="$mail_subject has just been removed!" - elif [ "$type" = "restore" ]; then - mail_subject="$mail_subject has just been restored!" - elif [ "$type" = "upgrade" ]; then - mail_subject="$mail_subject has just been upgraded!" - else # install - mail_subject="$mail_subject has just been installed!" - fi - - local mail_message="This is an automated message from your beloved YunoHost server. - -Specific information for the application $app. - -$(if [ -n "$app_message" ] -then - cat "$app_message" -else - echo "...No specific information..." -fi) - ---- -Automatic diagnosis data from YunoHost - -__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__" - - # Store the message into a file for further modifications. - echo "$mail_message" > mail_to_send - - # If a html email is required. Apply html tags to the message. - if [ "$admin_mail_html" -eq 1 ] - then - # Insert 'br' tags at each ending of lines. - ynh_replace_string "$" "
" mail_to_send - - # Insert starting HTML tags - sed --in-place '1s@^@\n\n\n\n@' mail_to_send - - # Keep tabulations - ynh_replace_string " " "\ \ " mail_to_send - ynh_replace_string "\t" "\ \ " mail_to_send - - # Insert url links tags - ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "\1" mail_to_send - - # Insert pre tags - ynh_replace_string "__PRE_TAG1__" "
" mail_to_send
-		ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send
-
-		# Insert finishing HTML tags
-		echo -e "\n\n" >> mail_to_send
-
-	# Otherwise, remove tags to keep a plain text.
-	else
-		# Remove URL tags
-		ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send
-		ynh_replace_string "__URL_TAG2__" ": " mail_to_send
-
-		# Remove PRE tags
-		ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send
-	fi
-
-	# Define binary to use for mail command
-	if [ -e /usr/bin/bsd-mailx ]
-	then
-		local mail_bin=/usr/bin/bsd-mailx
-	else
-		local mail_bin=/usr/bin/mail.mailutils
-	fi
-
-	if [ "$admin_mail_html" -eq 1 ]
-	then
-		content_type="text/html"
-	else
-		content_type="text/plain"
-	fi
-
-	# Send the email to the recipients
-	cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients"
-}
-
-#=================================================
-
-ynh_maintenance_mode_ON () {
-	# Load value of $path_url and $domain from the config if their not set
-	if [ -z $path_url ]; then
-		path_url=$(ynh_app_setting_get $app path)
-	fi
-	if [ -z $domain ]; then
-		domain=$(ynh_app_setting_get $app domain)
-	fi
-
-	mkdir -p /var/www/html/
-	
-	# Create an html to serve as maintenance notice
-	echo "
-
-
-
-Your app $app is currently under maintenance!
-
-
-
-

Your app $app is currently under maintenance!

-

This app has been put under maintenance by your administrator at $(date)

-

Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.

- - -" > "/var/www/html/maintenance.$app.html" - - # Create a new nginx config file to redirect all access to the app to the maintenance notice instead. - echo "# All request to the app will be redirected to ${path_url}_maintenance and fall on the maintenance notice -rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect; -# Use another location, to not be in conflict with the original config file -location ${path_url}_maintenance/ { -alias /var/www/html/ ; - -try_files maintenance.$app.html =503; - -# Include SSOWAT user panel. -include conf.d/yunohost_panel.conf.inc; -}" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" - - # The current config file will redirect all requests to the root of the app. - # To keep the full path, we can use the following rewrite rule: - # rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect; - # The difference will be in the $1 at the end, which keep the following queries. - # But, if it works perfectly for a html request, there's an issue with any php files. - # This files are treated as simple files, and will be downloaded by the browser. - # Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was. - - systemctl reload nginx -} - -ynh_maintenance_mode_OFF () { - # Load value of $path_url and $domain from the config if their not set - if [ -z $path_url ]; then - path_url=$(ynh_app_setting_get $app path) - fi - if [ -z $domain ]; then - domain=$(ynh_app_setting_get $app domain) - fi - - # Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app. - echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" - systemctl reload nginx - - # Sleep 4 seconds to let the browser reload the pages and redirect the user to the app. - sleep 4 - - # Then remove the temporary files used for the maintenance. - rm "/var/www/html/maintenance.$app.html" - rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" - - systemctl reload nginx -} - -#================================================= - # Create a changelog for an app after an upgrade from the file CHANGELOG.md. # # usage: ynh_app_changelog [--format=markdown/html/plain] [--output=changelog_file] --changelog=changelog_source] @@ -311,7 +151,7 @@ ynh_app_changelog () { return 0 fi - local current_version=$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version") +#REMOVEME? local current_version=$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version") local update_version=$(ynh_read_manifest --manifest="../manifest.json" --manifest_key="version") # Get the line of the version to update to into the changelog @@ -411,76 +251,3 @@ ynh_app_changelog () { echo "No significative changes from the changelog..." > "${final_changelog}_lite" fi } - -#================================================= - -# Check the amount of available RAM -# -# usage: ynh_check_ram [--required=RAM required in Mb] [--no_swap|--only_swap] [--free_ram] -# | arg: -r, --required= - Amount of RAM required in Mb. The helper will return 0 is there's enough RAM, or 1 otherwise. -# If --required isn't set, the helper will print the amount of RAM, in Mb. -# | arg: -s, --no_swap - Ignore swap -# | arg: -o, --only_swap - Ignore real RAM, consider only swap. -# | arg: -f, --free_ram - Count only free RAM, not the total amount of RAM available. -ynh_check_ram () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [r]=required= [s]=no_swap [o]=only_swap [f]=free_ram ) - local required - local no_swap - local only_swap - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - required=${required:-} - no_swap=${no_swap:-0} - only_swap=${only_swap:-0} - - local total_ram=$(vmstat --stats --unit M | grep "total memory" | awk '{print $1}') - local total_swap=$(vmstat --stats --unit M | grep "total swap" | awk '{print $1}') - local total_ram_swap=$(( total_ram + total_swap )) - - local free_ram=$(vmstat --stats --unit M | grep "free memory" | awk '{print $1}') - local free_swap=$(vmstat --stats --unit M | grep "free swap" | awk '{print $1}') - local free_ram_swap=$(( free_ram + free_swap )) - - # Use the total amount of ram - local ram=$total_ram_swap - if [ $free_ram -eq 1 ] - then - # Use the total amount of free ram - ram=$free_ram_swap - if [ $no_swap -eq 1 ] - then - # Use only the amount of free ram - ram=$free_ram - elif [ $only_swap -eq 1 ] - then - # Use only the amount of free swap - ram=$free_swap - fi - else - if [ $no_swap -eq 1 ] - then - # Use only the amount of free ram - ram=$total_ram - elif [ $only_swap -eq 1 ] - then - # Use only the amount of free swap - ram=$total_swap - fi - fi - - if [ -n "$required" ] - then - # Return 1 if the amount of ram isn't enough. - if [ $ram -lt $required ] - then - return 1 - else - return 0 - fi - - # If no RAM is required, return the amount of available ram. - else - echo $ram - fi -} diff --git a/scripts/backup b/scripts/backup index c580d77..2d41076 100644 --- a/scripts/backup +++ b/scripts/backup @@ -14,14 +14,14 @@ source /usr/share/yunohost/helpers #================================================= # 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 #================================================= # DECLARE DATA AND CONF FILES TO BACKUP diff --git a/scripts/install b/scripts/install index 840e8a4..39751c9 100644 --- a/scripts/install +++ b/scripts/install @@ -10,119 +10,29 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE FAILURE OF THE SCRIPT +# STORE VARIABLES FOR POST_INSTALL.md #================================================= -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors +# Get main domain and buid the url of the admin panel of the app. +admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" +ynh_app_setting_set --app="$app" --key=admin_panel --value="$admin_panel" -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= +# ynh_app_setting_set --app=$app --key=overwrite_periodic --value=1 +# ynh_app_setting_set --app=$app --key=admin_mail_html --value=1 -upgrade_level="$YNH_APP_ARG_UPGRADE_LEVEL" -ynh_update=$YNH_APP_ARG_YNH_UPDATE -previous_apticron=$YNH_APP_ARG_PREVIOUS_APTICRON -after_apticron=$YNH_APP_ARG_AFTER_APTICRON -unattended_mail="$YNH_APP_ARG_UNATTENDED_MAIL" -unattended_verbosity=$YNH_APP_ARG_UNATTENDED_VERBOSITY - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." --weight=3 - -ynh_app_setting_set --app=$app --key=upgrade_level --value="$upgrade_level" -ynh_app_setting_set --app=$app --key=ynh_update --value=$ynh_update -ynh_app_setting_set --app=$app --key=previous_apticron --value=$previous_apticron -ynh_app_setting_set --app=$app --key=after_apticron --value=$after_apticron -ynh_app_setting_set --app=$app --key=unattended_mail --value="$unattended_mail" -ynh_app_setting_set --app=$app --key=unattended_verbosity --value=$unattended_verbosity - -ynh_app_setting_set --app=$app --key=overwrite_periodic --value=1 -ynh_app_setting_set --app=$app --key=admin_mail_html --value=1 - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=10 - -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# SPECIFIC SETUP #================================================= # CONFIGURE APTICRON #================================================= ynh_script_progression --message="Configuring Apticron..." -apticron_config="/etc/apticron/apticron.conf" -# If the config file doesn't exist, copy the model -if [ ! -e "$apticron_config" ] -then - cp "/usr/lib/apticron/apticron.conf" "$apticron_config" -fi -# Create a backup of the config file for the reset action -cp "$apticron_config" "/etc/yunohost/apps/$app/conf/apticron.conf.backup" - -ynh_replace_string --match_string="# CUSTOM_SUBJECT=.*" \ - --replace_string="&\nCUSTOM_SUBJECT=\'[apticron] \$SYSTEM: \$NUM_PACKAGES package update(s)\'" --target_file="$apticron_config" -ynh_replace_string --match_string="# CUSTOM_NO_UPDATES_SUBJECT=.*" \ - --replace_string="&\nCUSTOM_NO_UPDATES_SUBJECT=\'[apticron] \$SYSTEM: Up to date \\\\o/\'" --target_file="$apticron_config" +_apticron_set_config #================================================= # CONFIGURE UNATTENDED-UPGRADES #================================================= ynh_script_progression --message="Configuring Unattended-Upgrades..." -unattended_upgrades_config="/etc/apt/apt.conf.d/50unattended-upgrades" - -# Make a backup of 50unattended-upgrades -cp "$unattended_upgrades_config" "/etc/apt/50unattended-upgrades.backup" - -# Configure upgrade sources -# Allow other updates -if [ "$upgrade_level" = "Security and updates" ] -then - ynh_replace_string --match_string="//\(.*\"o=Debian,a=stable\)" --replace_string="\1" --target_file="$unattended_upgrades_config" - ynh_replace_string --match_string="//\(.*\"o=Debian,a=stable-updates\)" --replace_string="\1" --target_file="$unattended_upgrades_config" -fi - -# Add YunoHost upgrade source -if [ $ynh_update -eq 1 ] -then - ynh_replace_string --match_string="origin=Debian,codename=\${distro_codename},label=Debian-Security\";" \ - --replace_string="&\n\n //YunoHost upgrade\n \"o=YunoHost,a=stable\";" --target_file="$unattended_upgrades_config" -fi - -# Allow MinimalSteps upgrading to reduce risk in case of reboot -ynh_replace_string --match_string="//\(Unattended-Upgrade::MinimalSteps\).*" --replace_string="\1 \"true\";" --target_file="$unattended_upgrades_config" - -# Configure Unattended Upgrades mailing -if [ "$unattended_mail" = "If an upgrade has been done" ] -then - # Allow mail to root - ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$unattended_upgrades_config" - - # Send mail even if there's no errors - ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"false\";" --target_file="$unattended_upgrades_config" - -elif [ "$unattended_mail" = "Only if there was an error" ] -then - # Allow mail to root - ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$unattended_upgrades_config" - - # Send mail only if there's an error - ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"true\";" --target_file="$unattended_upgrades_config" - -else # "Never" - # Comment "Unattended-Upgrade::Mail" if it isn't already commented - ynh_replace_string --match_string="^\(Unattended-Upgrade::Mail \)" --replace_string="//\1" --target_file="$unattended_upgrades_config" -fi +_unattended_upgrades_set_config #================================================= # CONFIGURE APT PERIODIC FOR UNATTENDED @@ -131,56 +41,6 @@ ynh_script_progression --message="Configure APT Periodic for Unattended" --weigh ynh_add_config --template="../conf/02periodic" --destination="/etc/apt/apt.conf.d/02periodic" -#================================================= -# MODIFY ORIGINAL APTICRON CRON FILE -#================================================= -ynh_script_progression --message="Modify original Apticron cron file" --weight=3 - -apticron_cron="/etc/cron.d/apticron" -# Create a backup of the cron file for the reset action -cp "$apticron_cron" "/etc/yunohost/apps/$app/conf/apticron.crond.backup" - -# Copy and comment the current cron -ynh_replace_string --match_string="^.* root if.*" --replace_string="#&\n&" --target_file="$apticron_cron" -# Modify the time to set at 20:00 every day -ynh_replace_string --match_string="^[[:digit:]].*\( root if.*\)" --replace_string="0 20 * * *\1" --target_file="$apticron_cron" -# Copy the new cron and set the time to 2:00 every night -ynh_replace_string --match_string="^0 20\(.*\)" --replace_string="&\n0 2\1" --target_file="$apticron_cron" - -if [ $previous_apticron -eq 0 ] -then - # Comment the first cron - ynh_replace_string --match_string="^0 20 .*" --replace_string="#&" --target_file="$apticron_cron" -fi - -if [ $after_apticron -eq 0 ] -then - # Comment the second cron - ynh_replace_string --match_string="^0 2 .*" --replace_string="#&" --target_file="$apticron_cron" -fi - -#================================================= -# GENERIC FINALISATION -#================================================= -# SEND A README FOR THE ADMIN -#================================================= - -# Get main domain and buid the url of the admin panel of the app. -admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" - -echo "To modify any option of unattended-upgrades, please have a look to $unattended_upgrades_config and -/etc/apt/apt.conf.d/02periodic -Unattended-upgrades will be executed every day at midnight. - -To modify the configuration of apticron, please have a look to $apticron_config. -Apticron will be executed, depending of the requested configuration at 8 p.m. and 2 a.m. If you want to change this schedule, please have a look to the cron file $apticron_cron. - -You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. -You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__. - -If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/unattended_upgrades_ynh__URL_TAG3__." > mail_to_send - -ynh_send_readme_to_admin --app_message="mail_to_send" --recipients=root --type=install #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index ee5abe4..e2ad5f6 100755 --- a/scripts/remove +++ b/scripts/remove @@ -9,22 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=5 - -ynh_remove_app_dependencies - #================================================= # SPECIFIC REMOVE #================================================= diff --git a/scripts/restore b/scripts/restore index cfd9f25..e221369 100644 --- a/scripts/restore +++ b/scripts/restore @@ -14,23 +14,23 @@ source /usr/share/yunohost/helpers #================================================= # 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 settings..." -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME #================================================= # SPECIFIC RESTORE #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=10 +#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=10 -ynh_install_app_dependencies $pkg_dependencies +#REMOVEME? ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE UNATTENDED-UPGRADES CONFIG diff --git a/scripts/upgrade b/scripts/upgrade index 8c7df94..2e11b61 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,20 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -unattended_verbosity=$(ynh_app_setting_get --app=$app --key=unattended_verbosity) -overwrite_periodic=$(ynh_app_setting_get --app=$app --key=overwrite_periodic) - -#================================================= -# CHECK VERSION -#================================================= - upgrade_type=$(ynh_check_app_version_changed) #================================================= @@ -39,7 +25,7 @@ fi # If admin_mail_html doesn't exist, create it if [ -z "$admin_mail_html" ]; then admin_mail_html=1 - ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html +#REMOVEME? ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html fi # Make a non perfect backup for apticron.conf if non existent @@ -61,25 +47,25 @@ fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3 +#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3 # Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { +#REMOVEME? ynh_backup_before_upgrade +#REMOVEME? ynh_clean_setup () { # restore it if the upgrade fails - ynh_restore_upgradebackup +#REMOVEME? ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS #================================================= # INSTALL 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 @@ -103,7 +89,7 @@ ynh_install_app_dependencies $pkg_dependencies if [ $overwrite_periodic -eq 1 ] then ynh_script_progression --message="Upgrading APT Periodic for Unattended..." --weight=3 - + ynh_add_config --template="../conf/02periodic" --destination="/etc/apt/apt.conf.d/02periodic" fi @@ -130,7 +116,7 @@ else fi ynh_app_changelog --format=$format -echo "To modify any option of unattended-upgrades, please have a look to /etc/apt/apt.conf.d/50unattended-upgrades and +echo "To modify any option of unattended-upgrades, please have a look to /etc/apt/apt.conf.d/50unattended-upgrades and /etc/apt/apt.conf.d/02periodic Unattended-upgrades will be executed every day at midnight. diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..1ad78f8 --- /dev/null +++ b/tests.toml @@ -0,0 +1,29 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + args.upgrade_level = "security_only" + args.ynh_update = true + args.previous_apticron = true + args.after_apticron = true + args.unattended_mail = "on_upgrade" + args.unattended_verbosity = "v1" + + test_upgrade_from.4e342d41.name = "Merge pull request #16 from YunoHost-Apps/testing" + +[suite_2] + args.upgrade_level = "security_and_updates" + args.ynh_update = false + args.previous_apticron = false + args.after_apticron = true + args.unattended_mail = "on_error" + args.unattended_verbosity = "v2" + +[suite_3] + args.upgrade_level = "security_only" + args.ynh_update = false + args.previous_apticron = true + args.after_apticron = false + args.unattended_mail = "never" + args.unattended_verbosity = "v3" From c4ee38a7a986cfb051e894a13ee59dfed78f53da Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Tue, 9 Jan 2024 16:31:23 +0000 Subject: [PATCH 02/11] Auto-update README --- README.md | 13 ------------- README_fr.md | 13 ------------- 2 files changed, 26 deletions(-) diff --git a/README.md b/README.md index b5bd12b..6b01c22 100644 --- a/README.md +++ b/README.md @@ -19,19 +19,6 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in Daily automatic upgrades **Shipped version:** 1.0~ynh6 -## Disclaimers / important information - -## Configuration - -Have a look to the following config files for Unattended-upgrades - * /etc/apt/apt.conf.d/50unattended-upgrades - * /etc/apt/apt.conf.d/02periodic - -And this one for Apticron - * /etc/apticron/apticron.conf -With its cron file - * /etc/cron.d/apticron - ## Documentation and resources * Official app website: diff --git a/README_fr.md b/README_fr.md index eb10c9b..77fe53f 100644 --- a/README_fr.md +++ b/README_fr.md @@ -19,19 +19,6 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po Mise à jour automatique quotidienne **Version incluse :** 1.0~ynh6 -## Avertissements / informations importantes - -## Configuration - -Regardez les fichiers de configuration suivant pour Unattended-upgrades - * /etc/apt/apt.conf.d/50unattended-upgrades - * /etc/apt/apt.conf.d/02periodic - -Et celui-ci pour Apticron - * /etc/apticron/apticron.conf -Avec son cron - * /etc/cron.d/apticron - ## Documentations et ressources * Site officiel de l’app : From b7a24107d414fba66b32d2efd098a00d2ead26fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 9 Jan 2024 17:53:54 +0100 Subject: [PATCH 03/11] update --- scripts/_common.sh | 19 +++-- scripts/actions/reset_default_app | 20 ----- scripts/actions/reset_default_config | 2 +- scripts/backup | 39 ++------- scripts/config | 2 +- scripts/install | 1 - scripts/remove | 15 +--- scripts/restore | 71 ++--------------- scripts/upgrade | 114 ++++++--------------------- tests.toml | 6 +- 10 files changed, 59 insertions(+), 230 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index f8b6193..59ab47b 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -9,7 +9,10 @@ #================================================= apticron_config="/etc/apticron/apticron.conf" +apticron_config_backup="/etc/yunohost/apps/$app/conf/apticron.conf.backup" + apticron_cron="/etc/cron.d/apticron" +apticron_cron_backup="/etc/yunohost/apps/$app/conf/apticron.crond.backup" _apticron_set_config() { # If the config file doesn't exist, copy the model @@ -18,7 +21,7 @@ _apticron_set_config() { fi # Create a backup of the config file for the reset action - cp "$apticron_config" "/etc/yunohost/apps/$app/conf/apticron.conf.backup" + cp "$apticron_config" "$apticron_config_backup" ynh_replace_string --match_string="# CUSTOM_SUBJECT=.*" \ --replace_string="&\nCUSTOM_SUBJECT=\'[apticron] \$SYSTEM: \$NUM_PACKAGES package update(s)\'" --target_file="$apticron_config" @@ -26,7 +29,7 @@ _apticron_set_config() { --replace_string="&\nCUSTOM_NO_UPDATES_SUBJECT=\'[apticron] \$SYSTEM: Up to date \\\\o/\'" --target_file="$apticron_config" # Create a backup of the cron file for the reset action - cp "$apticron_cron" "/etc/yunohost/apps/$app/conf/apticron.crond.backup" + cp "$apticron_cron" "$apticron_cron_backup" # Copy and comment the current cron ynh_replace_string --match_string="^.* root if.*" --replace_string="#&\n&" --target_file="$apticron_cron" @@ -47,16 +50,17 @@ _apticron_set_config() { } _apticron_restore_config() { - mv "/etc/yunohost/apps/$app/conf/apticron.conf.backup" "$apticron_config" - mv "/etc/yunohost/apps/$app/conf/apticron.crond.backup" "$apticron_cron" + mv "$apticron_config_backup" "$apticron_config" + mv "$apticron_cron_backup" "$apticron_cron" } unattended_upgrades_config="/etc/apt/apt.conf.d/50unattended-upgrades" +unattended_upgrades_config_backup="/etc/yunohost/apps/$app/conf/50unattended-upgrades.backup" _unattended_upgrades_set_config() { # Make a backup of 50unattended-upgrades - cp "$unattended_upgrades_config" "/etc/yunohost/apps/$app/conf/50unattended-upgrades.backup" + cp "$unattended_upgrades_config" "$unattended_upgrades_config_backup" # Configure upgrade sources # Allow other updates @@ -89,15 +93,14 @@ _unattended_upgrades_set_config() { # Send mail only if there's an error ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"true\";" --target_file="$unattended_upgrades_config" - else # "Never" + else # "Never" # Comment "Unattended-Upgrade::Mail" if it isn't already commented ynh_replace_string --match_string="^\(Unattended-Upgrade::Mail \)" --replace_string="//\1" --target_file="$unattended_upgrades_config" fi - } _unattended_upgrades_restore_config() { - mv "/etc/yunohost/apps/$app/conf/50unattended-upgrades.backup" "$unattended_upgrades_config" + mv "$unattended_upgrades_config_backup" "$unattended_upgrades_config" } #================================================= diff --git a/scripts/actions/reset_default_app b/scripts/actions/reset_default_app index bee4768..6cbe00d 100755 --- a/scripts/actions/reset_default_app +++ b/scripts/actions/reset_default_app @@ -10,26 +10,6 @@ source 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 - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -app=$YNH_APP_INSTANCE_NAME - -unattended_verbosity=$(ynh_app_setting_get --app=$app --key=unattended_verbosity) -upgrade_level="$(ynh_app_setting_get --app=$app --key=upgrade_level)" -ynh_update=$(ynh_app_setting_get --app=$app --key=ynh_update) -unattended_mail="$(ynh_app_setting_get --app=$app --key=unattended_mail)" -previous_apticron=$(ynh_app_setting_get --app=$app --key=previous_apticron) -after_apticron=$(ynh_app_setting_get --app=$app --key=after_apticron) - #================================================= # SPECIFIC ACTION #================================================= diff --git a/scripts/actions/reset_default_config b/scripts/actions/reset_default_config index 1cad8f5..db02539 100755 --- a/scripts/actions/reset_default_config +++ b/scripts/actions/reset_default_config @@ -93,7 +93,7 @@ then # Send mail only if there's an error ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"true\";" --target_file="$config_file" - else # "Never" + else # "Never" # Comment "Unattended-Upgrade::Mail" if it isn't already commented ynh_replace_string --match_string="^\(Unattended-Upgrade::Mail \)" --replace_string="//\1" --target_file="$config_file" fi diff --git a/scripts/backup b/scripts/backup index 2d41076..380c9b4 100644 --- a/scripts/backup +++ b/scripts/backup @@ -9,20 +9,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 -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_print_info --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -32,28 +18,17 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP UNATTENDED-UPGRADES CONFIG #================================================= -ynh_backup --src_path="/etc/apt/apt.conf.d/50unattended-upgrades" -# Backup also the backup of the config file -ynh_backup --src_path="/etc/apt/50unattended-upgrades.backup" +ynh_backup --src_path="$apticron_config" +ynh_backup --src_path="$apticron_config_backup" -#================================================= -# BACKUP APT PERIODIC -#================================================= +ynh_backup --src_path="$apticron_cron" +ynh_backup --src_path="$apticron_cron_backup" + +ynh_backup --src_path="$unattended_upgrades_config" +ynh_backup --src_path="$unattended_upgrades_config_backup" ynh_backup --src_path="/etc/apt/apt.conf.d/02periodic" -#================================================= -# BACKUP APTICRON CONFIG -#================================================= - -ynh_backup --src_path="/etc/apticron/apticron.conf" - -#================================================= -# BACKUP THE CRON FILE -#================================================= - -ynh_backup --src_path="/etc/cron.d/apticron" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/config b/scripts/config index dc96869..522b10f 100644 --- a/scripts/config +++ b/scripts/config @@ -156,7 +156,7 @@ apply_config() { # Send mail only if there's an error ynh_replace_string --match_string="/*\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"true\";" --target_file="$unattended_upgrades_config" - else # "Never" + else # "Never" # Comment "Unattended-Upgrade::Mail" ynh_replace_string --match_string="^\(Unattended-Upgrade::Mail \)" --replace_string="//\1" --target_file="$unattended_upgrades_config" fi diff --git a/scripts/install b/scripts/install index 39751c9..29c5857 100644 --- a/scripts/install +++ b/scripts/install @@ -41,7 +41,6 @@ ynh_script_progression --message="Configure APT Periodic for Unattended" --weigh ynh_add_config --template="../conf/02periodic" --destination="/etc/apt/apt.conf.d/02periodic" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index e2ad5f6..4502cc0 100755 --- a/scripts/remove +++ b/scripts/remove @@ -10,21 +10,14 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# SPECIFIC REMOVE +# REMOVE SYSTEM CONFIGURATIONS #================================================= -# REMOVE THE APT PERIODIC FILE -#================================================= -ynh_script_progression --message="Removing the APT Periodic file..." +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 +_apticron_restore_config +_unattended_upgrades_restore_config ynh_secure_remove "/etc/apt/apt.conf.d/02periodic" -#================================================= -# DECONFIGURE UNATTENDED-UPGRADES -#================================================= -ynh_script_progression --message="Deconfiguring unattended-upgrades..." - -mv "/etc/apt/50unattended-upgrades.backup" "/etc/apt/apt.conf.d/50unattended-upgrades" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index e221369..f325e7e 100644 --- a/scripts/restore +++ b/scripts/restore @@ -9,78 +9,21 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#================================================= -# SPECIFIC RESTORE -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=10 - -#REMOVEME? ynh_install_app_dependencies $pkg_dependencies - #================================================= # RESTORE UNATTENDED-UPGRADES CONFIG #================================================= -ynh_restore_file --origin_path="/etc/apt/apt.conf.d/50unattended-upgrades" -# Restore also the backup config file -ynh_restore_file --origin_path="/etc/apt/50unattended-upgrades.backup" +ynh_restore_file --origin_path="$apticron_config" +ynh_restore_file --origin_path="$apticron_config_backup" -#================================================= -# RESTORE APT PERIODIC -#================================================= +ynh_restore_file --origin_path="$apticron_cron" +ynh_restore_file --origin_path="$apticron_cron_backup" + +ynh_restore_file --origin_path="$unattended_upgrades_config" +ynh_restore_file --origin_path="$unattended_upgrades_config_backup" ynh_restore_file --origin_path="/etc/apt/apt.conf.d/02periodic" -#================================================= -# RESTORE APTICRON CONFIG -#================================================= - -ynh_restore_file --origin_path="/etc/apticron/apticron.conf" - -#================================================= -# RESTORE CRON FILE -#================================================= - -ynh_restore_file --origin_path="/etc/cron.d/apticron" - -#================================================= -# GENERIC FINALISATION -#================================================= -# SEND A README FOR THE ADMIN -#================================================= - -# Get main domain and buid the url of the admin panel of the app. -admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" - -echo "To modify any option of unattended-upgrades, please have a look to /etc/apt/apt.conf.d/50unattended-upgrades and -/etc/apt/apt.conf.d/02periodic -Unattended-upgrades will be executed every day at midnight. - -To modify the configuration of apticron, please have a look to /etc/apticron/apticron.conf. -Apticron will be executed, depending of the requested configuration at 8 p.m. and 2 a.m. If you want to change this schedule, please have a look to the cron file /etc/cron.d/apticron. - -You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. -You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__. - -If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/unattended_upgrades_ynh__URL_TAG3__." > mail_to_send - -ynh_send_readme_to_admin --app_message="mail_to_send" --recipients=root --type=restore - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 2e11b61..690c1cf 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -17,124 +17,56 @@ upgrade_type=$(ynh_check_app_version_changed) ynh_script_progression --message="Ensuring downward compatibility..." # If overwrite_periodic doesn't exist, create it -if [ -z "$overwrite_periodic" ]; then +if [ -z "${overwrite_periodic:-}" ]; then overwrite_periodic=1 ynh_app_setting_set --app=$app --key=overwrite_periodic --value=$overwrite_periodic fi -# If admin_mail_html doesn't exist, create it -if [ -z "$admin_mail_html" ]; then - admin_mail_html=1 -#REMOVEME? ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html -fi - # Make a non perfect backup for apticron.conf if non existent -if [ ! -e "../conf/apticron.conf.backup" ]; then +if [ ! -e "$apticron_config_backup" ]; then # Create a backup of the config file for the reset action - cp "/etc/apticron/apticron.conf" "../conf/apticron.conf.backup" - sed --in-place '/^CUSTOM_SUBJECT=/d' "../conf/apticron.conf.backup" - sed --in-place '/^CUSTOM_NO_UPDATES_SUBJECT=/d' "../conf/apticron.conf.backup" + cp "$apticron_config" "$apticron_config_backup" + sed --in-place '/^CUSTOM_SUBJECT=/d' "$apticron_config_backup" + sed --in-place '/^CUSTOM_NO_UPDATES_SUBJECT=/d' "$apticron_config_backup" fi # Make a non perfect backup for apticron cron file if non existent -if [ ! -e "../conf/apticron.crond.backup" ]; then +if [ ! -e "$apticron_cron" ]; then # Create a backup of the config file for the reset action - cp "/etc/cron.d/apticron" "../conf/apticron.crond.backup" - sed --in-place '/^[[:digit:]]/d' "../conf/apticron.crond.backup" - ynh_replace_string --match_string="^#\([[:digit:]].*\)" --replace_string="\1" --target_file="../conf/apticron.crond.backup" + cp "$apticron_cron" "$apticron_cron" + sed --in-place '/^[[:digit:]]/d' "$apticron_cron" + ynh_replace_string --match_string="^#\([[:digit:]].*\)" --replace_string="\1" --target_file="$apticron_cron" +fi + +# Make a non perfect backup for apticron cron file if non existent +if [ ! -e "$unattended_upgrades_config" ]; then + cp "$unattended_upgrades_config" "$unattended_upgrades_config_backup" fi #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# CONFIGURE APTICRON #================================================= -#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3 +ynh_script_progression --message="Configuring Apticron..." -# Backup the current version of the app -#REMOVEME? ynh_backup_before_upgrade -#REMOVEME? ynh_clean_setup () { - # restore it if the upgrade fails -#REMOVEME? ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors +_apticron_set_config #================================================= -# STANDARD UPGRADE STEPS +# CONFIGURE UNATTENDED-UPGRADES #================================================= -# INSTALL DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=5 +ynh_script_progression --message="Configuring Unattended-Upgrades..." -#REMOVEME? ynh_install_app_dependencies $pkg_dependencies +_unattended_upgrades_set_config #================================================= -# SPECIFIC UPGRADE +# CONFIGURE APT PERIODIC FOR UNATTENDED #================================================= -# UPGRADE APTICRON -#================================================= - -# Nothing to do here... - -#================================================= -# UPGRADE UNATTENDED-UPGRADES -#================================================= - -# Nothing to do here... - -#================================================= -# UPGRADE APT PERIODIC FOR UNATTENDED -#================================================= - # Overwrite 02periodic config file only if it's allowed -if [ $overwrite_periodic -eq 1 ] -then - ynh_script_progression --message="Upgrading APT Periodic for Unattended..." --weight=3 +if [ "$overwrite_periodic" -eq 1 ]; then + ynh_script_progression --message="Upgrading APT Periodic for Unattended..." ynh_add_config --template="../conf/02periodic" --destination="/etc/apt/apt.conf.d/02periodic" fi -#================================================= -# UPGRADE APTICRON CRON FILE -#================================================= - -# Nothing to do here... - -#================================================= -# GENERIC FINALISATION -#================================================= -# SEND A README FOR THE ADMIN -#================================================= - -# Get main domain and buid the url of the admin panel of the app. -admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" - -# If a html email is required. Apply html to the changelog. -if [ "$admin_mail_html" -eq 1 ]; then - format=html -else - format=plain -fi -ynh_app_changelog --format=$format - -echo "To modify any option of unattended-upgrades, please have a look to /etc/apt/apt.conf.d/50unattended-upgrades and -/etc/apt/apt.conf.d/02periodic -Unattended-upgrades will be executed every day at midnight. - -To modify the configuration of apticron, please have a look to /etc/apticron/apticron.conf. -Apticron will be executed, depending of the requested configuration at 8 p.m. and 2 a.m. If you want to change this schedule, please have a look to the cron file /etc/cron.d/apticron. - -You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. -You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__. - -If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/unattended_upgrades_ynh__URL_TAG3__. - ---- - -Changelog since your last upgrade: -$(cat changelog)" > mail_to_send - -ynh_send_readme_to_admin --app_message="mail_to_send" --recipients=root --type=upgrade - #================================================= # END OF SCRIPT #================================================= diff --git a/tests.toml b/tests.toml index 1ad78f8..1ea8f16 100644 --- a/tests.toml +++ b/tests.toml @@ -10,7 +10,11 @@ test_format = 1.0 args.unattended_mail = "on_upgrade" args.unattended_verbosity = "v1" - test_upgrade_from.4e342d41.name = "Merge pull request #16 from YunoHost-Apps/testing" + [default.test_upgrade_from.4e342d41] + name = "Merge pull request #16 from YunoHost-Apps/testing" + args.upgrade_level = "Security only" + args.unattended_mail = "On upgrade" + args.unattended_verbosity = "1" [suite_2] args.upgrade_level = "security_and_updates" From 36d71406aadba0b09ac1618490abfafdefc953ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 9 Jan 2024 18:07:57 +0100 Subject: [PATCH 04/11] update --- actions.toml | 7 +- scripts/_common.sh | 11 +++ scripts/actions/reset_default_app | 72 ----------------- scripts/actions/reset_default_config | 116 --------------------------- scripts/install | 2 +- scripts/remove | 2 +- scripts/upgrade | 2 +- 7 files changed, 17 insertions(+), 195 deletions(-) delete mode 100755 scripts/actions/reset_default_app delete mode 100755 scripts/actions/reset_default_config diff --git a/actions.toml b/actions.toml index 7691e45..fd10d87 100644 --- a/actions.toml +++ b/actions.toml @@ -1,6 +1,6 @@ [reset_default_unattended] name = "Reset the 50unattended-upgrades config file and restore a default one." -command = "/bin/bash scripts/actions/reset_default_config \"50unattended-upgrades\"" +command = "/bin/bash scripts/actions/reapply_config \"50unattended-upgrades\"" # user = "root" # optional # cwd = "/" # optional # accepted_return_codes = [0, 1, 2, 3] # optional @@ -9,17 +9,16 @@ description = "Reset the unattended-upgrades config file 50unattended-upgrades." [reset_default_periodic] name = "Reset the 02periodic apt config file and restore a default one." -command = "/bin/bash scripts/actions/reset_default_config \"02periodic\"" +command = "/bin/bash scripts/actions/reapply_config \"02periodic\"" # user = "root" # optional # cwd = "/" # optional # accepted_return_codes = [0, 1, 2, 3] # optional accepted_return_codes = [0] description = "Reset the config file 02periodic." - [reset_default_app] name = "Reset the app with a default configuration." -command = "/bin/bash scripts/actions/reset_default_app" +command = "/bin/bash scripts/actions/reapply_config \"50unattended-upgrades\" \"02periodic\" \"apticron\"" # user = "root" # optional # cwd = "/" # optional # accepted_return_codes = [0, 1, 2, 3] # optional diff --git a/scripts/_common.sh b/scripts/_common.sh index 59ab47b..334e079 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -103,6 +103,17 @@ _unattended_upgrades_restore_config() { mv "$unattended_upgrades_config_backup" "$unattended_upgrades_config" } + +_02periodic_config="/etc/apt/apt.conf.d/02periodic" + +_02periodic_set_config() { + ynh_add_config --template="../conf/02periodic" --destination="$_02periodic_config" +} + +_02periodic_remove() { + ynh_secure_remove "$_02periodic_config" +} + #================================================= # BACKUP #================================================= diff --git a/scripts/actions/reset_default_app b/scripts/actions/reset_default_app deleted file mode 100755 index 6cbe00d..0000000 --- a/scripts/actions/reset_default_app +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -# Load common variables for all scripts. -source scripts/_common.sh -source /usr/share/yunohost/helpers - -#================================================= -# SPECIFIC ACTION -#================================================= -# RESET APTICRON CONFIGURATION -#================================================= -ynh_script_progression --message="Resetting Apticron..." - -apticron_config="/etc/apticron/apticron.conf" -cp "conf/apticron.conf.backup" "$apticron_config" -ynh_replace_string --match_string="# CUSTOM_SUBJECT=.*" \ - --replace_string="&\nCUSTOM_SUBJECT=\'[apticron] \$SYSTEM: \$NUM_PACKAGES package update(s)\'" --target_file="$apticron_config" -ynh_replace_string --match_string="# CUSTOM_NO_UPDATES_SUBJECT=.*" \ - --replace_string="&\nCUSTOM_NO_UPDATES_SUBJECT=\'[apticron] \$SYSTEM: Up to date \\\\o/\'" --target_file="$apticron_config" - -#================================================= -# RESET UNATTENDED-UPGRADES CONFIGURATION -#================================================= -ynh_script_progression --message="Resetting unattended-upgrades..." - -yunohost app action run $app reset_default_unattended - -#================================================= -# RESET APT PERIODIC CONFIGURATION -#================================================= -ynh_script_progression --message="Resetting apt periodic..." - -yunohost app action run $app reset_default_periodic - -#================================================= -# RESET APTICRON CRON FILE -#================================================= -ynh_script_progression --message="Resetting apticron cron file..." - -apticron_cron="/etc/cron.d/apticron" -cp "conf/apticron.crond.backup" "$apticron_cron" - -# Copy and comment the current cron -ynh_replace_string --match_string="^.* root if.*" --replace_string="#&\n&" --target_file="$apticron_cron" -# Modify the time to set at 20:00 every day -ynh_replace_string --match_string="^[[:digit:]].*\( root if.*\)" --replace_string="0 20 * * *\1" --target_file="$apticron_cron" -# Copy the new cron and set the time to 2:00 every night -ynh_replace_string --match_string="^0 20\(.*\)" --replace_string="&\n0 2\1" --target_file="$apticron_cron" - -if [ $previous_apticron -eq 0 ] -then - # Comment the first cron - ynh_replace_string --match_string="^0 20 .*" --replace_string="#&" --target_file="$apticron_cron" -fi - -if [ $after_apticron -eq 0 ] -then - # Comment the second cron - ynh_replace_string --match_string="^0 2 .*" --replace_string="#&" --target_file="$apticron_cron" -fi - -#================================================= -# END OF SCRIPT -#================================================= - -ynh_script_progression --message="Execution completed" --last diff --git a/scripts/actions/reset_default_config b/scripts/actions/reset_default_config deleted file mode 100755 index db02539..0000000 --- a/scripts/actions/reset_default_config +++ /dev/null @@ -1,116 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source 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 - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=2 - -app=$YNH_APP_INSTANCE_NAME - -upgrade_level="$(ynh_app_setting_get --app=$app --key=upgrade_level)" -ynh_update=$(ynh_app_setting_get --app=$app --key=ynh_update) -unattended_mail="$(ynh_app_setting_get --app=$app --key=unattended_mail)" -unattended_verbosity=$(ynh_app_setting_get --app=$app --key=unattended_verbosity) - -#================================================= -# SORT OUT THE CONFIG FILE TO HANDLE -#================================================= - -file="$1" - -if [ "$file" = "50unattended-upgrades" ]; then - config_file="/etc/apt/apt.conf.d/50unattended-upgrades" -elif [ "$file" = "02periodic" ]; then - config_file="/etc/apt/apt.conf.d/02periodic" -fi - -#================================================= -# SPECIFIC ACTION -#================================================= -# RESET THE CONFIG FILE -#================================================= -ynh_script_progression --message="Resetting the config file $config_file..." --weight=9 - -# Verify the checksum and backup the file if it's different -ynh_backup_if_checksum_is_different --file="$config_file" - -# Reset the config /etc/apt/apt.conf.d/50unattended-upgrades -if [ "$file" = "50unattended-upgrades" ] -then - # Get the default file and overwrite the current config - cp /etc/apt/50unattended-upgrades.backup "$config_file" - - # Recreate the default config - # Allow security update - ynh_replace_string --match_string="//\(.*\"o=Debian,n=$(ynh_get_debian_release),l=Debian-Security\";\)" --replace_string="\1" --target_file="$config_file" - # Allow other updates - if [ "$upgrade_level" = "Security and updates" ] - then - ynh_replace_string --match_string="//\(.*\"o=Debian,n=$(ynh_get_debian_release)\";\)" --replace_string="\1" --target_file="$config_file" - ynh_replace_string --match_string="//\(.*\"o=Debian,n=$(ynh_get_debian_release)-updates\";\)" --replace_string="\1" --target_file="$config_file" - fi - - # Add YunoHost upgrade source - if [ $ynh_update -eq 1 ] - then - ynh_replace_string --match_string="origin=Debian,codename=\$(ynh_get_debian_release),label=Debian-Security\";" \ - --replace_string="&\n\n //YunoHost upgrade\n \"o=YunoHost,n=$(ynh_get_debian_release)\";" --target_file="$config_file" - fi - - # Allow MinimalSteps upgrading to reduce risk in case of reboot - ynh_replace_string --match_string="//\(Unattended-Upgrade::MinimalSteps\).*" --replace_string="\1 \"true\";" --target_file="$config_file" - - # Configure Unattended Upgrades mailing - if [ "$unattended_mail" = "If an upgrade has been done" ] - then - # Allow mail to root - ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$config_file" - - # Send mail even if there's no errors - ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"false\";" --target_file="$config_file" - - elif [ "$unattended_mail" = "Only if there was an error" ] - then - # Allow mail to root - ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$config_file" - - # Send mail only if there's an error - ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"true\";" --target_file="$config_file" - - else # "Never" - # Comment "Unattended-Upgrade::Mail" if it isn't already commented - ynh_replace_string --match_string="^\(Unattended-Upgrade::Mail \)" --replace_string="//\1" --target_file="$config_file" - fi -fi - -# Reset the config /etc/apt/apt.conf.d/02periodic -if [ "$file" = "02periodic" ] -then - # Get the default file and overwrite the current config - ynh_add_config --template="../conf/02periodic" --destination="/etc/apt/apt.conf.d/02periodic" -fi - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$config_file" - -#================================================= -# END OF SCRIPT -#================================================= - -ynh_script_progression --message="Execution completed" --last diff --git a/scripts/install b/scripts/install index 29c5857..90f6afe 100644 --- a/scripts/install +++ b/scripts/install @@ -39,7 +39,7 @@ _unattended_upgrades_set_config #================================================= ynh_script_progression --message="Configure APT Periodic for Unattended" --weight=2 -ynh_add_config --template="../conf/02periodic" --destination="/etc/apt/apt.conf.d/02periodic" +_02periodic_set_config #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 4502cc0..183c83d 100755 --- a/scripts/remove +++ b/scripts/remove @@ -16,7 +16,7 @@ ynh_script_progression --message="Removing system configurations related to $app _apticron_restore_config _unattended_upgrades_restore_config -ynh_secure_remove "/etc/apt/apt.conf.d/02periodic" +_02periodic_remove #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 690c1cf..8d54727 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -64,7 +64,7 @@ _unattended_upgrades_set_config if [ "$overwrite_periodic" -eq 1 ]; then ynh_script_progression --message="Upgrading APT Periodic for Unattended..." - ynh_add_config --template="../conf/02periodic" --destination="/etc/apt/apt.conf.d/02periodic" + _02periodic_set_config fi #================================================= From 0d71a589ce6d0c2fe61a96937dd639e06969e582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 9 Jan 2024 18:08:16 +0100 Subject: [PATCH 05/11] update --- scripts/actions/reapply_config | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 scripts/actions/reapply_config diff --git a/scripts/actions/reapply_config b/scripts/actions/reapply_config new file mode 100755 index 0000000..82eb7be --- /dev/null +++ b/scripts/actions/reapply_config @@ -0,0 +1,61 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +# Load common variables for all scripts. +source scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# SPECIFIC ACTION +#================================================= +# RESET APTICRON CONFIGURATION +#================================================= + +if [[ "$*" =~ ^apticron$ ]]; then + ynh_script_progression --message="Resetting Apticron..." + + ynh_backup_if_checksum_is_different --file="$apticron_config" + ynh_backup_if_checksum_is_different --file="$apticron_cron" + + _apticron_restore_config + _apticron_set_config + + ynh_store_file_checksum --file="$apticron_config" + ynh_store_file_checksum --file="$apticron_cron" +fi + +#================================================= +# RESET UNATTENDED-UPGRADES CONFIGURATION +#================================================= + +if [[ "$*" =~ ^50unattended-upgrades$ ]]; then + ynh_script_progression --message="Resetting unattended-upgrades..." + + ynh_backup_if_checksum_is_different --file="$unattended_upgrades_config" + _unattended_upgrades_restore_config + _unattended_upgrades_set_config + ynh_store_file_checksum --file="$unattended_upgrades_config" +fi + +#================================================= +# RESET APT PERIODIC CONFIGURATION +#================================================= + +if [[ "$*" =~ ^02periodic$ ]]; then + ynh_script_progression --message="Resetting apt periodic..." + + ynh_backup_if_checksum_is_different --file="$_02periodic_config" + _02periodic_set_config + ynh_store_file_checksum --file="$_02periodic_config" +fi + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Execution completed" --last From 6906fc305cb58aa6958882aa4b1847913a71f0f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 9 Jan 2024 18:21:04 +0100 Subject: [PATCH 06/11] fix arg upgrade --- tests.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.toml b/tests.toml index 1ea8f16..9f21fb5 100644 --- a/tests.toml +++ b/tests.toml @@ -13,7 +13,7 @@ test_format = 1.0 [default.test_upgrade_from.4e342d41] name = "Merge pull request #16 from YunoHost-Apps/testing" args.upgrade_level = "Security only" - args.unattended_mail = "On upgrade" + args.unattended_mail = "If an upgrade has been done" args.unattended_verbosity = "1" [suite_2] From 11a50fb023637ff4cf3f88f974df896aa709a5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 10 Jan 2024 19:12:55 +0100 Subject: [PATCH 07/11] add description.md --- doc/DESCRIPTION.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 doc/DESCRIPTION.md diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..623fa46 --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1,4 @@ +This package installs `unattended-upgrades` and `apticron` to: + +* automatically install security updates (or all updates if selected) +* send automatic messages about available and done updates From 9380b6ebe0127f1badc5e1c1e60f2a966a855e0f Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Wed, 10 Jan 2024 18:13:00 +0000 Subject: [PATCH 08/11] Auto-update README --- README.md | 6 +++++- README_fr.md | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6b01c22..3655f75 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,11 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in ## Overview -Daily automatic upgrades +This package installs `unattended-upgrades` and `apticron` to: + +* automatically install security updates (or all updates if selected) +* send automatic messages about available and done updates + **Shipped version:** 1.0~ynh6 ## Documentation and resources diff --git a/README_fr.md b/README_fr.md index 77fe53f..9a1e9e0 100644 --- a/README_fr.md +++ b/README_fr.md @@ -16,7 +16,11 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po ## Vue d’ensemble -Mise à jour automatique quotidienne +This package installs `unattended-upgrades` and `apticron` to: + +* automatically install security updates (or all updates if selected) +* send automatic messages about available and done updates + **Version incluse :** 1.0~ynh6 ## Documentations et ressources From c9bbf5965ee6b6b1a440c600d5fe65c24c6c4bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Sat, 13 Jan 2024 11:30:59 +0100 Subject: [PATCH 09/11] Bump ynh revision --- manifest.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.toml b/manifest.toml index 6f0387f..e14df8a 100644 --- a/manifest.toml +++ b/manifest.toml @@ -7,7 +7,7 @@ name = "Unattended-upgrades" description.en = "Daily automatic upgrades" description.fr = "Mise à jour automatique quotidienne" -version = "1.0~ynh6" +version = "1.0~ynh7" maintainers = [] From 5e76bcc9ab2f4b3370323bed031947e7b8fb6fbe Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Sat, 13 Jan 2024 10:31:05 +0000 Subject: [PATCH 10/11] Auto-update README --- README.md | 2 +- README_fr.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3655f75..09f66dd 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ This package installs `unattended-upgrades` and `apticron` to: * send automatic messages about available and done updates -**Shipped version:** 1.0~ynh6 +**Shipped version:** 1.0~ynh7 ## Documentation and resources * Official app website: diff --git a/README_fr.md b/README_fr.md index 9a1e9e0..8a2a83b 100644 --- a/README_fr.md +++ b/README_fr.md @@ -22,7 +22,7 @@ This package installs `unattended-upgrades` and `apticron` to: * send automatic messages about available and done updates -**Version incluse :** 1.0~ynh6 +**Version incluse :** 1.0~ynh7 ## Documentations et ressources * Site officiel de l’app : From 1e5262c95abc278b9dfa86a4f9c76ffebb5d67a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Sat, 13 Jan 2024 12:30:05 +0100 Subject: [PATCH 11/11] Fix manifest.toml option type --- manifest.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.toml b/manifest.toml index e14df8a..0d87fb5 100644 --- a/manifest.toml +++ b/manifest.toml @@ -31,7 +31,7 @@ ram.runtime = "50M" [install.upgrade_level] ask.en = "Choose the sources of packages to automatically upgrade" ask.fr = "Choisissez les sources des paquets à mettre à jour automatiquement" - type = "string" + type = "select" choices.security_only = "Security only" choices.security_and_updates = "Security and updates" default = "security_only"