Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7d56c2
commit eb48bf3
Showing
7 changed files
with
480 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[{ | ||
"id": "reset_default_unattended", | ||
"name": "Reset the 50unattended-upgrades config file and restore a default one.", | ||
"command": "/bin/bash scripts/actions/reset_default_config \"50unattended-upgrades\"", | ||
"user": "root", | ||
"accepted_return_codes": [0], | ||
"description": { | ||
"en": "Reset the unattended-upgrades config file 50unattended-upgrades.", | ||
"fr": "Réinitialise le fichier de configuration unattended-upgrades 50unattended-upgrades." | ||
} | ||
}, | ||
{ | ||
"id": "reset_default_periodic", | ||
"name": "Reset the 02periodic apt config file and restore a default one.", | ||
"command": "/bin/bash scripts/actions/reset_default_config \"02periodic\"", | ||
"user": "root", | ||
"accepted_return_codes": [0], | ||
"description": { | ||
"en": "Reset the config file 02periodic.", | ||
"fr": "Réinitialise le fichier de configuration 02periodic." | ||
} | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{ | ||
"name": "Unattended-upgrades configuration panel", | ||
"version": "0.1", | ||
"panel": [{ | ||
"name": "Unattended-upgrades configuration", | ||
"id": "main", | ||
"sections": [{ | ||
"name": "50unattended-upgrades configuration file", | ||
"id": "unattended_configuration", | ||
"options": [{ | ||
"name": "Choose the sources of packages to automatically upgrade.", | ||
"help": "We can't use a choices field for now. In the meantime please choose between one of this values:<br>Security only, Security and updates.", | ||
"id": "upgrade_level", | ||
"type": "text", | ||
"//": "\"choices\" : [\"Security only\", \"Security and updates\"]", | ||
"default" : "Security only" | ||
}, | ||
{ | ||
"name": "Would you like to update YunoHost packages automatically ?", | ||
"id": "ynh_update", | ||
"type": "bool", | ||
"default": true | ||
}, | ||
{ | ||
"name": "Would you like to receive an email from Unattended-Upgrades ?", | ||
"help": "We can't use a choices field for now. In the meantime please choose between one of this values:<br>If an upgrade has been done, Only if there was an error, Never.", | ||
"id": "unattended_mail", | ||
"type": "text", | ||
"//": "\"choices\" : [\"If an upgrade has been done\", \"Only if there was an error\", \"Never\"]", | ||
"default" : "If an upgrade has been done" | ||
}] | ||
}, | ||
{ | ||
"name": "apticron cron file", | ||
"id": "apticron_configuration", | ||
"options": [{ | ||
"name": "Would you like to receive an email to inform which upgrades need to be done ?", | ||
"id": "previous_apticron", | ||
"type": "bool", | ||
"default": true | ||
}, | ||
{ | ||
"name": "When do you want to receive this email ?", | ||
"help": "Choose an hour between 12 and 23.<br>", | ||
"id": "previous_apticron_hour", | ||
"type": "number", | ||
"default": 20 | ||
}, | ||
{ | ||
"name": "Would you like to receive an email to verify if there any upgrades left after each auto upgrade ?", | ||
"id": "after_apticron", | ||
"type": "bool", | ||
"default": true | ||
}, | ||
{ | ||
"name": "When do you want to receive this email ?", | ||
"help": "Choose an hour between 0 and 10.", | ||
"id": "after_apticron_hour", | ||
"type": "number", | ||
"default": 2 | ||
}] | ||
}, | ||
{ | ||
"name": "02periodic apt config file", | ||
"id": "periodic_configuration", | ||
"options": [{ | ||
"name": "Choose the level of verbosity of Unattended-Upgrades mail", | ||
"help": "We can't use a choices field for now. In the meantime please choose between one of this values:<br>1, 2, 3.", | ||
"help": "1: Progress report only.<br>2: Progress report and command outputs.<br>3: Progress report and command outputs and trace.", | ||
"id": "unattended_verbosity", | ||
"type": "text", | ||
"//": "\"choices\" : [\"1\", \"2\", \"3\"]", | ||
"default" : "1" | ||
}] | ||
}, | ||
{ | ||
"name": "Overwriting config files", | ||
"id": "overwrite_files", | ||
"options": [{ | ||
"name": "Overwrite the config file 02periodic ?", | ||
"help": "If the file is overwritten, a backup will be created.", | ||
"id": "overwrite_periodic", | ||
"type": "bool", | ||
"default": true | ||
}] | ||
}] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#!/bin/bash | ||
|
||
#================================================= | ||
# GENERIC STARTING | ||
#================================================= | ||
# IMPORT GENERIC HELPERS | ||
#================================================= | ||
|
||
source scripts/_common.sh | ||
source /usr/share/yunohost/helpers | ||
|
||
#================================================= | ||
# RETRIEVE ARGUMENTS | ||
#================================================= | ||
|
||
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 | ||
#================================================= | ||
|
||
# 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 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" |
Oops, something went wrong.