2018-06-14 02:13:59 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2020-02-27 18:22:07 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
|
2024-08-12 13:03:41 +02:00
|
|
|
# Remove legacy stuff
|
2020-02-27 18:22:07 +01:00
|
|
|
if [ -f "/etc/apt/sources.list.d/$app-stretch-backports.list" ]; then
|
2024-08-12 13:03:41 +02:00
|
|
|
ynh_secure_remove "/etc/apt/sources.list.d/$app-stretch-backports.list"
|
2020-02-27 18:22:07 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "/etc/yunohost/hooks.d/backup/17-data_home" ]; then
|
2024-08-12 13:03:41 +02:00
|
|
|
ynh_secure_remove "/etc/yunohost/hooks.d/backup/17-data_home"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Clear legacy stuff
|
|
|
|
if [ -d /opt/borg-env ]; then
|
|
|
|
ynh_secure_remove --file="/opt/borg-env"
|
|
|
|
ynh_secure_remove --file="/usr/local/bin/borg"
|
|
|
|
ynh_secure_remove --file="/usr/local/bin/backup-with-borg"
|
2020-02-27 18:22:07 +01:00
|
|
|
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...
|
2023-12-04 20:31:10 +01: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 :( !"
|
2024-08-12 13:03:41 +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
|
2024-08-12 13:03:41 +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
|
2023-12-04 20:31:10 +01:00
|
|
|
if [ -z "${alert_delay:-}" ]; then
|
2024-08-12 13:03:41 +02:00
|
|
|
ynh_app_setting_set --app="$app" --key=alert_delay --value="1"
|
|
|
|
ynh_app_setting_set --app="$app" --key=alert_mails --value="root"
|
2021-04-08 20:30:50 +02:00
|
|
|
fi
|
|
|
|
|
2021-04-08 20:20:10 +02:00
|
|
|
#=================================================
|
2024-08-12 13:03:41 +02:00
|
|
|
# UPGRADE BORG
|
2021-04-08 20:20:10 +02:00
|
|
|
#=================================================
|
2024-08-12 13:03:41 +02:00
|
|
|
ynh_script_progression --message="Upgrading Borg..." --weight=1
|
2021-04-08 20:20:10 +02:00
|
|
|
|
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
|
|
|
|
#=================================================
|
2023-12-04 20:31:10 +01:00
|
|
|
ynh_script_progression --message="Making sure SSH user exists with appropriate permissions..."
|
2021-07-13 13:44:06 +02:00
|
|
|
|
2024-08-12 13:03:41 +02:00
|
|
|
ynh_system_user_create --username="$ssh_user" --home_dir="/home/$ssh_user" --use_shell --groups ssh.app
|
2024-08-12 13:35:02 +02:00
|
|
|
mkdir -p "/home/$ssh_user"
|
|
|
|
chmod 700 "/home/$ssh_user"
|
|
|
|
chown "$ssh_user" "/home/$ssh_user"
|
2021-04-08 20:20:10 +02:00
|
|
|
|
2023-12-04 20:31:10 +01:00
|
|
|
# Tweak to prevent the backup of the backup itself
|
2024-08-12 13:03:41 +02:00
|
|
|
touch "/home/$ssh_user/.nobackup"
|
|
|
|
|
|
|
|
create_ssh_config "/home/$ssh_user/.ssh" "/home/$ssh_user/backup"
|
2021-04-08 20:20:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP CRON
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring cron to monitor backup..."
|
2023-10-25 21:57:09 +02:00
|
|
|
|
2024-08-12 13:03:41 +02:00
|
|
|
ynh_add_config --template="monitor-backup.cron" --destination="/etc/cron.d/$app"
|
|
|
|
ynh_add_config --template="monitor-backup.sh" --destination="$install_dir/monitor-backup.sh"
|
|
|
|
chmod +x "$install_dir/monitor-backup.sh"
|
2021-04-08 20:20:10 +02:00
|
|
|
|
2021-01-11 00:36:16 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|