2018-06-14 02:13:59 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2019-06-10 18:49:15 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
2018-06-14 02:13:59 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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)
|
2018-06-21 17:08:18 +02:00
|
|
|
export quota=$(ynh_app_setting_get $app quota)
|
2022-09-30 01:16:55 +02:00
|
|
|
export datadir=$(ynh_app_setting_get $app datadir)
|
2018-06-14 02:13:59 +02:00
|
|
|
|
2018-08-31 01:11:12 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
2018-06-14 02:13:59 +02:00
|
|
|
#=================================================
|
2021-01-11 00:36:16 +01:00
|
|
|
ynh_script_progression --message="Reinstalling dependencies..."
|
|
|
|
|
2018-06-14 02:13:59 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2019-05-21 17:05:24 +02:00
|
|
|
install_borg_with_pip
|
2018-06-14 02:13:59 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE SSH USER USED BY BORG
|
|
|
|
#=================================================
|
2021-05-07 19:24:28 +02:00
|
|
|
ynh_script_progression --message="Creating SSH user used by Borg..."
|
2021-01-11 00:36:16 +01:00
|
|
|
|
2021-05-07 19:24:28 +02:00
|
|
|
ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app
|
2018-06-14 02:13:59 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# AUTORIZE SSH FOR THIS USER
|
|
|
|
#=================================================
|
2021-01-11 00:36:16 +01:00
|
|
|
|
2022-09-30 01:16:55 +02:00
|
|
|
mkdir -p $datadir/.ssh
|
|
|
|
chmod o=--- $datadir
|
|
|
|
chown -R $ssh_user:$ssh_user $datadir
|
|
|
|
touch $datadir/.ssh/authorized_keys
|
2018-06-21 17:08:18 +02:00
|
|
|
extra="--storage-quota $quota"
|
|
|
|
if [ "$quota" = "" ]; then
|
|
|
|
extra=""
|
|
|
|
fi
|
2022-09-30 01:16:55 +02:00
|
|
|
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
|
2018-06-14 02:13:59 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# AVOID BACKUP OF BACKUP
|
|
|
|
#=================================================
|
2021-01-11 00:36:16 +01:00
|
|
|
|
2022-09-30 01:16:55 +02:00
|
|
|
touch $datadir/.nobackup
|
2018-11-29 00:08:47 +01:00
|
|
|
ynh_restore
|
2018-06-14 02:13:59 +02:00
|
|
|
|
2021-01-11 00:36:16 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|