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"