mirror of
https://github.com/YunoHost-Apps/unattended_upgrades_ynh.git
synced 2024-10-01 13:35:00 +02:00
update
This commit is contained in:
parent
b7a24107d4
commit
36d71406aa
7 changed files with 17 additions and 195 deletions
|
@ -1,6 +1,6 @@
|
||||||
[reset_default_unattended]
|
[reset_default_unattended]
|
||||||
name = "Reset the 50unattended-upgrades config file and restore a default one."
|
name = "Reset the 50unattended-upgrades config file and restore a default one."
|
||||||
command = "/bin/bash scripts/actions/reset_default_config \"50unattended-upgrades\""
|
command = "/bin/bash scripts/actions/reapply_config \"50unattended-upgrades\""
|
||||||
# user = "root" # optional
|
# user = "root" # optional
|
||||||
# cwd = "/" # optional
|
# cwd = "/" # optional
|
||||||
# accepted_return_codes = [0, 1, 2, 3] # optional
|
# accepted_return_codes = [0, 1, 2, 3] # optional
|
||||||
|
@ -9,17 +9,16 @@ description = "Reset the unattended-upgrades config file 50unattended-upgrades."
|
||||||
|
|
||||||
[reset_default_periodic]
|
[reset_default_periodic]
|
||||||
name = "Reset the 02periodic apt config file and restore a default one."
|
name = "Reset the 02periodic apt config file and restore a default one."
|
||||||
command = "/bin/bash scripts/actions/reset_default_config \"02periodic\""
|
command = "/bin/bash scripts/actions/reapply_config \"02periodic\""
|
||||||
# user = "root" # optional
|
# user = "root" # optional
|
||||||
# cwd = "/" # optional
|
# cwd = "/" # optional
|
||||||
# accepted_return_codes = [0, 1, 2, 3] # optional
|
# accepted_return_codes = [0, 1, 2, 3] # optional
|
||||||
accepted_return_codes = [0]
|
accepted_return_codes = [0]
|
||||||
description = "Reset the config file 02periodic."
|
description = "Reset the config file 02periodic."
|
||||||
|
|
||||||
|
|
||||||
[reset_default_app]
|
[reset_default_app]
|
||||||
name = "Reset the app with a default configuration."
|
name = "Reset the app with a default configuration."
|
||||||
command = "/bin/bash scripts/actions/reset_default_app"
|
command = "/bin/bash scripts/actions/reapply_config \"50unattended-upgrades\" \"02periodic\" \"apticron\""
|
||||||
# user = "root" # optional
|
# user = "root" # optional
|
||||||
# cwd = "/" # optional
|
# cwd = "/" # optional
|
||||||
# accepted_return_codes = [0, 1, 2, 3] # optional
|
# accepted_return_codes = [0, 1, 2, 3] # optional
|
||||||
|
|
|
@ -103,6 +103,17 @@ _unattended_upgrades_restore_config() {
|
||||||
mv "$unattended_upgrades_config_backup" "$unattended_upgrades_config"
|
mv "$unattended_upgrades_config_backup" "$unattended_upgrades_config"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_02periodic_config="/etc/apt/apt.conf.d/02periodic"
|
||||||
|
|
||||||
|
_02periodic_set_config() {
|
||||||
|
ynh_add_config --template="../conf/02periodic" --destination="$_02periodic_config"
|
||||||
|
}
|
||||||
|
|
||||||
|
_02periodic_remove() {
|
||||||
|
ynh_secure_remove "$_02periodic_config"
|
||||||
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP
|
# BACKUP
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC STARTING
|
|
||||||
#=================================================
|
|
||||||
# IMPORT GENERIC HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Load common variables for all scripts.
|
|
||||||
source scripts/_common.sh
|
|
||||||
source /usr/share/yunohost/helpers
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# SPECIFIC ACTION
|
|
||||||
#=================================================
|
|
||||||
# RESET APTICRON CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Resetting Apticron..."
|
|
||||||
|
|
||||||
apticron_config="/etc/apticron/apticron.conf"
|
|
||||||
cp "conf/apticron.conf.backup" "$apticron_config"
|
|
||||||
ynh_replace_string --match_string="# CUSTOM_SUBJECT=.*" \
|
|
||||||
--replace_string="&\nCUSTOM_SUBJECT=\'[apticron] \$SYSTEM: \$NUM_PACKAGES package update(s)\'" --target_file="$apticron_config"
|
|
||||||
ynh_replace_string --match_string="# CUSTOM_NO_UPDATES_SUBJECT=.*" \
|
|
||||||
--replace_string="&\nCUSTOM_NO_UPDATES_SUBJECT=\'[apticron] \$SYSTEM: Up to date \\\\o/\'" --target_file="$apticron_config"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RESET UNATTENDED-UPGRADES CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Resetting unattended-upgrades..."
|
|
||||||
|
|
||||||
yunohost app action run $app reset_default_unattended
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RESET APT PERIODIC CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Resetting apt periodic..."
|
|
||||||
|
|
||||||
yunohost app action run $app reset_default_periodic
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RESET APTICRON CRON FILE
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Resetting apticron cron file..."
|
|
||||||
|
|
||||||
apticron_cron="/etc/cron.d/apticron"
|
|
||||||
cp "conf/apticron.crond.backup" "$apticron_cron"
|
|
||||||
|
|
||||||
# Copy and comment the current cron
|
|
||||||
ynh_replace_string --match_string="^.* root if.*" --replace_string="#&\n&" --target_file="$apticron_cron"
|
|
||||||
# Modify the time to set at 20:00 every day
|
|
||||||
ynh_replace_string --match_string="^[[:digit:]].*\( root if.*\)" --replace_string="0 20 * * *\1" --target_file="$apticron_cron"
|
|
||||||
# Copy the new cron and set the time to 2:00 every night
|
|
||||||
ynh_replace_string --match_string="^0 20\(.*\)" --replace_string="&\n0 2\1" --target_file="$apticron_cron"
|
|
||||||
|
|
||||||
if [ $previous_apticron -eq 0 ]
|
|
||||||
then
|
|
||||||
# Comment the first cron
|
|
||||||
ynh_replace_string --match_string="^0 20 .*" --replace_string="#&" --target_file="$apticron_cron"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $after_apticron -eq 0 ]
|
|
||||||
then
|
|
||||||
# Comment the second cron
|
|
||||||
ynh_replace_string --match_string="^0 2 .*" --replace_string="#&" --target_file="$apticron_cron"
|
|
||||||
fi
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# END OF SCRIPT
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_script_progression --message="Execution completed" --last
|
|
|
@ -1,116 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC STARTING
|
|
||||||
#=================================================
|
|
||||||
# IMPORT GENERIC HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
source scripts/_common.sh
|
|
||||||
source /usr/share/yunohost/helpers
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# MANAGE SCRIPT FAILURE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Exit if an error occurs during the execution of the script
|
|
||||||
ynh_abort_if_errors
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RETRIEVE ARGUMENTS
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Loading installation settings..." --weight=2
|
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
|
||||||
|
|
||||||
upgrade_level="$(ynh_app_setting_get --app=$app --key=upgrade_level)"
|
|
||||||
ynh_update=$(ynh_app_setting_get --app=$app --key=ynh_update)
|
|
||||||
unattended_mail="$(ynh_app_setting_get --app=$app --key=unattended_mail)"
|
|
||||||
unattended_verbosity=$(ynh_app_setting_get --app=$app --key=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="Resetting the config file $config_file..." --weight=9
|
|
||||||
|
|
||||||
# Verify the checksum and backup the file if it's different
|
|
||||||
ynh_backup_if_checksum_is_different --file="$config_file"
|
|
||||||
|
|
||||||
# Reset the config /etc/apt/apt.conf.d/50unattended-upgrades
|
|
||||||
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
|
|
||||||
# Allow security update
|
|
||||||
ynh_replace_string --match_string="//\(.*\"o=Debian,n=$(ynh_get_debian_release),l=Debian-Security\";\)" --replace_string="\1" --target_file="$config_file"
|
|
||||||
# Allow other updates
|
|
||||||
if [ "$upgrade_level" = "Security and updates" ]
|
|
||||||
then
|
|
||||||
ynh_replace_string --match_string="//\(.*\"o=Debian,n=$(ynh_get_debian_release)\";\)" --replace_string="\1" --target_file="$config_file"
|
|
||||||
ynh_replace_string --match_string="//\(.*\"o=Debian,n=$(ynh_get_debian_release)-updates\";\)" --replace_string="\1" --target_file="$config_file"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Add YunoHost upgrade source
|
|
||||||
if [ $ynh_update -eq 1 ]
|
|
||||||
then
|
|
||||||
ynh_replace_string --match_string="origin=Debian,codename=\$(ynh_get_debian_release),label=Debian-Security\";" \
|
|
||||||
--replace_string="&\n\n //YunoHost upgrade\n \"o=YunoHost,n=$(ynh_get_debian_release)\";" --target_file="$config_file"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Allow MinimalSteps upgrading to reduce risk in case of reboot
|
|
||||||
ynh_replace_string --match_string="//\(Unattended-Upgrade::MinimalSteps\).*" --replace_string="\1 \"true\";" --target_file="$config_file"
|
|
||||||
|
|
||||||
# Configure Unattended Upgrades mailing
|
|
||||||
if [ "$unattended_mail" = "If an upgrade has been done" ]
|
|
||||||
then
|
|
||||||
# Allow mail to root
|
|
||||||
ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$config_file"
|
|
||||||
|
|
||||||
# Send mail even if there's no errors
|
|
||||||
ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"false\";" --target_file="$config_file"
|
|
||||||
|
|
||||||
elif [ "$unattended_mail" = "Only if there was an error" ]
|
|
||||||
then
|
|
||||||
# Allow mail to root
|
|
||||||
ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$config_file"
|
|
||||||
|
|
||||||
# Send mail only if there's an error
|
|
||||||
ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"true\";" --target_file="$config_file"
|
|
||||||
|
|
||||||
else # "Never"
|
|
||||||
# Comment "Unattended-Upgrade::Mail" if it isn't already commented
|
|
||||||
ynh_replace_string --match_string="^\(Unattended-Upgrade::Mail \)" --replace_string="//\1" --target_file="$config_file"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Reset the config /etc/apt/apt.conf.d/02periodic
|
|
||||||
if [ "$file" = "02periodic" ]
|
|
||||||
then
|
|
||||||
# Get the default file and overwrite the current config
|
|
||||||
ynh_add_config --template="../conf/02periodic" --destination="/etc/apt/apt.conf.d/02periodic"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Calculate and store the config file checksum into the app settings
|
|
||||||
ynh_store_file_checksum --file="$config_file"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# END OF SCRIPT
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_script_progression --message="Execution completed" --last
|
|
|
@ -39,7 +39,7 @@ _unattended_upgrades_set_config
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configure APT Periodic for Unattended" --weight=2
|
ynh_script_progression --message="Configure APT Periodic for Unattended" --weight=2
|
||||||
|
|
||||||
ynh_add_config --template="../conf/02periodic" --destination="/etc/apt/apt.conf.d/02periodic"
|
_02periodic_set_config
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
|
|
|
@ -16,7 +16,7 @@ ynh_script_progression --message="Removing system configurations related to $app
|
||||||
|
|
||||||
_apticron_restore_config
|
_apticron_restore_config
|
||||||
_unattended_upgrades_restore_config
|
_unattended_upgrades_restore_config
|
||||||
ynh_secure_remove "/etc/apt/apt.conf.d/02periodic"
|
_02periodic_remove
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
|
|
|
@ -64,7 +64,7 @@ _unattended_upgrades_set_config
|
||||||
if [ "$overwrite_periodic" -eq 1 ]; then
|
if [ "$overwrite_periodic" -eq 1 ]; then
|
||||||
ynh_script_progression --message="Upgrading APT Periodic for Unattended..."
|
ynh_script_progression --message="Upgrading APT Periodic for Unattended..."
|
||||||
|
|
||||||
ynh_add_config --template="../conf/02periodic" --destination="/etc/apt/apt.conf.d/02periodic"
|
_02periodic_set_config
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue