unattended_upgrades_ynh/scripts/upgrade

165 lines
6.1 KiB
Text
Raw Normal View History

2018-02-24 21:03:40 +01:00
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2019-01-18 23:41:40 +01:00
# Load common variables for all scripts.
source _variables
2018-02-24 21:03:40 +01:00
2020-04-23 20:44:27 +02:00
source _common.sh
source /usr/share/yunohost/helpers
2018-02-24 21:03:40 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2020-04-23 20:44:27 +02:00
ynh_script_progression --message="Loading installation settings..."
2018-02-24 21:03:40 +01:00
app=$YNH_APP_INSTANCE_NAME
2020-04-23 20:44:27 +02:00
unattended_verbosity=$(ynh_app_setting_get --app=$app --key=unattended_verbosity)
overwrite_periodic=$(ynh_app_setting_get --app=$app --key=overwrite_periodic)
2018-02-25 15:14:30 +01:00
2018-02-24 21:03:40 +01:00
#=================================================
# CHECK VERSION
#=================================================
2018-07-13 17:38:14 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2018-02-24 21:03:40 +01:00
2018-09-30 12:02:50 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-04-23 20:44:27 +02:00
ynh_script_progression --message="Ensuring downward compatibility..."
2018-09-30 12:02:50 +02:00
# If overwrite_periodic doesn't exist, create it
if [ -z "$overwrite_periodic" ]; then
2020-04-23 20:44:27 +02:00
overwrite_periodic=1
ynh_app_setting_set --app=$app --key=overwrite_periodic --value=$overwrite_periodic
fi
# If admin_mail_html doesn't exist, create it
if [ -z "$admin_mail_html" ]; then
admin_mail_html=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html
fi
# Make a non perfect backup for apticron.conf if non existent
if [ ! -e "../conf/apticron.conf.backup" ]; then
# Create a backup of the config file for the reset action
cp "/etc/apticron/apticron.conf" "../conf/apticron.conf.backup"
sed --in-place '/^CUSTOM_SUBJECT=/d' "../conf/apticron.conf.backup"
sed --in-place '/^CUSTOM_NO_UPDATES_SUBJECT=/d' "../conf/apticron.conf.backup"
fi
# Make a non perfect backup for apticron cron file if non existent
if [ ! -e "../conf/apticron.crond.backup" ]; then
# Create a backup of the config file for the reset action
cp "/etc/cron.d/apticron" "../conf/apticron.crond.backup"
sed --in-place '/^[[:digit:]]/d' "../conf/apticron.crond.backup"
ynh_replace_string --match_string="^#\([[:digit:]].*\)" --replace_string="\1" --target_file="../conf/apticron.crond.backup"
2018-09-30 12:02:50 +02:00
fi
2018-02-24 21:03:40 +01:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2020-04-23 20:44:27 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3
2018-02-25 15:14:30 +01:00
2018-02-24 21:03:40 +01:00
# Backup the current version of the app
2018-07-13 17:38:14 +02:00
ynh_backup_before_upgrade
ynh_clean_setup () {
2020-04-23 20:44:27 +02:00
# restore it if the upgrade fails
ynh_restore_upgradebackup
2018-07-13 17:38:14 +02:00
}
2018-02-24 21:03:40 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
2018-02-25 14:46:16 +01:00
# INSTALL DEPENDENCIES
2018-02-24 21:03:40 +01:00
#=================================================
2020-04-23 20:44:27 +02:00
ynh_script_progression --message="Upgrading dependencies..." --weight=5
2018-02-24 21:03:40 +01:00
2019-01-18 23:41:40 +01:00
ynh_install_app_dependencies $app_depencencies
2018-02-24 21:03:40 +01:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
2018-02-25 14:46:16 +01:00
# UPGRADE APTICRON
2018-02-24 21:03:40 +01:00
#=================================================
2018-02-25 14:46:16 +01:00
# Nothing to do here...
2018-02-24 21:03:40 +01:00
#=================================================
2018-02-25 14:46:16 +01:00
# UPGRADE UNATTENDED-UPGRADES
2018-02-24 21:03:40 +01:00
#=================================================
2018-02-25 14:46:16 +01:00
# Nothing to do here...
2018-02-24 21:03:40 +01:00
#=================================================
2018-02-25 14:46:16 +01:00
# UPGRADE APT PERIODIC FOR UNATTENDED
2018-02-24 21:03:40 +01:00
#=================================================
2018-09-30 12:02:50 +02:00
# Overwrite 02periodic config file only if it's allowed
if [ $overwrite_periodic -eq 1 ]
then
2020-04-23 20:44:27 +02:00
ynh_script_progression --message="Upgrading APT Periodic for Unattended..." --weight=3
ynh_backup_if_checksum_is_different --file="/etc/apt/apt.conf.d/02periodic"
2018-02-24 21:03:40 +01:00
2020-04-23 20:44:27 +02:00
cp "../conf/02periodic" "/etc/apt/apt.conf.d/02periodic"
ynh_replace_string --match_string="__VERBOSITY__" --replace_string="$unattended_verbosity" --target_file="/etc/apt/apt.conf.d/02periodic"
# This config file is used by /etc/cron.daily/apt
2018-02-24 21:03:40 +01:00
2020-04-23 20:44:27 +02:00
ynh_store_file_checksum --file="/etc/apt/apt.conf.d/02periodic"
2018-09-30 12:02:50 +02:00
fi
2018-02-24 21:03:40 +01:00
#=================================================
2018-02-25 14:46:16 +01:00
# UPGRADE APTICRON CRON FILE
2018-02-24 21:03:40 +01:00
#=================================================
2018-02-25 14:46:16 +01:00
# Nothing to do here...
2019-01-21 13:24:26 +01:00
#=================================================
# GENERIC FINALISATION
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
2020-04-23 20:29:58 +02:00
# If a html email is required. Apply html to the changelog.
if [ "$admin_mail_html" -eq 1 ]; then
format=html
else
format=plain
fi
ynh_app_changelog --format=$format
2019-01-30 19:36:12 +01:00
echo "To modify any option of unattended-upgrades, please have a look to /etc/apt/apt.conf.d/50unattended-upgrades and
2019-01-21 13:24:26 +01:00
/etc/apt/apt.conf.d/02periodic
Unattended-upgrades will be executed every day at midnight.
To modify the configuration of apticron, please have a look to /etc/apticron/apticron.conf.
Apticron will be executed, depending of the requested configuration at 8 p.m. and 2 a.m. If you want to change this schedule, please have a look to the cron file /etc/cron.d/apticron.
2019-01-30 19:36:12 +01:00
You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/unattended_upgrades_ynh__URL_TAG3__.
---
Changelog since your last upgrade:
$(cat changelog)" > mail_to_send
2019-01-21 13:24:26 +01:00
2020-04-23 20:44:27 +02:00
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients=root --type=upgrade
2019-01-21 13:24:26 +01:00
2019-01-30 19:18:18 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2020-04-23 20:44:27 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last