From ad2e5bae89b8b024d05fce3705332e3d5e23d127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Wed, 25 Oct 2023 21:45:35 +0200 Subject: [PATCH 1/7] v2 --- manifest.toml | 67 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/_common.sh | 8 +++--- scripts/backup | 8 +++--- scripts/install | 10 +++---- scripts/remove | 10 +++---- scripts/restore | 16 +++++------ scripts/upgrade | 26 +++++++++--------- 7 files changed, 106 insertions(+), 39 deletions(-) create mode 100644 manifest.toml diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..5e8fbbf --- /dev/null +++ b/manifest.toml @@ -0,0 +1,67 @@ +packaging_format = 2 + +id = "borgserver" +name = "Borg Server" +description.en = "Offer backup storage to a friend" +description.fr = "Offrez un espace de stockage à un⋅e ami⋅e" + +version = "1.1.16~ynh9" + +maintainers = ["ljf"] + +[upstream] +license = "BSD-3-Clause" +website = "https://www.borgbackup.org/" +admindoc = "https://borgbackup.readthedocs.io/en/stable/" +code = "https://github.com/borgbackup/borg" +cpe = "???" # FIXME: optional but recommended if relevant, this is meant to contain the Common Platform Enumeration, which is sort of a standard id for applications defined by the NIST. In particular, Yunohost may use this is in the future to easily track CVE (=security reports) related to apps. The CPE may be obtained by searching here: https://nvd.nist.gov/products/cpe/search. For example, for Nextcloud, the CPE is 'cpe:2.3:a:nextcloud:nextcloud' (no need to include the version number) +fund = "???" # FIXME: optional but recommended (or remove if irrelevant / not applicable). This is meant to be an URL where people can financially support this app, especially when its development is based on volunteers and/or financed by its community. YunoHost may later advertise it in the webadmin. + +[integration] +yunohost = ">= 4.2.3" +architectures = "all" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"] +multi_instance = true +ldap = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "sso" key : the "ldap" key corresponds to wether or not a user *can* login on the app using its YunoHost credentials. +sso = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "ldap" key : the "sso" key corresponds to wether or not a user is *automatically logged-in* on the app when logged-in on the YunoHost portal. +disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... +ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... + +[install] + [install.ssh_user] + ask.en = "Indicate the SSH user to create" + ask.fr = "Indiquez l'utilisateur SSH à créer" + type = "string" + example = "john" + + [install.public_key] + ask.en = "Indicate the public key given by borg_ynh app" + ask.fr = "Indiquez la clé publique donnée par l'app borg_ynh" + type = "string" + + [install.alert_delay] + ask.en = "After which delay in days should we alert if there are no changes on repo ?" + ask.fr = "Après quel délais en jours devons-nous lancer une alerte si il n'y a pas de changement dans le repo ?" + type = "string" + default = "1" + + [install.alert_mails] + ask.en = "Emails to whom send alerts ?" + ask.fr = "Emails des personnes à qui envoyer les alertes ?" + type = "string" + default = "root" + example = "camille@example.com,eden@example.com" + + [install.quota] + ask.en = "Indicate the storage quota" + ask.fr = "Indiquez le quota de stockage" + type = "string" + optionnal = true + example = "30G" + +[resources] + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] diff --git a/scripts/_common.sh b/scripts/_common.sh index 53870b5..ea74774 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,7 +7,7 @@ PKG_DIR=$(cd ../; pwd) BORG_VERSION=1.1.16 -pkg_dependencies="python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev python3-jinja2 python3-setuptools python3-venv virtualenv libfuse-dev pkg-config" +#REMOVEME? pkg_dependencies="python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev python3-jinja2 python3-setuptools python3-venv virtualenv libfuse-dev pkg-config" # Install borg with pip if borg is not here install_borg_with_pip () { @@ -35,10 +35,10 @@ ynh_export () { for var in $@; do ynh_arg=$(echo "$var" | awk '{print toupper($0)}') - if [ "$var" == "path_url" ]; then + if [ "$var" == "path" ]; then ynh_arg="PATH" fi - ynh_arg="YNH_APP_ARG_$ynh_arg" +#REMOVEME? ynh_arg="YNH_APP_ARG_$ynh_arg" export $var="${!ynh_arg}" done } @@ -48,7 +48,7 @@ ynh_save_args () { for var in $@; do local setting_var="$var" - if [ "$var" == "path_url" ]; then + if [ "$var" == "path" ]; then setting_var="path" fi ynh_app_setting_set $app $setting_var "${!var}" diff --git a/scripts/backup b/scripts/backup index 4263664..2d524e4 100755 --- a/scripts/backup +++ b/scripts/backup @@ -13,15 +13,15 @@ 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 -export ssh_user="$(ynh_app_setting_get $app ssh_user)" +#REMOVEME? app=$YNH_APP_INSTANCE_NAME +#REMOVEME? export ssh_user="$(ynh_app_setting_get $app ssh_user)" #================================================= # DECLARE DATA AND CONF FILES TO BACKUP diff --git a/scripts/install b/scripts/install index a7c29c3..d2813c2 100755 --- a/scripts/install +++ b/scripts/install @@ -14,13 +14,13 @@ 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 #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -export app=$YNH_APP_INSTANCE_NAME +#REMOVEME? export app=$YNH_APP_INSTANCE_NAME # Retrieve arguments ynh_export ssh_user public_key quota alert_delay alert_mails @@ -44,9 +44,9 @@ ynh_save_args ssh_user public_key quota alert_delay alert_mails #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." +#REMOVEME? ynh_script_progression --message="Installing dependencies..." -ynh_install_app_dependencies $pkg_dependencies +#REMOVEME? ynh_install_app_dependencies $pkg_dependencies install_borg_with_pip #================================================= @@ -54,7 +54,7 @@ install_borg_with_pip #================================================= ynh_script_progression --message="Creating SSH user used by Borg..." -ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app +#REMOVEME? ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app #================================================= # AUTORIZE SSH FOR THIS USER diff --git a/scripts/remove b/scripts/remove index bb5bf94..9d85f73 100755 --- a/scripts/remove +++ b/scripts/remove @@ -13,15 +13,15 @@ source /usr/share/yunohost/helpers # LOAD SETTINGS #================================================= -app=$YNH_APP_INSTANCE_NAME -ssh_user=$(ynh_app_setting_get $app ssh_user) +#REMOVEME? app=$YNH_APP_INSTANCE_NAME +#REMOVEME? ssh_user=$(ynh_app_setting_get $app ssh_user) #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." +#REMOVEME? ynh_script_progression --message="Removing dependencies..." -ynh_remove_app_dependencies +#REMOVEME? ynh_remove_app_dependencies # Remove borg if we are removing the last borg app on the system if [ "$(yunohost app list | grep "id: borg" | wc -l)" == "1" ] ; then @@ -34,7 +34,7 @@ fi #================================================= # We keep files cause we don't know what the user want to do about # backups stored in the home directory -ynh_system_user_delete --username=$ssh_user +#REMOVEME? ynh_system_user_delete --username=$ssh_user #================================================= # REMOVE CRON FILES diff --git a/scripts/restore b/scripts/restore index 410547b..5904c69 100755 --- a/scripts/restore +++ b/scripts/restore @@ -14,24 +14,24 @@ 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 #================================================= -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME -export ssh_user=$(ynh_app_setting_get $app ssh_user) -export public_key=$(ynh_app_setting_get $app public_key) -export quota=$(ynh_app_setting_get $app quota) +#REMOVEME? export ssh_user=$(ynh_app_setting_get $app ssh_user) +#REMOVEME? export public_key=$(ynh_app_setting_get $app public_key) +#REMOVEME? export quota=$(ynh_app_setting_get $app quota) #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." +#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." -ynh_install_app_dependencies $pkg_dependencies +#REMOVEME? ynh_install_app_dependencies $pkg_dependencies install_borg_with_pip #================================================= @@ -39,7 +39,7 @@ install_borg_with_pip #================================================= ynh_script_progression --message="Creating SSH user used by Borg..." -ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app +#REMOVEME? ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app #================================================= # AUTORIZE SSH FOR THIS USER diff --git a/scripts/upgrade b/scripts/upgrade index a55b038..13f2c8c 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -13,12 +13,12 @@ source /usr/share/yunohost/helpers # LOAD SETTINGS #================================================= -app=$YNH_APP_INSTANCE_NAME -ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user) -public_key=$(ynh_app_setting_get --app=$app --key=public_key) -alert_delay=$(ynh_app_setting_get --app=$app --key=alert_delay) -alert_mails=$(ynh_app_setting_get --app=$app --key=alert_mails) -quota=$(ynh_app_setting_get --app=$app --key=quota) +#REMOVEME? app=$YNH_APP_INSTANCE_NAME +#REMOVEME? ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user) +#REMOVEME? public_key=$(ynh_app_setting_get --app=$app --key=public_key) +#REMOVEME? alert_delay=$(ynh_app_setting_get --app=$app --key=alert_delay) +#REMOVEME? alert_mails=$(ynh_app_setting_get --app=$app --key=alert_mails) +#REMOVEME? quota=$(ynh_app_setting_get --app=$app --key=quota) #================================================= # CHECK IF AN UPGRADE IS NEEDED @@ -33,13 +33,13 @@ ynh_check_app_version_changed # We don't backup before upgrade cause we don't want accidental # remove of repo if upgrade failed -#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 #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -83,14 +83,14 @@ fi #================================================= ynh_script_progression --message="Creating SSH user used by Borg..." -ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app +#REMOVEME? ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." +#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." -ynh_install_app_dependencies $pkg_dependencies +#REMOVEME? ynh_install_app_dependencies $pkg_dependencies #================================================= # SPECIFIC UPGRADE From e9e4804c0ee8459c2a6983d9014c373c5f6a72d4 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Wed, 25 Oct 2023 19:45:39 +0000 Subject: [PATCH 2/7] Auto-update README --- README.md | 4 ++-- README_fr.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fa8d128..28369e5 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ It shall NOT be edited by hand. # Borg Server for YunoHost -[![Integration level](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![Working status](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/borgserver.maintain.svg) +[![Integration level](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![Working status](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/borgserver.maintain.svg) + [![Install Borg Server with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=borgserver) *[Lire ce readme en français.](./README_fr.md)* @@ -26,7 +27,6 @@ The main goal of Borg is to provide an efficient and secure way to backup data. * Official app website: * Official admin documentation: * Upstream app code repository: -* YunoHost documentation for this app: * Report a bug: ## Developer info diff --git a/README_fr.md b/README_fr.md index 8b87325..7fa160e 100644 --- a/README_fr.md +++ b/README_fr.md @@ -5,7 +5,8 @@ It shall NOT be edited by hand. # Borg Server pour YunoHost -[![Niveau d’intégration](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/borgserver.maintain.svg) +[![Niveau d’intégration](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/borgserver.maintain.svg) + [![Installer Borg Server avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=borgserver) *[Read this readme in english.](./README.md)* @@ -26,7 +27,6 @@ The main goal of Borg is to provide an efficient and secure way to backup data. * Site officiel de l’app : * Documentation officielle de l’admin : * Dépôt de code officiel de l’app : -* Documentation YunoHost pour cette app : * Signaler un bug : ## Informations pour les développeurs From cad879fb567b057eac20b9b9b80d846c508d066c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Wed, 25 Oct 2023 21:57:09 +0200 Subject: [PATCH 3/7] v2 --- manifest.toml | 24 +++++++++++++----------- scripts/_common.sh | 4 +--- scripts/install | 15 +++------------ scripts/remove | 15 ++++----------- scripts/restore | 20 +------------------- scripts/upgrade | 36 ++---------------------------------- tests.toml | 21 +++++++++++++++++++++ 7 files changed, 45 insertions(+), 90 deletions(-) create mode 100644 tests.toml diff --git a/manifest.toml b/manifest.toml index 5e8fbbf..9c8b28f 100644 --- a/manifest.toml +++ b/manifest.toml @@ -5,7 +5,7 @@ name = "Borg Server" description.en = "Offer backup storage to a friend" description.fr = "Offrez un espace de stockage à un⋅e ami⋅e" -version = "1.1.16~ynh9" +version = "1.2.6~ynh1" maintainers = ["ljf"] @@ -14,18 +14,16 @@ license = "BSD-3-Clause" website = "https://www.borgbackup.org/" admindoc = "https://borgbackup.readthedocs.io/en/stable/" code = "https://github.com/borgbackup/borg" -cpe = "???" # FIXME: optional but recommended if relevant, this is meant to contain the Common Platform Enumeration, which is sort of a standard id for applications defined by the NIST. In particular, Yunohost may use this is in the future to easily track CVE (=security reports) related to apps. The CPE may be obtained by searching here: https://nvd.nist.gov/products/cpe/search. For example, for Nextcloud, the CPE is 'cpe:2.3:a:nextcloud:nextcloud' (no need to include the version number) -fund = "???" # FIXME: optional but recommended (or remove if irrelevant / not applicable). This is meant to be an URL where people can financially support this app, especially when its development is based on volunteers and/or financed by its community. YunoHost may later advertise it in the webadmin. [integration] -yunohost = ">= 4.2.3" -architectures = "all" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"] +yunohost = ">= 11.2" +architectures = "all" multi_instance = true -ldap = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "sso" key : the "ldap" key corresponds to wether or not a user *can* login on the app using its YunoHost credentials. -sso = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "ldap" key : the "sso" key corresponds to wether or not a user is *automatically logged-in* on the app when logged-in on the YunoHost portal. -disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... -ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... -ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ldap = "not_relevant" +sso = "not_relevant" +disk = "50M" +ram.build = "50M" +ram.runtime = "50M" [install] [install.ssh_user] @@ -62,6 +60,10 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen [resources] [resources.system_user] - [resources.install_dir] + #[resources.install_dir] [resources.permissions] + + [resources.apt] + packages = "python3-pip, python3-dev, libacl1-dev, libssl-dev, liblz4-dev, python3-jinja2, python3-setuptools, python3-venv, virtualenv, libfuse-dev, pkg-config" + diff --git a/scripts/_common.sh b/scripts/_common.sh index ea74774..a2eafc1 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,9 +5,7 @@ #================================================= # App package root directory should be the parent folder PKG_DIR=$(cd ../; pwd) -BORG_VERSION=1.1.16 - -#REMOVEME? pkg_dependencies="python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev python3-jinja2 python3-setuptools python3-venv virtualenv libfuse-dev pkg-config" +BORG_VERSION=1.2.6 # Install borg with pip if borg is not here install_borg_with_pip () { diff --git a/scripts/install b/scripts/install index d2813c2..d77d07d 100755 --- a/scripts/install +++ b/scripts/install @@ -9,19 +9,10 @@ source _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 - #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -#REMOVEME? export app=$YNH_APP_INSTANCE_NAME - # Retrieve arguments ynh_export ssh_user public_key quota alert_delay alert_mails @@ -44,9 +35,8 @@ ynh_save_args ssh_user public_key quota alert_delay alert_mails #================================================= # INSTALL DEPENDENCIES #================================================= -#REMOVEME? ynh_script_progression --message="Installing dependencies..." +ynh_script_progression --message="Installing dependencies..." -#REMOVEME? ynh_install_app_dependencies $pkg_dependencies install_borg_with_pip #================================================= @@ -54,7 +44,7 @@ install_borg_with_pip #================================================= ynh_script_progression --message="Creating SSH user used by Borg..." -#REMOVEME? ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app +ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app #================================================= # AUTORIZE SSH FOR THIS USER @@ -83,6 +73,7 @@ touch $home/.nobackup # SETUP CRON #================================================= ynh_script_progression --message="Configuring cron to monitor backup..." + ynh_add_config --template="monitor-backup" --destination="/etc/cron.d/$app" #================================================= diff --git a/scripts/remove b/scripts/remove index 9d85f73..d907141 100755 --- a/scripts/remove +++ b/scripts/remove @@ -9,19 +9,10 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME -#REMOVEME? ssh_user=$(ynh_app_setting_get $app ssh_user) - #================================================= # REMOVE DEPENDENCIES #================================================= -#REMOVEME? ynh_script_progression --message="Removing dependencies..." - -#REMOVEME? ynh_remove_app_dependencies +ynh_script_progression --message="Removing dependencies..." # Remove borg if we are removing the last borg app on the system if [ "$(yunohost app list | grep "id: borg" | wc -l)" == "1" ] ; then @@ -34,11 +25,13 @@ fi #================================================= # We keep files cause we don't know what the user want to do about # backups stored in the home directory -#REMOVEME? ynh_system_user_delete --username=$ssh_user + +ynh_system_user_delete --username=$ssh_user #================================================= # REMOVE CRON FILES #================================================= + ynh_secure_remove "/etc/cron.d/$app" #================================================= diff --git a/scripts/restore b/scripts/restore index 5904c69..12bc819 100755 --- a/scripts/restore +++ b/scripts/restore @@ -9,29 +9,11 @@ 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? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? export ssh_user=$(ynh_app_setting_get $app ssh_user) -#REMOVEME? export public_key=$(ynh_app_setting_get $app public_key) -#REMOVEME? export quota=$(ynh_app_setting_get $app quota) - #================================================= # INSTALL DEPENDENCIES #================================================= #REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." -#REMOVEME? ynh_install_app_dependencies $pkg_dependencies install_borg_with_pip #================================================= @@ -39,7 +21,7 @@ install_borg_with_pip #================================================= ynh_script_progression --message="Creating SSH user used by Borg..." -#REMOVEME? ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app +ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app #================================================= # AUTORIZE SSH FOR THIS USER diff --git a/scripts/upgrade b/scripts/upgrade index 13f2c8c..d6b2f3a 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,38 +9,12 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME -#REMOVEME? ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user) -#REMOVEME? public_key=$(ynh_app_setting_get --app=$app --key=public_key) -#REMOVEME? alert_delay=$(ynh_app_setting_get --app=$app --key=alert_delay) -#REMOVEME? alert_mails=$(ynh_app_setting_get --app=$app --key=alert_mails) -#REMOVEME? quota=$(ynh_app_setting_get --app=$app --key=quota) - #================================================= # CHECK IF AN UPGRADE IS NEEDED #================================================= ynh_check_app_version_changed -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= - -# We don't backup before upgrade cause we don't want accidental -# remove of repo if upgrade failed - -#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 - #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -83,14 +57,7 @@ fi #================================================= ynh_script_progression --message="Creating SSH user used by Borg..." -#REMOVEME? ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." - -#REMOVEME? ynh_install_app_dependencies $pkg_dependencies +ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app #================================================= # SPECIFIC UPGRADE @@ -126,6 +93,7 @@ touch /home/$ssh_user/.nobackup # SETUP CRON #================================================= ynh_script_progression --message="Configuring cron to monitor backup..." + ynh_add_config --template="monitor-backup" --destination="/etc/cron.d/$app" #================================================= diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..c61c0a2 --- /dev/null +++ b/tests.toml @@ -0,0 +1,21 @@ +test_format = 1.0 + +[default] + + # ------------ + # Tests to run + # ------------ + + exclude = ["install.root", "install.subdir", "change_url"] # The test IDs to be used in only/exclude statements are: install.root, install.subdir, install.nourl, install.multi, backup_restore, upgrade, upgrade.someCommitId change_url + # NB: you should NOT need this except if you really have a good reason... + + + # ------------ + # Tests to run + # ------------ + + args.ssh_user="sam" + args.public_key="ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" + args.alert_delay=1 + args.alert_mails="sam@domain.tld" + args.quota="1G" \ No newline at end of file From 8fa3f329a67f8a76d26149e94bffb2039bf73958 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 4 Dec 2023 20:31:10 +0100 Subject: [PATCH 4/7] Try to cleanup some of the mess .. --- check_process | 27 --------------------------- manifest.toml | 5 ----- scripts/_common.sh | 33 --------------------------------- scripts/backup | 21 --------------------- scripts/install | 38 ++++++++------------------------------ scripts/restore | 25 ++++++++++--------------- scripts/upgrade | 32 ++++++++++++-------------------- tests.toml | 22 +++++----------------- 8 files changed, 35 insertions(+), 168 deletions(-) delete mode 100644 check_process diff --git a/check_process b/check_process deleted file mode 100644 index edbba5a..0000000 --- a/check_process +++ /dev/null @@ -1,27 +0,0 @@ -;; Test complet - ; Manifest - ssh_user="sam" - public_key="ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" - alert_delay=1 - alert_mails="sam@domain.tld" - quota="1G" - ; 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=c6ff77fc299c008b83cfe5f849b5d115989d5c49 - backup_restore=1 - multi_instance=1 - port_already_use=0 - change_url=0 -;;; Options -Email=ljf+borg_ynh@reflexlibre.net -Notificatio -;;; Upgrade options - ; commit=c6ff77fc299c008b83cfe5f849b5d115989d5c49 - name=Merge pull request #26 from YunoHost-Apps/testing - manifest_arg=ssh_user=sam&public_key=ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"a=1G diff --git a/manifest.toml b/manifest.toml index 9c8b28f..2ae9754 100644 --- a/manifest.toml +++ b/manifest.toml @@ -58,12 +58,7 @@ ram.runtime = "50M" example = "30G" [resources] - [resources.system_user] - - #[resources.install_dir] - [resources.permissions] [resources.apt] packages = "python3-pip, python3-dev, libacl1-dev, libssl-dev, liblz4-dev, python3-jinja2, python3-setuptools, python3-venv, virtualenv, libfuse-dev, pkg-config" - diff --git a/scripts/_common.sh b/scripts/_common.sh index a2eafc1..6720bb1 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,10 +1,5 @@ #!/bin/bash -#================================================= -# COMMON VARIABLES -#================================================= -# App package root directory should be the parent folder -PKG_DIR=$(cd ../; pwd) BORG_VERSION=1.2.6 # Install borg with pip if borg is not here @@ -24,31 +19,3 @@ install_borg_with_pip () { # We need this to be executable by other borg apps chmod a+x /usr/local/bin/borg } - -#================================================= -# COMMON HELPERS -#================================================= -ynh_export () { - local ynh_arg="" - for var in $@; - do - ynh_arg=$(echo "$var" | awk '{print toupper($0)}') - if [ "$var" == "path" ]; then - ynh_arg="PATH" - fi -#REMOVEME? ynh_arg="YNH_APP_ARG_$ynh_arg" - export $var="${!ynh_arg}" - done -} -# Save listed var in YunoHost app settings -# usage: ynh_save_args VARNAME1 [VARNAME2 [...]] -ynh_save_args () { - for var in $@; - do - local setting_var="$var" - if [ "$var" == "path" ]; then - setting_var="path" - fi - ynh_app_setting_set $app $setting_var "${!var}" - done -} diff --git a/scripts/backup b/scripts/backup index 2d524e4..5a503fa 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,28 +1,7 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - 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 -#REMOVEME? export ssh_user="$(ynh_app_setting_get $app ssh_user)" - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= diff --git a/scripts/install b/scripts/install index d77d07d..45ba80e 100755 --- a/scripts/install +++ b/scripts/install @@ -9,13 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -# Retrieve arguments -ynh_export ssh_user public_key quota alert_delay alert_mails - #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= @@ -26,12 +19,6 @@ if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] ; then fi ynh_system_user_exists --username=$ssh_user && ynh_die --message="This user already exists" -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= - -ynh_save_args ssh_user public_key quota alert_delay alert_mails - #================================================= # INSTALL DEPENDENCIES #================================================= @@ -39,34 +26,25 @@ ynh_script_progression --message="Installing dependencies..." install_borg_with_pip -#================================================= -# CREATE SSH USER USED BY BORG -#================================================= -ynh_script_progression --message="Creating SSH user used by Borg..." - -ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app - #================================================= # AUTORIZE SSH FOR THIS USER #================================================= ynh_script_progression --message="Configuring SSH public key for remote connexion..." +ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app + home=/home/$ssh_user -mkdir -p /home/$ssh_user/.ssh -chmod o=--- /home/$ssh_user -chown -R $ssh_user:$ssh_user /home/$ssh_user -touch /home/$ssh_user/.ssh/authorized_keys +mkdir -p $home/.ssh +chmod o=--- $home +chown -R $ssh_user:$ssh_user $home +touch $home/.ssh/authorized_keys extra="--storage-quota $quota" if [ "$quota" = "" ]; then extra="" fi -echo "command=\"borg serve $extra --restrict-to-repository /home/$ssh_user/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> /home/$ssh_user/.ssh/authorized_keys - -#================================================= -# AVOID BACKUP OF BACKUP -#================================================= -ynh_script_progression --message="Avoiding to backup the backup itself..." +echo "command=\"borg serve $extra --restrict-to-repository $home/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> $home/.ssh/authorized_keys +# Tweak to prevent the backup of the backup itself touch $home/.nobackup #================================================= diff --git a/scripts/restore b/scripts/restore index 12bc819..0b41588 100755 --- a/scripts/restore +++ b/scripts/restore @@ -12,37 +12,32 @@ source /usr/share/yunohost/helpers #================================================= # INSTALL DEPENDENCIES #================================================= -#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." +ynh_script_progression --message="Reinstalling borg env..." install_borg_with_pip #================================================= # CREATE SSH USER USED BY BORG #================================================= -ynh_script_progression --message="Creating SSH user used by Borg..." +ynh_script_progression --message="Making sure SSH user exists with appropriate permissions..." ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app -#================================================= -# AUTORIZE SSH FOR THIS USER -#================================================= - home=/home/$ssh_user -mkdir -p /home/$ssh_user/.ssh -chmod o=--- /home/$ssh_user -chown -R $ssh_user:$ssh_user /home/$ssh_user -touch /home/$ssh_user/.ssh/authorized_keys +mkdir -p $home/.ssh +chmod o=--- $home/$ssh_user extra="--storage-quota $quota" if [ "$quota" = "" ]; then extra="" fi -echo "command=\"borg serve $extra --restrict-to-repository /home/$ssh_user/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> /home/$ssh_user/.ssh/authorized_keys - -#================================================= -# AVOID BACKUP OF BACKUP -#================================================= +echo "command=\"borg serve $extra --restrict-to-repository $home/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> $home/.ssh/authorized_keys +chown -R $ssh_user:$ssh_user $home +# Tweak to prevent the backup of the backup itself touch $home/.nobackup + + +# Actual restore of ...? ynh_restore #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index d6b2f3a..4e2dd21 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -30,7 +30,7 @@ if [ -f "/etc/yunohost/hooks.d/backup/17-data_home" ]; then fi # Fix broken value ssh_user that mistakenly got replaced by the public key in previous versions... -[ -n "$ssh_user" ] || ynh_die "Unable to retrieve ssh_user please fix /etc/yunohost/apps/$app/settings.yml manually :( !" +[ -n "${ssh_user:-}" ] || ynh_die "Unable to retrieve ssh_user please fix /etc/yunohost/apps/$app/settings.yml manually :( !" if echo "$ssh_user" | grep -q ' '; then ssh_user=$(grep "$ssh_user" /home/*/.ssh/authorized_keys | grep borg | cut -d/ -f3) [ -n "$ssh_user" ] || ynh_die "Unable to retrieve ssh_user please fix /etc/yunohost/apps/$app/settings.yml manually :( !" @@ -42,7 +42,7 @@ if echo "$public_key" | grep -q -v ' '; then fi # Alert delay and alert mail missing -if [ -z "$alert_delay" ]; then +if [ -z "${alert_delay:-}" ]; then ynh_app_setting_set --app=$app --key=alert_delay --value=1 ynh_app_setting_set --app=$app --key=alert_mails --value="root" fi @@ -52,13 +52,6 @@ if [ ! -f "/opt/borg-env/$(ynh_get_debian_release)" ] ; then ynh_secure_remove /opt/borg-env fi -#================================================= -# CREATE SSH USER USED BY BORG -#================================================= -ynh_script_progression --message="Creating SSH user used by Borg..." - -ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app - #================================================= # SPECIFIC UPGRADE #================================================= @@ -71,23 +64,22 @@ install_borg_with_pip #================================================= # AUTORIZE SSH FOR THIS USER #================================================= -ynh_script_progression --message="Seting good permissions..." +ynh_script_progression --message="Making sure SSH user exists with appropriate permissions..." -mkdir -p /home/$ssh_user/.ssh -chmod o=--- /home/$ssh_user +ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app + +home=/home/$ssh_user +mkdir -p $home/.ssh +chmod o=--- $home/$ssh_user extra="--storage-quota $quota" if [ "$quota" = "" ]; then extra="" fi -echo "command=\"borg serve $extra --restrict-to-repository /home/$ssh_user/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> /home/$ssh_user/.ssh/authorized_keys -chown -R $ssh_user:$ssh_user /home/$ssh_user +echo "command=\"borg serve $extra --restrict-to-repository $home/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> $home/.ssh/authorized_keys +chown -R $ssh_user:$ssh_user $home -#================================================= -# AVOID BACKUP OF BACKUP -#================================================= -ynh_script_progression --message="Avoiding to backup the backup itself..." - -touch /home/$ssh_user/.nobackup +# Tweak to prevent the backup of the backup itself +touch $home/.nobackup #================================================= # SETUP CRON diff --git a/tests.toml b/tests.toml index c61c0a2..faaf6c7 100644 --- a/tests.toml +++ b/tests.toml @@ -2,20 +2,8 @@ test_format = 1.0 [default] - # ------------ - # Tests to run - # ------------ - - exclude = ["install.root", "install.subdir", "change_url"] # The test IDs to be used in only/exclude statements are: install.root, install.subdir, install.nourl, install.multi, backup_restore, upgrade, upgrade.someCommitId change_url - # NB: you should NOT need this except if you really have a good reason... - - - # ------------ - # Tests to run - # ------------ - - args.ssh_user="sam" - args.public_key="ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" - args.alert_delay=1 - args.alert_mails="sam@domain.tld" - args.quota="1G" \ No newline at end of file + args.ssh_user = "sam" + args.public_key = "ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" + args.alert_delay = 1 + args.alert_mails = "sam@domain.tld" + args.quota = "1G" From 9d8d85b6e250a7760e9c6decbcf1f06d99625f4f Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Mon, 4 Dec 2023 19:31:24 +0000 Subject: [PATCH 5/7] Auto-update README --- README.md | 1 + README_fr.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 28369e5..72adfc6 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ The main goal of Borg is to provide an efficient and secure way to backup data. * Official app website: * Official admin documentation: * Upstream app code repository: +* YunoHost Store: * Report a bug: ## Developer info diff --git a/README_fr.md b/README_fr.md index 7fa160e..a98033e 100644 --- a/README_fr.md +++ b/README_fr.md @@ -27,6 +27,7 @@ The main goal of Borg is to provide an efficient and secure way to backup data. * Site officiel de l’app : * Documentation officielle de l’admin : * Dépôt de code officiel de l’app : +* YunoHost Store: * Signaler un bug : ## Informations pour les développeurs From a3da355e0e3ddc19cce101fa0fa1fc1c05204eda Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 4 Dec 2023 21:31:34 +0100 Subject: [PATCH 6/7] Fix package_check tweak.. --- scripts/install | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 45ba80e..4faa57f 100755 --- a/scripts/install +++ b/scripts/install @@ -14,9 +14,10 @@ source /usr/share/yunohost/helpers #================================================= # Here is a small hack to avoid multi install CI test to fail due # to same ssh_user provided -if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] ; then +if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] && [[ "$YNH_APP_INSTANCE_NUMBER" != "1" ]] ; then ssh_user+="$YNH_APP_INSTANCE_NUMBER" fi + ynh_system_user_exists --username=$ssh_user && ynh_die --message="This user already exists" #================================================= From 958b58dddc684670dfa21597ccaae82c8fa6a59e Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 4 Dec 2023 22:21:00 +0100 Subject: [PATCH 7/7] Typo --- scripts/restore | 2 +- scripts/upgrade | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/restore b/scripts/restore index 0b41588..c176e72 100755 --- a/scripts/restore +++ b/scripts/restore @@ -25,7 +25,7 @@ ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_she home=/home/$ssh_user mkdir -p $home/.ssh -chmod o=--- $home/$ssh_user +chmod o=--- $home extra="--storage-quota $quota" if [ "$quota" = "" ]; then extra="" diff --git a/scripts/upgrade b/scripts/upgrade index 4e2dd21..4546a08 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -70,7 +70,7 @@ ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_she home=/home/$ssh_user mkdir -p $home/.ssh -chmod o=--- $home/$ssh_user +chmod o=--- $home extra="--storage-quota $quota" if [ "$quota" = "" ]; then extra=""