mirror of
https://github.com/YunoHost-Apps/borgserver_ynh.git
synced 2024-09-03 20:36:20 +02:00
Allow to choose in which directory create the dir
This commit is contained in:
parent
3efeed0e87
commit
9f95ae0fb5
7 changed files with 63 additions and 25 deletions
|
@ -2,6 +2,7 @@
|
||||||
; Manifest
|
; Manifest
|
||||||
ssh_user="sam"
|
ssh_user="sam"
|
||||||
public_key="ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
|
public_key="ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
|
||||||
|
datadir=/home/USER
|
||||||
alert_delay=1
|
alert_delay=1
|
||||||
alert_mails="sam@domain.tld"
|
alert_mails="sam@domain.tld"
|
||||||
quota="1G"
|
quota="1G"
|
||||||
|
|
|
@ -44,6 +44,15 @@
|
||||||
"fr": "Indiquez la clé publique donnée par l'app borg_ynh"
|
"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",
|
"name": "alert_delay",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|
|
@ -22,16 +22,17 @@ ynh_print_info --message="Loading installation settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
export ssh_user="$(ynh_app_setting_get $app ssh_user)"
|
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
|
# DECLARE DATA AND CONF FILES TO BACKUP
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Declaring files to be backed up..."
|
ynh_print_info --message="Declaring files to be backed up..."
|
||||||
ynh_backup "/home/$ssh_user/.ssh"
|
ynh_backup "$datadir/.ssh"
|
||||||
ynh_backup "/home/$ssh_user/.nobackup"
|
ynh_backup "$datadir/.nobackup"
|
||||||
ynh_backup "/etc/cron.d/$app"
|
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
|
# END OF SCRIPT
|
||||||
|
|
|
@ -23,7 +23,7 @@ ynh_abort_if_errors
|
||||||
export app=$YNH_APP_INSTANCE_NAME
|
export app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
# 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
|
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
||||||
|
@ -35,11 +35,21 @@ if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] ; then
|
||||||
fi
|
fi
|
||||||
ynh_system_user_exists --username=$ssh_user && ynh_die --message="This user already exists"
|
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
|
# 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
|
# INSTALL DEPENDENCIES
|
||||||
|
@ -54,30 +64,29 @@ install_borg_with_pip
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Creating 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
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# AUTORIZE SSH FOR THIS USER
|
# AUTORIZE SSH FOR THIS USER
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring SSH public key for remote connexion..."
|
ynh_script_progression --message="Configuring SSH public key for remote connexion..."
|
||||||
|
|
||||||
home=/home/$ssh_user
|
mkdir -p $datadir/.ssh
|
||||||
mkdir -p /home/$ssh_user/.ssh
|
chmod o=--- $datadir
|
||||||
chmod o=--- /home/$ssh_user
|
chown -R $ssh_user:$ssh_user $datadir
|
||||||
chown -R $ssh_user:$ssh_user /home/$ssh_user
|
touch $datadir/.ssh/authorized_keys
|
||||||
touch /home/$ssh_user/.ssh/authorized_keys
|
|
||||||
extra="--storage-quota $quota"
|
extra="--storage-quota $quota"
|
||||||
if [ "$quota" = "" ]; then
|
if [ "$quota" = "" ]; then
|
||||||
extra=""
|
extra=""
|
||||||
fi
|
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
|
# AVOID BACKUP OF BACKUP
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Avoiding to backup the backup itself..."
|
ynh_script_progression --message="Avoiding to backup the backup itself..."
|
||||||
|
|
||||||
touch $home/.nobackup
|
touch $datadir/.nobackup
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP CRON
|
# SETUP CRON
|
||||||
|
|
|
@ -15,6 +15,7 @@ source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
ssh_user=$(ynh_app_setting_get $app ssh_user)
|
ssh_user=$(ynh_app_setting_get $app ssh_user)
|
||||||
|
datadir=$(ynh_app_setting_get $app ssh_user)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE DEPENDENCIES
|
# REMOVE DEPENDENCIES
|
||||||
|
@ -36,6 +37,17 @@ fi
|
||||||
# backups stored in the home directory
|
# backups stored in the home directory
|
||||||
ynh_system_user_delete --username=$ssh_user
|
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
|
# REMOVE CRON FILES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -25,6 +25,7 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
export ssh_user=$(ynh_app_setting_get $app ssh_user)
|
export ssh_user=$(ynh_app_setting_get $app ssh_user)
|
||||||
export public_key=$(ynh_app_setting_get $app public_key)
|
export public_key=$(ynh_app_setting_get $app public_key)
|
||||||
export quota=$(ynh_app_setting_get $app quota)
|
export quota=$(ynh_app_setting_get $app quota)
|
||||||
|
export datadir=$(ynh_app_setting_get $app datadir)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL DEPENDENCIES
|
# 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
|
# AUTORIZE SSH FOR THIS USER
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
home=/home/$ssh_user
|
mkdir -p $datadir/.ssh
|
||||||
mkdir -p /home/$ssh_user/.ssh
|
chmod o=--- $datadir
|
||||||
chmod o=--- /home/$ssh_user
|
chown -R $ssh_user:$ssh_user $datadir
|
||||||
chown -R $ssh_user:$ssh_user /home/$ssh_user
|
touch $datadir/.ssh/authorized_keys
|
||||||
touch /home/$ssh_user/.ssh/authorized_keys
|
|
||||||
extra="--storage-quota $quota"
|
extra="--storage-quota $quota"
|
||||||
if [ "$quota" = "" ]; then
|
if [ "$quota" = "" ]; then
|
||||||
extra=""
|
extra=""
|
||||||
fi
|
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
|
# AVOID BACKUP OF BACKUP
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
touch $home/.nobackup
|
touch $datadir/.nobackup
|
||||||
ynh_restore
|
ynh_restore
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -16,6 +16,7 @@ source /usr/share/yunohost/helpers
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user)
|
ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user)
|
||||||
public_key=$(ynh_app_setting_get --app=$app --key=public_key)
|
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_delay=$(ynh_app_setting_get --app=$app --key=alert_delay)
|
||||||
alert_mails=$(ynh_app_setting_get --app=$app --key=alert_mails)
|
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
|
ynh_secure_remove /opt/borg-env
|
||||||
fi
|
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
|
# CREATE SSH USER USED BY BORG
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Creating 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
|
# UPGRADE DEPENDENCIES
|
||||||
|
@ -105,16 +111,16 @@ install_borg_with_pip
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Seting good permissions..."
|
ynh_script_progression --message="Seting good permissions..."
|
||||||
|
|
||||||
mkdir -p /home/$ssh_user/.ssh
|
mkdir -p $datadir/.ssh
|
||||||
chmod o=--- /home/$ssh_user
|
chmod o=--- $datadir
|
||||||
chown -R $ssh_user:$ssh_user /home/$ssh_user
|
chown -R $ssh_user:$ssh_user $datadir
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# AVOID BACKUP OF BACKUP
|
# AVOID BACKUP OF BACKUP
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Avoiding to backup the backup itself..."
|
ynh_script_progression --message="Avoiding to backup the backup itself..."
|
||||||
|
|
||||||
touch /home/$ssh_user/.nobackup
|
touch $datadir/.nobackup
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP CRON
|
# SETUP CRON
|
||||||
|
|
Loading…
Reference in a new issue