2018-06-14 02:13:59 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
2021-01-11 00:36:16 +01:00
|
|
|
export app=$YNH_APP_INSTANCE_NAME
|
2020-02-27 17:49:59 +01:00
|
|
|
|
2018-06-14 02:13:59 +02:00
|
|
|
# Retrieve arguments
|
2021-04-08 20:20:10 +02:00
|
|
|
ynh_export ssh_user public_key quota alert_delay alert_mails
|
2018-06-14 02:13:59 +02:00
|
|
|
|
2020-02-27 17:49:59 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
|
|
|
#=================================================
|
2021-04-10 11:35:53 +02:00
|
|
|
# Here is a small hack to avoid multi install CI test to fail due
|
|
|
|
# to same ssh_user provided
|
2021-04-14 13:01:48 +02:00
|
|
|
if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] ; then
|
2021-04-10 11:35:53 +02:00
|
|
|
ssh_user+="$YNH_APP_INSTANCE_NUMBER"
|
|
|
|
fi
|
2020-02-27 18:55:40 +01:00
|
|
|
ynh_system_user_exists --username=$ssh_user && ynh_die --message="This user already exists"
|
2020-02-27 17:49:59 +01:00
|
|
|
|
2018-06-14 02:13:59 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2021-01-11 00:36:16 +01:00
|
|
|
|
2021-04-08 20:20:10 +02:00
|
|
|
ynh_save_args ssh_user public_key quota alert_delay alert_mails
|
2018-06-14 02:13:59 +02:00
|
|
|
|
2018-08-31 01:11:12 +02:00
|
|
|
#=================================================
|
2019-05-21 16:48:54 +02:00
|
|
|
# INSTALL DEPENDENCIES
|
2018-06-14 02:13:59 +02:00
|
|
|
#=================================================
|
2021-01-11 00:36:16 +01:00
|
|
|
ynh_script_progression --message="Installing 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-04-08 20:20:10 +02:00
|
|
|
ynh_script_progression --message="Creating SSH user used by Borg..."
|
2021-01-11 00:36:16 +01:00
|
|
|
|
2018-06-21 15:38:59 +02:00
|
|
|
adduser $ssh_user --quiet --gecos ",,," --shell /bin/bash --disabled-password
|
2018-06-14 02:13:59 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# AUTORIZE SSH FOR THIS USER
|
|
|
|
#=================================================
|
2021-04-08 20:20:10 +02:00
|
|
|
ynh_script_progression --message="Configuring SSH public key for remote connexion..."
|
2021-01-11 00:36:16 +01:00
|
|
|
|
2018-06-14 02:13:59 +02:00
|
|
|
home=/home/$ssh_user
|
|
|
|
mkdir -p /home/$ssh_user/.ssh
|
2021-04-08 20:20:10 +02:00
|
|
|
chmod o=--- /home/$ssh_user
|
2018-06-14 02:13:59 +02:00
|
|
|
touch /home/$ssh_user/.ssh/authorized_keys
|
2018-06-21 17:08:18 +02:00
|
|
|
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
|
2018-06-14 02:13:59 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# AVOID BACKUP OF BACKUP
|
|
|
|
#=================================================
|
2021-04-08 20:20:10 +02:00
|
|
|
ynh_script_progression --message="Avoiding to backup the backup itself..."
|
2021-01-11 00:36:16 +01:00
|
|
|
|
2018-06-14 02:13:59 +02:00
|
|
|
touch $home/.nobackup
|
|
|
|
|
2021-04-08 20:20:10 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP CRON
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring cron to monitor backup..."
|
|
|
|
ynh_add_config --template="monitor-backup" --destination="/etc/cron.d/$app"
|
|
|
|
|
2021-01-11 00:36:16 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|