mirror of
https://github.com/YunoHost-Apps/unattended_upgrades_ynh.git
synced 2024-10-01 13:35:00 +02:00
110 lines
3.8 KiB
Bash
Executable file
110 lines
3.8 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC STARTING
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source scripts/_common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS
|
|
#=================================================
|
|
ynh_script_progression --message="Retrieve arguments from the manifest" --weight=2
|
|
|
|
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
|
|
upgrade_level="$(ynh_app_setting_get $app upgrade_level)"
|
|
ynh_update="$(ynh_app_setting_get $app ynh_update)"
|
|
unattended_mail="$(ynh_app_setting_get $app unattended_mail)"
|
|
unattended_verbosity="$(ynh_app_setting_get $app unattended_verbosity)"
|
|
|
|
#=================================================
|
|
# SORT OUT THE CONFIG FILE TO HANDLE
|
|
#=================================================
|
|
|
|
file="$1"
|
|
|
|
if [ "$file" = "50unattended-upgrades" ]; then
|
|
config_file="/etc/apt/apt.conf.d/50unattended-upgrades"
|
|
elif [ "$file" = "02periodic" ]; then
|
|
config_file="/etc/apt/apt.conf.d/02periodic"
|
|
fi
|
|
|
|
#=================================================
|
|
# SPECIFIC ACTION
|
|
#=================================================
|
|
# RESET THE CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Reset the config file $config_file" --weight=9
|
|
|
|
# Verify the checksum and backup the file if it's different
|
|
ynh_backup_if_checksum_is_different "$config_file"
|
|
|
|
if [ "$file" = "50unattended-upgrades" ]
|
|
then
|
|
# Get the default file and overwrite the current config
|
|
cp /etc/apt/50unattended-upgrades.backup "$config_file"
|
|
|
|
# Recreate the default config
|
|
distro_codename=$(lsb_release -cs)
|
|
# Allow security update
|
|
ynh_replace_string "//\(.*\"o=Debian,n=${distro_codename},l=Debian-Security\";\)" "\1" "$config_file"
|
|
# Allow other updates
|
|
if [ "$upgrade_level" = "Security and updates" ]
|
|
then
|
|
ynh_replace_string "//\(.*\"o=Debian,n=$distro_codename\";\)" "\1" "$config_file"
|
|
ynh_replace_string "//\(.*\"o=Debian,n=$distro_codename-updates\";\)" "\1" "$config_file"
|
|
fi
|
|
|
|
# Add YunoHost upgrade source
|
|
if [ $ynh_update -eq 1 ]
|
|
then
|
|
ynh_replace_string "origin=Debian,codename=\${distro_codename},label=Debian-Security\";" \
|
|
"&\n\n //YunoHost upgrade\n \"o=YunoHost,n=$distro_codename\";" "$config_file"
|
|
fi
|
|
|
|
# Allow MinimalSteps upgrading to reduce risk in case of reboot
|
|
ynh_replace_string "//\(Unattended-Upgrade::MinimalSteps\).*" "\1 \"true\";" "$config_file"
|
|
|
|
# Configure Unattended Upgrades mailing
|
|
if [ "$unattended_mail" = "If an upgrade has been done" ]
|
|
then
|
|
# Allow mail to root
|
|
ynh_replace_string "//\(Unattended-Upgrade::Mail \)" "\1" "$config_file"
|
|
|
|
# Send mail even if there's no errors
|
|
ynh_replace_string "//\(Unattended-Upgrade::MailOnlyOnError \).*" "\1\"false\";" "$config_file"
|
|
|
|
elif [ "$unattended_mail" = "Only if there was an error" ]
|
|
then
|
|
# Allow mail to root
|
|
ynh_replace_string "//\(Unattended-Upgrade::Mail \)" "\1" "$config_file"
|
|
|
|
# Send mail only if there's an error
|
|
ynh_replace_string "//\(Unattended-Upgrade::MailOnlyOnError \).*" "\1\"true\";" "$config_file"
|
|
|
|
else # "Never"
|
|
# Comment "Unattended-Upgrade::Mail" if it isn't already commented
|
|
ynh_replace_string "^\(Unattended-Upgrade::Mail \)" "//\1" "$config_file"
|
|
fi
|
|
fi
|
|
|
|
if [ "$file" = "02periodic" ]
|
|
then
|
|
# Get the default file and overwrite the current config
|
|
cp /etc/yunohost/apps/$app/conf/02periodic "$config_file"
|
|
|
|
# Recreate the default config
|
|
ynh_replace_string "__VERBOSITY__" "$unattended_verbosity" "/etc/apt/apt.conf.d/02periodic"
|
|
fi
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
|
ynh_store_file_checksum "$config_file"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Execution completed" --last
|