2018-06-14 02:13:59 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
2023-10-25 21:45:35 +02:00
|
|
|
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
|
|
|
|
#REMOVEME? ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user)
|
|
|
|
#REMOVEME? public_key=$(ynh_app_setting_get --app=$app --key=public_key)
|
|
|
|
#REMOVEME? alert_delay=$(ynh_app_setting_get --app=$app --key=alert_delay)
|
|
|
|
#REMOVEME? alert_mails=$(ynh_app_setting_get --app=$app --key=alert_mails)
|
|
|
|
#REMOVEME? quota=$(ynh_app_setting_get --app=$app --key=quota)
|
2018-06-14 02:13:59 +02:00
|
|
|
|
2018-08-31 01:11:12 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF AN UPGRADE IS NEEDED
|
|
|
|
#=================================================
|
2021-01-11 00:36:16 +01:00
|
|
|
|
2018-08-31 01:11:12 +02:00
|
|
|
ynh_check_app_version_changed
|
|
|
|
|
2018-06-14 02:13:59 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
|
2021-04-08 20:20:10 +02:00
|
|
|
# We don't backup before upgrade cause we don't want accidental
|
|
|
|
# remove of repo if upgrade failed
|
|
|
|
|
2023-10-25 21:45:35 +02:00
|
|
|
#REMOVEME? #ynh_backup_before_upgrade
|
|
|
|
#REMOVEME? #ynh_clean_setup () {
|
2021-04-08 20:20:10 +02:00
|
|
|
# # restore it if the upgrade fails
|
2023-10-25 21:45:35 +02:00
|
|
|
#REMOVEME? # ynh_restore_upgradebackup
|
2021-04-08 20:20:10 +02:00
|
|
|
#}
|
2018-06-14 02:13:59 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
2023-10-25 21:45:35 +02:00
|
|
|
#REMOVEME? ynh_abort_if_errors
|
2018-06-14 02:13:59 +02:00
|
|
|
|
2020-02-27 18:22:07 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
|
|
|
|
if [ -f "/etc/apt/sources.list.d/$app-stretch-backports.list" ]; then
|
|
|
|
rm -f /etc/apt/sources.list.d/$app-stretch-backports.list
|
|
|
|
install_borg_with_pip
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "/etc/yunohost/hooks.d/backup/17-data_home" ]; then
|
|
|
|
ynh_secure_remove /etc/yunohost/hooks.d/backup/17-data_home
|
|
|
|
fi
|
|
|
|
|
2021-04-11 18:44:28 +02:00
|
|
|
# Fix broken value ssh_user that mistakenly got replaced by the public key in previous versions...
|
2021-04-11 19:25:54 +02:00
|
|
|
[ -n "$ssh_user" ] || ynh_die "Unable to retrieve ssh_user please fix /etc/yunohost/apps/$app/settings.yml manually :( !"
|
2021-04-08 20:20:10 +02:00
|
|
|
if echo "$ssh_user" | grep -q ' '; then
|
2021-04-11 19:09:49 +02:00
|
|
|
ssh_user=$(grep "$ssh_user" /home/*/.ssh/authorized_keys | grep borg | cut -d/ -f3)
|
2021-04-11 19:15:16 +02:00
|
|
|
[ -n "$ssh_user" ] || ynh_die "Unable to retrieve ssh_user please fix /etc/yunohost/apps/$app/settings.yml manually :( !"
|
2021-04-11 18:44:28 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=ssh_user --value="$ssh_user"
|
2021-04-08 20:20:10 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if echo "$public_key" | grep -q -v ' '; then
|
2021-04-07 03:52:14 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=public_key --value="$(grep -Po 'no-user-rc \K.*$' /home/$ssh_user/.ssh/authorized_keys)"
|
2020-02-27 18:22:07 +01:00
|
|
|
fi
|
2021-01-11 00:36:16 +01:00
|
|
|
|
2021-04-08 20:30:50 +02:00
|
|
|
# Alert delay and alert mail missing
|
|
|
|
if [ -z "$alert_delay" ]; then
|
|
|
|
ynh_app_setting_set --app=$app --key=alert_delay --value=1
|
|
|
|
ynh_app_setting_set --app=$app --key=alert_mails --value="root"
|
|
|
|
fi
|
|
|
|
|
2021-04-08 20:20:10 +02:00
|
|
|
# Reinstall borg if debian change of major version
|
|
|
|
if [ ! -f "/opt/borg-env/$(ynh_get_debian_release)" ] ; then
|
|
|
|
ynh_secure_remove /opt/borg-env
|
|
|
|
fi
|
|
|
|
|
2021-05-07 19:24:28 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE SSH USER USED BY BORG
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Creating SSH user used by Borg..."
|
|
|
|
|
2023-10-25 21:45:35 +02:00
|
|
|
#REMOVEME? ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app
|
2021-05-07 19:24:28 +02:00
|
|
|
|
2021-01-11 00:36:16 +01:00
|
|
|
#=================================================
|
2021-04-08 20:20:10 +02:00
|
|
|
# UPGRADE DEPENDENCIES
|
2021-01-11 00:36:16 +01:00
|
|
|
#=================================================
|
2023-10-25 21:45:35 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..."
|
2021-01-11 00:36:16 +01:00
|
|
|
|
2023-10-25 21:45:35 +02:00
|
|
|
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
|
2021-04-08 20:20:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# Upgrade borgbackup
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading borgbackup..." --weight=1
|
|
|
|
|
2021-01-11 00:36:16 +01:00
|
|
|
install_borg_with_pip
|
|
|
|
|
2021-07-13 13:44:06 +02:00
|
|
|
#=================================================
|
|
|
|
# AUTORIZE SSH FOR THIS USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Seting good permissions..."
|
|
|
|
|
|
|
|
mkdir -p /home/$ssh_user/.ssh
|
|
|
|
chmod o=--- /home/$ssh_user
|
2022-10-27 04:21:32 +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
|
2021-07-13 13:44:06 +02:00
|
|
|
chown -R $ssh_user:$ssh_user /home/$ssh_user
|
|
|
|
|
2021-04-08 20:20:10 +02:00
|
|
|
#=================================================
|
|
|
|
# AVOID BACKUP OF BACKUP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Avoiding to backup the backup itself..."
|
|
|
|
|
2021-04-09 12:36:47 +02:00
|
|
|
touch /home/$ssh_user/.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="Upgrade of $app completed" --last
|