diff --git a/check_process b/check_process index edbba5a..436a7f5 100644 --- a/check_process +++ b/check_process @@ -2,6 +2,7 @@ ; Manifest ssh_user="sam" public_key="ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" + datadir=/home/USER alert_delay=1 alert_mails="sam@domain.tld" quota="1G" diff --git a/manifest.json b/manifest.json index 710c48b..0388c8a 100644 --- a/manifest.json +++ b/manifest.json @@ -44,6 +44,15 @@ "fr": "Indiquez la clé publique donnée par l'app borg_ynh" } }, + { + "name": "datadir", + "type": "string", + "ask": { + "en": "Indicate the directory where create the user directory with the borg archive", + "fr": "Indiquez le dossier où créer le dossier utilisateur contenant l'archive borg" + }, + "default": "/home/__SSH_USER__" + }, { "name": "alert_delay", "type": "string", diff --git a/scripts/backup b/scripts/backup index 4263664..6ee6fd9 100755 --- a/scripts/backup +++ b/scripts/backup @@ -22,16 +22,17 @@ ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME export ssh_user="$(ynh_app_setting_get $app ssh_user)" +export datadir="$(ynh_app_setting_get $app datadir)" #================================================= # 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 "$datadir/.ssh" +ynh_backup "$datadir/.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." +ynh_print_info --message="Borg backup repo in $datadir/ won't be backup to avoid backup of backup loop issue." #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index a7c29c3..45675cc 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 alert_delay alert_mails +ynh_export ssh_user public_key quota datadir alert_delay alert_mails #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS @@ -35,11 +35,21 @@ if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] ; then fi ynh_system_user_exists --username=$ssh_user && ynh_die --message="This user already exists" +datadir=$(echo "$datadir" | sed "s/__SSH_USER__/$ssh_user/" | sed "s/__APP__/$app/") +if [[ -z "$datadir" ]]; then + datadir=/home/$ssh_user +fi + +if ! _acceptable_path_to_delete "$datadir"; then + ynh_die --message="This path can't be used as home dir for the ssh_user" +fi + + #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_save_args ssh_user public_key quota alert_delay alert_mails +ynh_save_args ssh_user public_key quota alert_delay alert_mails datadir #================================================= # INSTALL DEPENDENCIES @@ -54,30 +64,29 @@ 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 +ynh_system_user_create --username=$ssh_user --home_dir=$datadir --use_shell --groups ssh.app #================================================= # 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 -chown -R $ssh_user:$ssh_user /home/$ssh_user -touch /home/$ssh_user/.ssh/authorized_keys +mkdir -p $datadir/.ssh +chmod o=--- $datadir +chown -R $ssh_user:$ssh_user $datadir +touch $datadir/.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 +echo "command=\"borg serve $extra --restrict-to-repository $datadir/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> $datadir/.ssh/authorized_keys #================================================= # AVOID BACKUP OF BACKUP #================================================= ynh_script_progression --message="Avoiding to backup the backup itself..." -touch $home/.nobackup +touch $datadir/.nobackup #================================================= # SETUP CRON diff --git a/scripts/remove b/scripts/remove index bb5bf94..8f14df3 100755 --- a/scripts/remove +++ b/scripts/remove @@ -15,6 +15,7 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME ssh_user=$(ynh_app_setting_get $app ssh_user) +datadir=$(ynh_app_setting_get $app ssh_user) #================================================= # REMOVE DEPENDENCIES @@ -36,6 +37,17 @@ fi # backups stored in the home directory ynh_system_user_delete --username=$ssh_user +#================================================= +# REMOVE DATA DIR +#================================================= + +# Remove the data directory if --purge option is used +if [ "${YNH_APP_PURGE:-0}" -eq 1 ] +then + ynh_script_progression --message="Removing app data directory..." --weight=1 + ynh_secure_remove --file="$datadir" +fi + #================================================= # REMOVE CRON FILES #================================================= diff --git a/scripts/restore b/scripts/restore index 410547b..0fe7b26 100755 --- a/scripts/restore +++ b/scripts/restore @@ -25,6 +25,7 @@ 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) +export datadir=$(ynh_app_setting_get $app datadir) #================================================= # INSTALL DEPENDENCIES @@ -45,22 +46,21 @@ ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_she # 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 $datadir/.ssh +chmod o=--- $datadir +chown -R $ssh_user:$ssh_user $datadir +touch $datadir/.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 +echo "command=\"borg serve $extra --restrict-to-repository $datadir/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> $datadir/.ssh/authorized_keys #================================================= # AVOID BACKUP OF BACKUP #================================================= -touch $home/.nobackup +touch $datadir/.nobackup ynh_restore #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 9454993..3a9ea4c 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -16,6 +16,7 @@ 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) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) alert_delay=$(ynh_app_setting_get --app=$app --key=alert_delay) alert_mails=$(ynh_app_setting_get --app=$app --key=alert_mails) @@ -77,12 +78,17 @@ if [ ! -f "/opt/borg-env/$(ynh_get_debian_release)" ] ; then ynh_secure_remove /opt/borg-env fi +if [ -z "$datadir" ]; +then + datadir="/home/${ssh_user}" + ynh_app_setting_set --app=$app --key=datadir --value=$datadir +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 +ynh_system_user_create --username=$ssh_user --home_dir=$datadir --use_shell --groups ssh.app #================================================= # UPGRADE DEPENDENCIES @@ -105,16 +111,16 @@ install_borg_with_pip #================================================= ynh_script_progression --message="Seting good permissions..." -mkdir -p /home/$ssh_user/.ssh -chmod o=--- /home/$ssh_user -chown -R $ssh_user:$ssh_user /home/$ssh_user +mkdir -p $datadir/.ssh +chmod o=--- $datadir +chown -R $ssh_user:$ssh_user $datadir #================================================= # AVOID BACKUP OF BACKUP #================================================= ynh_script_progression --message="Avoiding to backup the backup itself..." -touch /home/$ssh_user/.nobackup +touch $datadir/.nobackup #================================================= # SETUP CRON