mirror of
https://github.com/YunoHost-Apps/borgserver_ynh.git
synced 2024-09-03 20:36:20 +02:00
101 lines
3.4 KiB
Bash
Executable file
101 lines
3.4 KiB
Bash
Executable file
#!/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
|
|
#=================================================
|
|
|
|
export app=$YNH_APP_INSTANCE_NAME
|
|
|
|
# Retrieve arguments
|
|
ynh_export ssh_user public_key quota datadir alert_delay alert_mails
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
|
#=================================================
|
|
# Here is a small hack to avoid multi install CI test to fail due
|
|
# to same ssh_user provided
|
|
if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] ; then
|
|
ssh_user+="$YNH_APP_INSTANCE_NUMBER"
|
|
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 datadir
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Installing dependencies..."
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
install_borg_with_pip
|
|
|
|
#=================================================
|
|
# 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=$datadir --use_shell --groups ssh.app
|
|
|
|
#=================================================
|
|
# AUTORIZE SSH FOR THIS USER
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring SSH public key for remote connexion..."
|
|
|
|
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 $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 $datadir/.nobackup
|
|
|
|
#=================================================
|
|
# SETUP CRON
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring cron to monitor backup..."
|
|
ynh_add_config --template="monitor-backup" --destination="/etc/cron.d/$app"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|