diff --git a/README.md b/README.md
index 489e494..fa8d128 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ It shall NOT be edited by hand.
# Borg Server for YunoHost
-[](https://dash.yunohost.org/appci/app/borgserver)  
+[](https://dash.yunohost.org/appci/app/borgserver)  
[](https://install-app.yunohost.org/?app=borgserver)
*[Lire ce readme en français.](./README_fr.md)*
@@ -21,26 +21,24 @@ The main goal of Borg is to provide an efficient and secure way to backup data.
**Shipped version:** 1.1.16~ynh9
-
-
-
## Documentation and resources
-* Official app website: https://www.borgbackup.org/
-* Official admin documentation: https://borgbackup.readthedocs.io/en/stable/
-* Upstream app code repository: https://github.com/borgbackup/borg
-* YunoHost documentation for this app: https://yunohost.org/app_borgserver
-* Report a bug: https://github.com/YunoHost-Apps/borgserver_ynh/issues
+* Official app website:
+* Official admin documentation:
+* Upstream app code repository:
+* YunoHost documentation for this app:
+* Report a bug:
## 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.
-```
+
+``` bash
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
```
-**More info regarding app packaging:** https://yunohost.org/packaging_apps
\ No newline at end of file
+**More info regarding app packaging:**
diff --git a/README_fr.md b/README_fr.md
index 89269cd..9c3b678 100644
--- a/README_fr.md
+++ b/README_fr.md
@@ -1,10 +1,14 @@
+
+
# Borg Server pour YunoHost
-[](https://dash.yunohost.org/appci/app/borgserver)  
+[](https://dash.yunohost.org/appci/app/borgserver)  
[](https://install-app.yunohost.org/?app=borgserver)
*[Read this readme in english.](./README.md)*
-*[Lire ce readme en français.](./README_fr.md)*
> *Ce package vous permet d'installer Borg Server rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.*
@@ -17,26 +21,24 @@ The main goal of Borg is to provide an efficient and secure way to backup data.
**Version incluse :** 1.1.16~ynh9
-
-
-
## Documentations et ressources
-* Site officiel de l'app : https://www.borgbackup.org/
-* Documentation officielle de l'admin : https://borgbackup.readthedocs.io/en/stable/
-* Dépôt de code officiel de l'app : https://github.com/borgbackup/borg
-* Documentation YunoHost pour cette app : https://yunohost.org/app_borgserver
-* Signaler un bug : https://github.com/YunoHost-Apps/borgserver_ynh/issues
+* 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
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing).
Pour essayer la branche testing, procédez comme suit.
-```
+
+``` bash
sudo yunohost app install https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing --debug
ou
sudo yunohost app upgrade borgserver -u https://github.com/YunoHost-Apps/borgserver_ynh/tree/testing --debug
```
-**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps
\ No newline at end of file
+**Plus d'infos sur le packaging d'applications :**
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/conf/monitor-backup b/conf/monitor-backup
index 7ecc10b..dedb486 100644
--- a/conf/monitor-backup
+++ b/conf/monitor-backup
@@ -1,2 +1,2 @@
SHELL=/bin/bash
-0 9,20 * * * root : Monitor __SSH_USER__ backup ; ALERT_DELAY="$(grep '^alert_delay: ' /etc/yunohost/apps/__APP__/settings.yml | awk -F\' '{print $2}')"; [[ $(find /home/__SSH_USER__/backup/data -follow -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__" $(grep '^alert_mails: ' /etc/yunohost/apps/__APP__/settings.yml | awk '{print $2}'))
+0 9,20 * * * root : Monitor __SSH_USER__ backup ; ALERT_DELAY="$(grep '^alert_delay: ' /etc/yunohost/apps/__APP__/settings.yml | awk -F\' '{print $2}')"; [[ $(find __DATADIR__/backup/data -follow -mtime -${ALERT_DELAY} -ls | wc -l) > 0 ]] || ( echo "No file has been backuped in __DATADIR__ since ${ALERT_DELAY} days" | mail -s "[YNH] Backup missing : __SSH_USER__" $(grep '^alert_mails: ' /etc/yunohost/apps/__APP__/settings.yml | awk '{print $2}'))
diff --git a/manifest.json b/manifest.json
index 710c48b..9c86660 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 path of the ssh user home directory where create the borg archive",
+ "fr": "Indiquez le chemin du dossier de l'utilisateur ssh où créer 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..e46e16d 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