unattended_upgrades_ynh/scripts/install

164 lines
6.1 KiB
Text
Raw Normal View History

2018-02-24 21:03:40 +01:00
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/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
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2018-02-25 14:46:16 +01:00
upgrade_level="$YNH_APP_ARG_UPGRADE_LEVEL"
ynh_update="$YNH_APP_ARG_YNH_UPDATE"
previous_apticron="$YNH_APP_ARG_PREVIOUS_APTICRON"
after_apticron="$YNH_APP_ARG_AFTER_APTICRON"
unattended_mail="$YNH_APP_ARG_UNATTENDED_MAIL"
unattended_verbosity="$YNH_APP_ARG_UNATTENDED_VERBOSITY"
2018-02-24 21:03:40 +01:00
app=$YNH_APP_INSTANCE_NAME
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2018-09-30 12:02:50 +02:00
ynh_app_setting_set $app upgrade_level "$upgrade_level"
2018-02-24 21:03:40 +01:00
ynh_app_setting_set $app ynh_update $ynh_update
ynh_app_setting_set $app previous_apticron $previous_apticron
ynh_app_setting_set $app after_apticron $after_apticron
2018-09-30 12:02:50 +02:00
ynh_app_setting_set $app unattended_mail "$unattended_mail"
2018-02-24 21:03:40 +01:00
ynh_app_setting_set $app unattended_verbosity $unattended_verbosity
2018-09-30 12:02:50 +02:00
ynh_app_setting_set $app overwrite_periodic "1"
2018-02-24 21:03:40 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2019-01-18 23:41:40 +01:00
ynh_install_app_dependencies $app_depencencies
2018-02-24 21:03:40 +01:00
#=================================================
# SPECIFIC SETUP
#=================================================
# CONFIGURE APTICRON
#=================================================
apticron_config="/etc/apticron/apticron.conf"
2018-02-25 14:46:16 +01:00
ynh_replace_string "# CUSTOM_SUBJECT=.*" \
2018-02-24 21:03:40 +01:00
"&\nCUSTOM_SUBJECT=\'[apticron] \$SYSTEM: \$NUM_PACKAGES package update(s)\'" "$apticron_config"
2018-02-25 14:46:16 +01:00
ynh_replace_string "# CUSTOM_NO_UPDATES_SUBJECT=.*" \
"&\nCUSTOM_NO_UPDATES_SUBJECT=\'[apticron] \$SYSTEM: Up to date \\\\o/\'" "$apticron_config"
2018-02-24 21:03:40 +01:00
#=================================================
# CONFIGURE UNATTENDED-UPGRADES
#=================================================
unattended_upgrades_config="/etc/apt/apt.conf.d/50unattended-upgrades"
2018-02-25 14:46:16 +01:00
# Make a backup of 50unattended-upgrades
cp -a "$unattended_upgrades_config" "/etc/apt/50unattended-upgrades.backup"
2018-02-24 21:03:40 +01:00
# Configure upgrade sources
# Allow other updates
if [ "$upgrade_level" = "Security and updates" ]
then
2018-09-30 12:02:50 +02:00
ynh_replace_string "//\(.*\"o=Debian,a=stable\)" "\1" "$unattended_upgrades_config"
ynh_replace_string "//\(.*\"o=Debian,a=stable-updates\)" "\1" "$unattended_upgrades_config"
2018-02-24 21:03:40 +01:00
fi
# Add YunoHost upgrade source
if [ $ynh_update -eq 1 ]
then
2018-02-25 14:46:16 +01:00
ynh_replace_string "origin=Debian,codename=\${distro_codename},label=Debian-Security\";" \
2018-09-30 12:02:50 +02:00
"&\n\n //YunoHost upgrade\n \"o=YunoHost,a=stable\";" "$unattended_upgrades_config"
2018-02-24 21:03:40 +01:00
fi
# Allow MinimalSteps upgrading to reduce risk in case of reboot
2018-02-25 14:46:16 +01:00
ynh_replace_string "//\(Unattended-Upgrade::MinimalSteps\).*" "\1 \"true\";" "$unattended_upgrades_config"
2018-02-24 21:03:40 +01:00
# Configure Unattended Upgrades mailing
if [ "$unattended_mail" = "If an upgrade has been done" ]
then
# Allow mail to root
2018-02-25 14:46:16 +01:00
ynh_replace_string "//\(Unattended-Upgrade::Mail \)" "\1" "$unattended_upgrades_config"
2018-02-24 21:03:40 +01:00
# Send mail even if there's no errors
2018-02-25 14:46:16 +01:00
ynh_replace_string "//\(Unattended-Upgrade::MailOnlyOnError \).*" "\1\"false\";" "$unattended_upgrades_config"
2018-02-24 21:03:40 +01:00
elif [ "$unattended_mail" = "Only if there was an error" ]
then
# Allow mail to root
2018-02-25 14:46:16 +01:00
ynh_replace_string "//\(Unattended-Upgrade::Mail \)" "\1" "$unattended_upgrades_config"
2018-02-24 21:03:40 +01:00
# Send mail only if there's an error
2018-02-25 14:46:16 +01:00
ynh_replace_string "//\(Unattended-Upgrade::MailOnlyOnError \).*" "\1\"true\";" "$unattended_upgrades_config"
2018-02-24 21:03:40 +01:00
else # "Never"
# Comment "Unattended-Upgrade::Mail" if isn't already commented
2018-02-25 14:46:16 +01:00
ynh_replace_string "^\(Unattended-Upgrade::Mail \)" "//\1" "$unattended_upgrades_config"
2018-02-24 21:03:40 +01:00
fi
#=================================================
# CONFIGURE APT PERIODIC FOR UNATTENDED
#=================================================
cp "../conf/02periodic" "/etc/apt/apt.conf.d/02periodic"
ynh_replace_string "__VERBOSITY__" "$unattended_verbosity" "/etc/apt/apt.conf.d/02periodic"
# This config file is used by /etc/cron.daily/apt
ynh_store_file_checksum "/etc/apt/apt.conf.d/02periodic"
#=================================================
2018-02-25 14:46:16 +01:00
# MODIFY ORIGINAL APTICRON CRON FILE
2018-02-24 21:03:40 +01:00
#=================================================
2018-02-25 14:46:16 +01:00
apticron_cron="/etc/cron.d/apticron"
# Copy and comment the current cron
ynh_replace_string "^.* root if.*" "#&\n&" "$apticron_cron"
# Modify the time to set at 20:00 every day
ynh_replace_string "^[[:digit:]].*\( root if.*\)" "0 20 * * *\1" "$apticron_cron"
# Copy the new cron and set the time to 2:00 every night
ynh_replace_string "^0 20\(.*\)" "&\n0 2\1" "$apticron_cron"
2018-02-24 21:03:40 +01:00
2018-02-25 14:46:16 +01:00
if [ $previous_apticron -eq 0 ]
then
# Comment the first cron
ynh_replace_string "^0 20 .*" "#&" "$apticron_cron"
fi
2018-02-24 21:03:40 +01:00
2018-02-25 14:46:16 +01:00
if [ $after_apticron -eq 0 ]
then
# Comment the second cron
ynh_replace_string "^0 2 .*" "#&" "$apticron_cron"
fi
2018-02-24 21:03:40 +01:00
#=================================================
# GENERIC FINALISATION
#=================================================
2018-02-25 14:46:16 +01:00
# SEND A README FOR THE ADMIN
2018-02-24 21:03:40 +01:00
#=================================================
2018-02-25 14:46:16 +01:00
message="To modify any option of unattended-upgrades, please have a look to $unattended_upgrades_config and
/etc/apt/apt.conf.d/02periodic
Unattended-upgrades will be executed every day at midnight.
2018-02-24 21:03:40 +01:00
2018-02-25 14:46:16 +01:00
To modify the configuration of apticron, please have a look to $apticron_config.
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 $apticron_cron.
2018-02-24 21:03:40 +01:00
2018-02-25 14:46:16 +01:00
If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/unattended_upgrades_ynh"
2018-02-24 21:03:40 +01:00
2018-07-13 17:38:14 +02:00
ynh_send_readme_to_admin --app_message="$message" --recipients="root"