1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/restic_ynh.git synced 2024-09-03 20:16:22 +02:00
restic_ynh/scripts/upgrade

126 lines
4.9 KiB
Text
Raw Normal View History

#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
2024-05-25 09:34:34 +02:00
# STOP SYSTEMD SERVICE
#=================================================
2024-05-25 09:34:34 +02:00
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
2024-05-26 12:55:09 +02:00
if grep "${app}.timer" /etc/yunohost/services.yml > /dev/null ; then
yunohost service remove $app.timer
ynh_systemd_action --service="$app" --action="stop"
ynh_systemd_action --service="$app.timer" --action="disable"
fi
#=================================================
2024-05-25 09:34:34 +02:00
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2024-05-26 15:24:04 +02:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if [ -f "/usr/local/bin/backup-with-${app}" ]; then
ynh_secure_remove --file="/usr/local/bin/backup-with-${app}"
fi
if [ -d "/opt/yunohost/$app" ]; then
2024-05-26 15:31:15 +02:00
mv "/opt/yunohost/$app/"* "$install_dir"
2024-05-26 15:24:04 +02:00
ynh_secure_remove --file="/opt/yunohost/$app/check-restic"
ynh_secure_remove --file="/opt/yunohost/$app/check_method_restic"
ynh_secure_remove --file="/opt/yunohost/$app/restic_check_log_restic"
ynh_secure_remove --file="/opt/yunohost/$app/restic_log_restic"
ynh_secure_remove --file="/opt/yunohost/$app/"
fi
2024-05-25 09:34:34 +02:00
2024-05-26 12:55:09 +02:00
# old versions did not have delimiters in ~/.ssh/config making removal in
# multi-instance cases break the remaining instances.
# So we need to add the delimiters if they are missing
# The config will be re-added afterwards
2024-05-26 13:26:43 +02:00
if ! grep -q "begin ${app}" /root/.ssh/config; then
2024-05-26 12:55:09 +02:00
# did not find delimiters so removing old configuration
2024-05-26 13:26:43 +02:00
sed -e "/Host ${server}/,+6d" "/root/.ssh/config" -i || true
fi
#=================================================
2020-04-12 17:13:11 +02:00
# INSTALL RESTIC
#=================================================
2024-05-26 12:55:09 +02:00
ynh_script_progression --message="Installing Restic..." --weight=7
2023-01-16 19:29:00 +01:00
2024-05-25 22:20:53 +02:00
ynh_setup_source --source_id=main --dest_dir="$install_dir"
chmod +x "$install_dir/restic"
2020-11-14 18:03:13 +01:00
2024-05-26 12:55:09 +02:00
# This function will only create it if required
_gen_and_save_public_key
2024-05-26 12:55:09 +02:00
# Set ssh config if it is missing
if ! grep -q "begin $app" "/root/.ssh/config"; then
_set_ssh_config
fi
2020-11-14 18:03:13 +01:00
#=================================================
2024-05-26 12:55:09 +02:00
# SETUP THE BACKUP METHOD
2020-11-14 18:03:13 +01:00
#=================================================
2024-05-26 12:55:09 +02:00
ynh_script_progression --message="Setting up backup method..." --weight=1
2023-01-16 19:29:00 +01:00
2024-05-26 12:55:09 +02:00
mkdir -p /etc/yunohost/hooks.d/backup
mkdir -p /etc/yunohost/hooks.d/backup_method
mkdir -p /usr/share/yunohost/backup_method
2020-11-14 18:03:13 +01:00
2024-05-26 12:55:09 +02:00
## Backup method
_ynh_add_config_j2 --template="backup_method.j2" --destination="/etc/yunohost/hooks.d/backup_method/05-${app}_app"
chmod go=--- "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
2023-01-16 19:29:00 +01:00
2024-05-26 12:55:09 +02:00
_ynh_add_config_j2 --template="backup-with-restic.j2" --destination="$install_dir/backup-with-restic"
chmod u+x "$install_dir/backup-with-restic"
2020-11-14 18:03:13 +01:00
2024-05-26 12:55:09 +02:00
## Check method
_ynh_add_config_j2 --template="check_method.j2" --destination="$install_dir/check_method_restic"
2023-01-16 19:29:00 +01:00
2024-05-26 12:55:09 +02:00
_ynh_add_config_j2 --template="check-restic.j2" --destination="$install_dir/check-restic"
chmod u+x "$install_dir/check-restic"
2024-05-26 12:55:09 +02:00
## Backup log script
_ynh_add_config_j2 --template="restic_log.j2" --destination="$install_dir/restic_log"
chmod u+x "$install_dir/restic_log"
2024-05-26 12:55:09 +02:00
# Check log script
_ynh_add_config_j2 --template="restic_check_log.j2" --destination="$install_dir/restic_check_log"
chmod u+x "$install_dir/restic_check_log"
chown -R "$app:$app" "$install_dir"
2021-02-28 16:38:35 +01:00
#=================================================
2024-05-26 12:55:09 +02:00
# SYSTEM CONFIGURATION
2021-02-28 16:38:35 +01:00
#=================================================
2024-05-26 12:55:09 +02:00
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
2021-02-28 16:38:35 +01:00
2024-05-26 12:55:09 +02:00
# Systemd services and timers
for suffix in "${systemd_services_suffixes[@]}"; do
ynh_add_systemd_config --service="$app$suffix" --template="systemd$suffix.service"
_ynh_add_config_j2 --template="systemd$suffix.timer.j2" --destination="/etc/systemd/system/$app$suffix.timer"
ynh_systemd_action --service_name="${app}$suffix.service" --action="disable"
systemctl enable --quiet "${app}$suffix.timer"
ynh_systemd_action --service_name="${app}$suffix.timer" --action="start"
2022-03-13 17:45:45 +01:00
2024-05-26 12:55:09 +02:00
yunohost service add "$app$suffix" --description="Restic backup program ($app$suffix)" \
--test_status="systemctl show $app$suffix.service -p ActiveState --value | grep -v failed"
done
ynh_add_config --template="sudoer" --destination="/etc/sudoers.d/$app"
chown root:root "/etc/sudoers.d/$app"
2023-01-16 19:29:00 +01:00
2024-05-26 12:55:09 +02:00
ynh_use_logrotate --logfile="/var/log/restic_backup_${app}.log"
ynh_use_logrotate --logfile="/var/log/restic_backup_${app}.err"
ynh_use_logrotate --logfile="/var/log/restic_check_${app}.log"
ynh_use_logrotate --logfile="/var/log/restic_check_${app}.err"
2022-03-13 17:45:45 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed"