From 7ae2a32926e4f6a616fba91b79ce72d5839681c1 Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Mon, 11 Jan 2021 00:34:05 +0100 Subject: [PATCH 1/8] [fix] Avoid to use virtualenv --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 3ae7714..ed7af32 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -11,7 +11,7 @@ pkg_dependencies="python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev pyth # Install borg with pip if borg is not here install_borg_with_pip () { if [ ! -d /opt/borg-env ]; then - virtualenv --python=python3 /opt/borg-env + python3 -m venv /opt/borg-env /opt/borg-env/bin/python /opt/borg-env/bin/pip install borgbackup==1.1.10 echo "#!/bin/bash /opt/borg-env/bin/python /opt/borg-env/bin/borg \"\$@\"" > /usr/local/bin/borg From 4bae195eca353c4e6f41d0923936ab9f572fdda9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Mon, 11 Jan 2021 00:36:16 +0100 Subject: [PATCH 2/8] Upgrade to V.1.1.14 (#29) * Upgrade to v. 1.1.14 * Fix linter warnings * Small typos Co-authored-by: ljf (zamentur) --- README.md | 59 +++++++++++++++++++++++++++++++++++-- check_process | 12 -------- manifest.json | 13 +++++---- scripts/_common.sh | 73 ++-------------------------------------------- scripts/install | 15 +++++++++- scripts/remove | 9 ++++++ scripts/restore | 10 +++++++ scripts/upgrade | 16 +++++++++- 8 files changed, 116 insertions(+), 91 deletions(-) diff --git a/README.md b/README.md index a7891fd..9b63e4c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,58 @@ -# borgserver_ynh -Offer backup storage to a friend +# Borg Server for YunoHost +[![Integration level](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![](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) + +> *This package allows you to install Borg Server quickly and simply on a YunoHost server. +If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* + +## Overview +Offer backup storage to a friend. +The main goal of Borg is to provide an efficient and secure way to backup data. The data deduplication technique used makes Borg suitable for daily backups since only changes are stored. The authenticated encryption technique makes it suitable for backups to not fully trusted targets. + +**Shipped version:** 1.1.14 + +## Documentation + + * Official documentation: https://borgbackup.readthedocs.io/en/stable/ + * YunoHost documentation: If specific documentation is needed, feel free to contribute. + +## YunoHost specific features + +#### Multi-user support + + * Are LDAP and HTTP auth supported? + * Can the app be used by multiple users? + +#### Supported architectures + +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/borgserver%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/borgserver/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/borgserver%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/borgserver/) + +## Limitations + +* Any known limitations. + +## Additional information + +* Other info you would like to add about this app. + +## Links + + * Report a bug: https://github.com/YunoHost-Apps/borgserver_ynh/issues + * App website: https://www.borgbackup.org/ + * Upstream app repository: https://github.com/borgbackup/borg + * YunoHost website: https://yunohost.org/ + +--- + +## Developer info + +Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing --debug +or +sudo yunohost app upgrade borgserver -u https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing --debug +``` diff --git a/check_process b/check_process index 0154af1..efc60ad 100644 --- a/check_process +++ b/check_process @@ -14,20 +14,8 @@ upgrade=1 backup_restore=1 multi_instance=0 - incorrect_path=0 port_already_use=0 change_url=0 -;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto - Level 4=na - Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 ;;; Options Email=ljf+borgserver_ynh@reflexlibre.net Notification=down diff --git a/manifest.json b/manifest.json index 7bdbeba..6f3ba89 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Offer backup storage to a friend.", "fr": "Offrez un espace de stockage à un⋅e ami⋅e." }, - "version": "1.1.10~ynh5", + "version": "1.1.14~ynh1", "url": "https://borgbackup.readthedocs.io", "license": "BSD-3-Clause", "maintainer": { @@ -15,22 +15,24 @@ "url": "https://reflexlibre.net" }, "requirements": { - "yunohost": ">= 3.6" + "yunohost": ">= 3.8.1" }, - "multi_instance": true, + "multi_instance": false, "services": [], "arguments": { "install" : [ { "name": "ssh_user", + "type": "string", "ask": { - "en": "Indicate the ssh user to create", - "fr": "Indiquez l'utilisateur ssh à créer" + "en": "Indicate the SSH user to create", + "fr": "Indiquez l'utilisateur SSH à créer" }, "example": "john" }, { "name": "public_key", + "type": "string", "ask": { "en": "Indicate the public key given by borg_ynh app", "fr": "Indiquez la clé publique donnée par l'app borg_ynh" @@ -38,6 +40,7 @@ }, { "name": "quota", + "type": "string", "ask": { "en": "Indicate the storage quota", "fr": "Indiquez le quota de stockage" diff --git a/scripts/_common.sh b/scripts/_common.sh index ed7af32..9553a46 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -12,7 +12,7 @@ pkg_dependencies="python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev pyth install_borg_with_pip () { if [ ! -d /opt/borg-env ]; then python3 -m venv /opt/borg-env - /opt/borg-env/bin/python /opt/borg-env/bin/pip install borgbackup==1.1.10 + /opt/borg-env/bin/python /opt/borg-env/bin/pip install borgbackup==1.1.14 echo "#!/bin/bash /opt/borg-env/bin/python /opt/borg-env/bin/borg \"\$@\"" > /usr/local/bin/borg chmod a+x /usr/local/bin/borg @@ -47,22 +47,7 @@ ynh_save_args () { done } -# Render templates with Jinja2 -# -# Attention : Variables should be exported before calling this helper to be -# accessible inside templates. -# -# usage: ynh_render_template some_template output_path -# | arg: some_template - Template file to be rendered -# | arg: output_path - The path where the output will be redirected to -ynh_render_template() { - local template_path=$1 - local output_path=$2 - # Taken from https://stackoverflow.com/a/35009576 - python2.7 -c 'import os, sys, jinja2; sys.stdout.write( - jinja2.Template(sys.stdin.read() - ).render(os.environ));' < $template_path > $output_path -} + ynh_configure () { ynh_backup_if_checksum_is_different $2 @@ -71,57 +56,5 @@ ynh_configure () { } ynh_read_json () { - sudo python3 -c "import sys, json;print(json.load(open('$1'))['$2'])" -} - -ynh_read_manifest () { - if [ -f '../manifest.json' ] ; then - ynh_read_json '../manifest.json' "$1" - else - ynh_read_json '../settings/manifest.json' "$1" - fi -} -# Checks the app version to upgrade with the existing app version and returns: -# - UPGRADE_APP if the upstream app version has changed -# - UPGRADE_PACKAGE if only the YunoHost package has changed -# -## It stops the current script without error if the package is up-to-date -# -# This helper should be used to avoid an upgrade of an app, or the upstream part -# of it, when it's not needed -# -# To force an upgrade, even if the package is up to date, -# you have to set the variable YNH_FORCE_UPGRADE before. -# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp - -# usage: ynh_check_app_version_changed -ynh_check_app_version_changed () { - local force_upgrade=${YNH_FORCE_UPGRADE:-0} - local package_check=${PACKAGE_CHECK_EXEC:-0} - - # By default, upstream app version has changed - local return_value="UPGRADE_APP" - - local current_version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) - local current_upstream_version="${current_version/~ynh*/}" - local update_version=$(ynh_read_manifest "../manifest.json" "version" || echo 1.0) - local update_upstream_version="${update_version/~ynh*/}" - - if [ "$current_version" == "$update_version" ] ; then - # Complete versions are the same - if [ "$force_upgrade" != "0" ] - then - echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2 - unset YNH_FORCE_UPGRADE - elif [ "$package_check" != "0" ] - then - echo "Upgrade forced for package check." >&2 - else - ynh_die "Up-to-date, nothing to do" 0 - fi - elif [ "$current_upstream_version" == "$update_upstream_version" ] ; then - # Upstream versions are the same, only YunoHost package versions differ - return_value="UPGRADE_PACKAGE" - fi - echo $return_value + python3 -c "import sys, json;print(json.load(open('$1'))['$2'])" } diff --git a/scripts/install b/scripts/install index d49c8a6..10e81f7 100755 --- a/scripts/install +++ b/scripts/install @@ -19,8 +19,8 @@ ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -export app=$YNH_APP_INSTANCE_NAME +export app=$YNH_APP_INSTANCE_NAME # Retrieve arguments ynh_export ssh_user public_key quota @@ -28,27 +28,34 @@ ynh_export ssh_user public_key quota #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= + 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 #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Installing dependencies..." + ynh_install_app_dependencies $pkg_dependencies install_borg_with_pip #================================================= # CREATE SSH USER USED BY BORG #================================================= +ynh_script_progression --message="Creat SSH user used by Borg..." + adduser $ssh_user --quiet --gecos ",,," --shell /bin/bash --disabled-password #================================================= # AUTORIZE SSH FOR THIS USER #================================================= + home=/home/$ssh_user mkdir -p /home/$ssh_user/.ssh touch /home/$ssh_user/.ssh/authorized_keys @@ -61,5 +68,11 @@ echo "command=\"borg serve $extra --restrict-to-repository /home/$ssh_user/backu #================================================= # AVOID BACKUP OF BACKUP #================================================= + touch $home/.nobackup +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index 03babc8..4f5756e 100755 --- a/scripts/remove +++ b/scripts/remove @@ -19,9 +19,18 @@ ssh_user=$(ynh_app_setting_get $app ssh_user) #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_script_progression --message="Removing dependencies..." + ynh_remove_app_dependencies #================================================= # REMOVE FILES #================================================= + userdel $ssh_user + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 01756a1..d0fa4ae 100755 --- a/scripts/restore +++ b/scripts/restore @@ -29,17 +29,21 @@ export quota=$(ynh_app_setting_get $app quota) #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Reinstalling dependencies..." + ynh_install_app_dependencies $pkg_dependencies install_borg_with_pip #================================================= # CREATE SSH USER USED BY BORG #================================================= + adduser $ssh_user --quiet --gecos ",,," --shell /bin/bash --disabled-password #================================================= # AUTORIZE SSH FOR THIS USER #================================================= + home=/home/$ssh_user mkdir -p /home/$ssh_user/.ssh touch /home/$ssh_user/.ssh/authorized_keys @@ -52,6 +56,12 @@ echo "command=\"borg serve $extra --restrict-to-repository /home/$ssh_user/backu #================================================= # AVOID BACKUP OF BACKUP #================================================= + touch $home/.nobackup ynh_restore +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index bb19d2c..40f12ef 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -19,6 +19,7 @@ ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user) #================================================= # CHECK IF AN UPGRADE IS NEEDED #================================================= + ynh_check_app_version_changed #================================================= @@ -34,7 +35,6 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors - #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -52,3 +52,17 @@ fi if echo "$ssh_user" | grep -v ' '; then ynh_app_setting_set --app=$app --key=ssh_user --value="$(grep -Po 'no-user-rc \K.*$' /home/$ssh_user/.ssh/authorized_keys)" fi + +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." + +ynh_install_app_dependencies $pkg_dependencies +install_borg_with_pip + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" --last From dbe5923576a7e22afaf4640caf62e3b92e099bbc Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 7 Apr 2021 03:52:14 +0200 Subject: [PATCH 3/8] Fix stupid typo that overwrote the ssh_user setting ... --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 40f12ef..e94e027 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -50,7 +50,7 @@ if [ -f "/etc/yunohost/hooks.d/backup/17-data_home" ]; then fi if echo "$ssh_user" | grep -v ' '; then - ynh_app_setting_set --app=$app --key=ssh_user --value="$(grep -Po 'no-user-rc \K.*$' /home/$ssh_user/.ssh/authorized_keys)" + ynh_app_setting_set --app=$app --key=public_key --value="$(grep -Po 'no-user-rc \K.*$' /home/$ssh_user/.ssh/authorized_keys)" fi #================================================= From 400b4c5725c7a06b98f39cfcfb43ed0db5f9f76e Mon Sep 17 00:00:00 2001 From: ljf Date: Thu, 8 Apr 2021 20:20:10 +0200 Subject: [PATCH 4/8] [enh] Add monitoring options --- README.md | 2 +- check_process | 20 ++++++++++++------- conf/monitor-backup | 2 ++ manifest.json | 23 ++++++++++++++++++++-- scripts/_common.sh | 25 ++++++++++------------- scripts/backup | 18 +++++++++++++++++ scripts/install | 15 +++++++++++--- scripts/remove | 18 ++++++++++++++--- scripts/upgrade | 48 +++++++++++++++++++++++++++++++++++++-------- 9 files changed, 132 insertions(+), 39 deletions(-) create mode 100644 conf/monitor-backup diff --git a/README.md b/README.md index 9b63e4c..c19f68a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in Offer backup storage to a friend. The main goal of Borg is to provide an efficient and secure way to backup data. The data deduplication technique used makes Borg suitable for daily backups since only changes are stored. The authenticated encryption technique makes it suitable for backups to not fully trusted targets. -**Shipped version:** 1.1.14 +**Shipped version:** 1.1.16 ## Documentation diff --git a/check_process b/check_process index efc60ad..edbba5a 100644 --- a/check_process +++ b/check_process @@ -1,9 +1,10 @@ ;; Test complet ; Manifest - server="domain.tld:22" - ssh_user="sam" - public_key="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILM5TaFx9x9gXAkdRqEw39tpBLW/jXFzcBe9diuPlEfP" - quota="5G" + 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 @@ -12,10 +13,15 @@ setup_private=0 setup_public=0 upgrade=1 + upgrade=1 from_commit=c6ff77fc299c008b83cfe5f849b5d115989d5c49 backup_restore=1 - multi_instance=0 + multi_instance=1 port_already_use=0 change_url=0 ;;; Options -Email=ljf+borgserver_ynh@reflexlibre.net -Notification=down +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/conf/monitor-backup b/conf/monitor-backup new file mode 100644 index 0000000..9010a0f --- /dev/null +++ b/conf/monitor-backup @@ -0,0 +1,2 @@ +SHELL=/bin/bash +0 9,20 * * * root : Monitor __SSH_USER__ backup ; ALERT_DELAY="$(yunohost app setting __APP__ alert_delay)"; [[ $(find /home/__SSH_USER__ -mtime -${ALERT_DELAY} -ls | wc -l) > 0 ]] || ( echo "No file has been backuped in /home/__SSH_USER__ since ${ALERT_DELAY} days" | mail -s "[YNH] Backup missing : __SSH_USER__" $(yunohost app setting __APP__ alert_mails)) diff --git a/manifest.json b/manifest.json index 6f3ba89..877c874 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Offer backup storage to a friend.", "fr": "Offrez un espace de stockage à un⋅e ami⋅e." }, - "version": "1.1.14~ynh1", + "version": "1.1.16~ynh1", "url": "https://borgbackup.readthedocs.io", "license": "BSD-3-Clause", "maintainer": { @@ -17,7 +17,7 @@ "requirements": { "yunohost": ">= 3.8.1" }, - "multi_instance": false, + "multi_instance": true, "services": [], "arguments": { "install" : [ @@ -38,6 +38,25 @@ "fr": "Indiquez la clé publique donnée par l'app borg_ynh" } }, + { + "name": "alert_delay", + "type": "number", + "ask": { + "en": "After which delay in days should we alert if there are no changes on repo ?", + "fr": "Après quel délais en jours devons-nous lancer une alerte si il n'y a pas de changement dans le repo ?" + }, + "default": "1" + }, + { + "name": "alert_mails", + "type": "string", + "ask": { + "en": "Emails to whom send alerts ?", + "fr": "Emails des personnes à qui envoyer les alertes ?" + }, + "default": "root", + "example": "camille@example.com,eden@example.com" + }, { "name": "quota", "type": "string", diff --git a/scripts/_common.sh b/scripts/_common.sh index 9553a46..6a33ffa 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,18 +5,25 @@ #================================================= # App package root directory should be the parent folder PKG_DIR=$(cd ../; pwd) +BORG_VERSION=1.1.16 -pkg_dependencies="python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev python-jinja2 python3-setuptools python-virtualenv" +pkg_dependencies="python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev python3-jinja2 python3-setuptools python3-venv python-virtualenv virtualenv libfuse-dev pkg-config" # Install borg with pip if borg is not here install_borg_with_pip () { + if [ -d /opt/borg-env ]; then + /opt/borg-env/bin/python /opt/borg-env/bin/pip list | grep "Version: $BORG_VERSION" || ynh_secure_remove /opt/borg-env + fi if [ ! -d /opt/borg-env ]; then python3 -m venv /opt/borg-env - /opt/borg-env/bin/python /opt/borg-env/bin/pip install borgbackup==1.1.14 + /opt/borg-env/bin/python /opt/borg-env/bin/pip install wheel + /opt/borg-env/bin/python /opt/borg-env/bin/pip install borgbackup[fuse]==$BORG_VERSION echo "#!/bin/bash /opt/borg-env/bin/python /opt/borg-env/bin/borg \"\$@\"" > /usr/local/bin/borg - chmod a+x /usr/local/bin/borg + touch "/opt/borg-env/$(ynh_get_debian_release)" fi + # We need this to be executable by other borg apps + chmod a+x /usr/local/bin/borg } #================================================= @@ -46,15 +53,3 @@ ynh_save_args () { ynh_app_setting_set $app $setting_var "${!var}" done } - - - -ynh_configure () { - ynh_backup_if_checksum_is_different $2 - ynh_render_template "${PKG_DIR}/conf/$1.j2" $2 - ynh_store_file_checksum $2 -} - -ynh_read_json () { - python3 -c "import sys, json;print(json.load(open('$1'))['$2'])" -} diff --git a/scripts/backup b/scripts/backup index a50d340..4263664 100755 --- a/scripts/backup +++ b/scripts/backup @@ -18,5 +18,23 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME +export ssh_user="$(ynh_app_setting_get $app ssh_user)" + +#================================================= +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." +ynh_backup "/home/$ssh_user/.ssh" +ynh_backup "/home/$ssh_user/.nobackup" +ynh_backup "/etc/cron.d/$app" + +ynh_print_info --message="Borg backup repo in /home/$ssh_user/ won't be backup to avoid backup of backup loop issue." + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 10e81f7..9cade3c 100755 --- a/scripts/install +++ b/scripts/install @@ -23,7 +23,7 @@ ynh_abort_if_errors export app=$YNH_APP_INSTANCE_NAME # Retrieve arguments -ynh_export ssh_user public_key quota +ynh_export ssh_user public_key quota alert_delay alert_mails #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS @@ -35,7 +35,7 @@ ynh_system_user_exists --username=$ssh_user && ynh_die --message="This user alre # STORE SETTINGS FROM MANIFEST #================================================= -ynh_save_args ssh_user public_key quota +ynh_save_args ssh_user public_key quota alert_delay alert_mails #================================================= # INSTALL DEPENDENCIES @@ -48,16 +48,18 @@ install_borg_with_pip #================================================= # CREATE SSH USER USED BY BORG #================================================= -ynh_script_progression --message="Creat SSH user used by Borg..." +ynh_script_progression --message="Creating SSH user used by Borg..." adduser $ssh_user --quiet --gecos ",,," --shell /bin/bash --disabled-password #================================================= # AUTORIZE SSH FOR THIS USER #================================================= +ynh_script_progression --message="Configuring SSH public key for remote connexion..." home=/home/$ssh_user mkdir -p /home/$ssh_user/.ssh +chmod o=--- /home/$ssh_user touch /home/$ssh_user/.ssh/authorized_keys extra="--storage-quota $quota" if [ "$quota" = "" ]; then @@ -68,9 +70,16 @@ echo "command=\"borg serve $extra --restrict-to-repository /home/$ssh_user/backu #================================================= # AVOID BACKUP OF BACKUP #================================================= +ynh_script_progression --message="Avoiding to backup the backup itself..." 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" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index 4f5756e..4a4c3eb 100755 --- a/scripts/remove +++ b/scripts/remove @@ -23,12 +23,24 @@ ynh_script_progression --message="Removing dependencies..." ynh_remove_app_dependencies -#================================================= -# REMOVE FILES -#================================================= +# Remove borg if we are removing the last borg app on the system +if [ "$(yunohost app list | grep "id: borg" | wc -l)" == "1" ] ; then + ynh_secure_remove "/opt/borg-env" + ynh_secure_remove "/usr/local/bin/borg" +fi +#================================================= +# REMOVE USER BUT KEEP FILES +#================================================= +# We keep files cause we don't know what the user want to do about +# backups stored in the home directory userdel $ssh_user +#================================================= +# REMOVE CRON FILES +#================================================= +ynh_secure_remove "/etc/cron.d/$app" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index e94e027..382b029 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -26,12 +26,14 @@ ynh_check_app_version_changed # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # restore it if the upgrade fails - ynh_restore_upgradebackup -} +# 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 () { +# # restore it if the upgrade fails +# ynh_restore_upgradebackup +#} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -49,18 +51,48 @@ if [ -f "/etc/yunohost/hooks.d/backup/17-data_home" ]; then ynh_secure_remove /etc/yunohost/hooks.d/backup/17-data_home fi -if echo "$ssh_user" | grep -v ' '; then +if echo "$ssh_user" | grep -q ' '; then + ynh_app_setting_set --app=$app --key=ssh_user --value="$(grep "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIadutuK2" /home/*/.ssh/authorized_keys | grep borg | cut -d/ -f3)" +fi + +if echo "$public_key" | grep -q -v ' '; then ynh_app_setting_set --app=$app --key=public_key --value="$(grep -Po 'no-user-rc \K.*$' /home/$ssh_user/.ssh/authorized_keys)" fi +# Reinstall borg if debian change of major version +if [ ! -f "/opt/borg-env/$(ynh_get_debian_release)" ] ; then + ynh_secure_remove /opt/borg-env +fi + #================================================= -# INSTALL DEPENDENCIES +# UPGRADE DEPENDENCIES #================================================= ynh_script_progression --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# SPECIFIC UPGRADE +#================================================= +# Upgrade borgbackup +#================================================= +ynh_script_progression --message="Upgrading borgbackup..." --weight=1 + install_borg_with_pip +#================================================= +# AVOID BACKUP OF BACKUP +#================================================= +ynh_script_progression --message="Avoiding to backup the backup itself..." + +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" + #================================================= # END OF SCRIPT #================================================= From 51cf595323c822283727a60373c4a906c5598dc8 Mon Sep 17 00:00:00 2001 From: ljf Date: Thu, 8 Apr 2021 20:30:50 +0200 Subject: [PATCH 5/8] [fix] Add default value for new params --- scripts/upgrade | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index 382b029..e2f6989 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,6 +15,9 @@ source /usr/share/yunohost/helpers 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) #================================================= # CHECK IF AN UPGRADE IS NEEDED @@ -59,6 +62,12 @@ if echo "$public_key" | grep -q -v ' '; then ynh_app_setting_set --app=$app --key=public_key --value="$(grep -Po 'no-user-rc \K.*$' /home/$ssh_user/.ssh/authorized_keys)" fi +# Alert delay and alert mail missing +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 + # Reinstall borg if debian change of major version if [ ! -f "/opt/borg-env/$(ynh_get_debian_release)" ] ; then ynh_secure_remove /opt/borg-env From 490dffd52413b360c8890e7df229927feb894b8f Mon Sep 17 00:00:00 2001 From: ljf Date: Fri, 9 Apr 2021 12:36:47 +0200 Subject: [PATCH 6/8] [fix] Upgrade unknown var --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index e2f6989..54c5b50 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -94,7 +94,7 @@ install_borg_with_pip #================================================= ynh_script_progression --message="Avoiding to backup the backup itself..." -touch $home/.nobackup +touch /home/$ssh_user/.nobackup #================================================= # SETUP CRON From 116c4cda9c86e13af1caf60fdb619c501dbf140c Mon Sep 17 00:00:00 2001 From: ljf Date: Sat, 10 Apr 2021 11:35:53 +0200 Subject: [PATCH 7/8] [fix] Multi install CI test --- scripts/install | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 9cade3c..0f7bdeb 100755 --- a/scripts/install +++ b/scripts/install @@ -28,7 +28,11 @@ ynh_export ssh_user public_key quota alert_delay alert_mails #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= - +# 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 + ssh_user+="$YNH_APP_INSTANCE_NUMBER" +fi ynh_system_user_exists --username=$ssh_user && ynh_die --message="This user already exists" #================================================= From 81b537f6dc23b6da35cda66d6b4c78e80c8e8271 Mon Sep 17 00:00:00 2001 From: ljf Date: Sat, 10 Apr 2021 13:00:36 +0200 Subject: [PATCH 8/8] [fix] Lineter number args not regocgnize and doesn't exist in 3.8 --- manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 877c874..52f7cde 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Offer backup storage to a friend.", "fr": "Offrez un espace de stockage à un⋅e ami⋅e." }, - "version": "1.1.16~ynh1", + "version": "1.1.16~ynh2", "url": "https://borgbackup.readthedocs.io", "license": "BSD-3-Clause", "maintainer": { @@ -40,7 +40,7 @@ }, { "name": "alert_delay", - "type": "number", + "type": "string", "ask": { "en": "After which delay in days should we alert if there are no changes on repo ?", "fr": "Après quel délais en jours devons-nous lancer une alerte si il n'y a pas de changement dans le repo ?"