mirror of
https://github.com/YunoHost-Apps/borg_ynh.git
synced 2024-09-03 18:16:05 +02:00
162 lines
5.9 KiB
Bash
Executable file
162 lines
5.9 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
|
|
export app=$YNH_APP_INSTANCE_NAME
|
|
|
|
export repository="$(ynh_app_setting_get $app repository)"
|
|
export server="$(ynh_app_setting_get $app server)"
|
|
export ssh_user="$(ynh_app_setting_get $app ssh_user)"
|
|
export passphrase="$(ynh_app_setting_get $app passphrase)"
|
|
export on_calendar="$(ynh_app_setting_get $app on_calendar)"
|
|
export conf="$(ynh_app_setting_get $app conf)"
|
|
export data="$(ynh_app_setting_get $app data)"
|
|
export apps="$(ynh_app_setting_get $app apps)"
|
|
export mailalert="$(ynh_app_setting_get $app mailalert)"
|
|
if [[ $mailalert != "always" && $mailalert != "errors_only" && $mailalert != "never" ]]; then
|
|
ynh_app_setting_set --app=$app --key="mailalert" --value="errors_only"
|
|
export mailalert="errors_only"
|
|
fi
|
|
ynh_app_setting_set --app=$app --key="state" --value="not run since last update"
|
|
ynh_app_setting_set --app=$app --key="last_run" --value="-"
|
|
|
|
#=================================================
|
|
# CHECK IF AN UPGRADE IS NEEDED
|
|
#=================================================
|
|
ynh_check_app_version_changed
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
# restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
if [ -z "$repository" ]; then
|
|
repository="ssh://$ssh_user@$server/~/backup"
|
|
server=$(echo "$repository" | cut -d"@" -f2 | cut -d"/" -f1)
|
|
if [[ $server == *":"* ]]; then
|
|
server="[$(echo "$server" | cut -d":" -f1)]:$(echo "$server" | cut -d":" -f2)"
|
|
fi
|
|
ynh_app_setting_set $app repository "$repository"
|
|
ynh_app_setting_set $app server "$server"
|
|
ynh_app_setting_delete $app ssh_user
|
|
fi
|
|
|
|
if grep "borg.timer" /etc/yunohost/services.yml > /dev/null ; then
|
|
yunohost service remove $app.timer
|
|
systemctl enable $app.timer --quiet
|
|
systemctl start $app.timer
|
|
fi
|
|
|
|
# Replace backports with pip
|
|
[ ! -e " /etc/apt/sources.list.d/$app-stretch-backports.list" ] || rm -f /etc/apt/sources.list.d/$app-stretch-backports.list
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring system user..." --weight=1
|
|
|
|
# Create a system user
|
|
ynh_system_user_create --username=$app
|
|
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# Upgrade borgbackup
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading borgbackup..." --weight=1
|
|
|
|
install_borg_with_pip
|
|
|
|
#=================================================
|
|
# SETUP THE BACKUP METHOD
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up backup method..." --weight=1
|
|
ynh_add_config --template="backup_method" --destination="/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
|
chmod go=--- "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
|
|
|
ynh_add_config --template="backup-with-borg" --destination="/usr/local/bin/backup-with-$app"
|
|
chmod u+x "/usr/local/bin/backup-with-$app"
|
|
chown $app:$app "/usr/local/bin/backup-with-$app"
|
|
|
|
ynh_add_config --template="sudoer" --destination="/etc/sudoers.d/$app"
|
|
chown root:root "/etc/sudoers.d/$app"
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
# Disable the service, this is to prevent the service from being triggered at boot time
|
|
systemctl disable $app.service --quiet
|
|
|
|
#=================================================
|
|
# CONFIGURE SYSTEMD TIMER
|
|
#=================================================
|
|
ynh_add_config --template="systemd.timer" --destination="/etc/systemd/system/$app.timer"
|
|
systemctl enable $app.timer --quiet
|
|
systemctl start $app.timer
|
|
|
|
mkdir -p /etc/yunohost/hooks.d/backup
|
|
mkdir -p /var/log/${app}
|
|
chown -R $app:$app /var/log/${app}
|
|
chmod u+w /var/log/${app}
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
|
|
# Inactive services are ignored cause it's a timer
|
|
yunohost service add $app --description="Deduplicating backup program" --test_status="systemctl show $app.service -p ActiveState --value | grep -v failed"
|
|
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|