Skip to content

Commit

Permalink
Unattended Upgrade Manager module - reconfiguring automatic updates
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Mar 1, 2025
1 parent 889e9f8 commit 530d75f
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 2 deletions.
33 changes: 31 additions & 2 deletions tools/json/config.system.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,38 @@
"status": "Stable",
"author": "@armbian",
"condition": "module_watchtower status && pkg_installed docker-ce"
},
{
"id": "UNAT01",
"description": "Enable automating packages updating",
"command": [
"module_armbian_upgrades install"
],
"status": "Stable",
"author": "@armbian",
"condition": "! module_armbian_upgrades status"
},
{
"id": "UNAT02",
"description": "Configure automating packages updating",
"command": [
"module_armbian_upgrades configure"
],
"status": "Stable",
"author": "@armbian",
"condition": "module_armbian_upgrades status"
},
{
"id": "UNAT03",
"description": "Disable automating packages updating",
"command": [
"module_armbian_upgrades remove"
],
"status": "Stable",
"author": "@armbian",
"condition": "module_armbian_upgrades status"
}



]
}
]
Expand Down
156 changes: 156 additions & 0 deletions tools/modules/system/module_armbian_upgrades.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
declare -A module_options
module_options+=(
["module_armbian_upgrades,author"]="@igorpecovnik"
["module_armbian_upgrades,feature"]="module_armbian_upgrades"
["module_armbian_upgrades,desc"]="Install and configure automatic updates"
["module_armbian_upgrades,example"]="install remove configure status defaults help"
["module_armbian_upgrades,port"]=""
["module_armbian_upgrades,status"]="Active"
["module_armbian_upgrades,arch"]="x86-64"
)
#
# Module configure automatic updates
#
function module_armbian_upgrades () {

local title="unattended-upgrades"
local condition=$(which "$title" 2>/dev/null)

local commands
IFS=' ' read -r -a commands <<< "${module_options["module_armbian_upgrades,example"]}"

case "$1" in

"${commands[0]}")
pkg_update
pkg_install -o Dpkg::Options::="--force-confold" unattended-upgrades
# set Armbian defaults
${module_options["module_armbian_upgrades,feature"]} ${commands[4]}
;;
"${commands[1]}")
pkg_remove unattended-upgrades
;;
"${commands[2]}")
# read values from 20auto-upgrades
if [[ -f "/etc/apt/apt.conf.d/20auto-upgrades" ]]; then
Unattended_Upgrade=$(
awk -F'"' '/APT::Periodic::Unattended-Upgrade/ {print ($2 == 1) ? "ON" : "OFF"}' /etc/apt/apt.conf.d/20auto-upgrades
)
Update_Package_Lists=$(
awk -F'"' '/APT::Periodic::Update-Package-Lists/ {print ($2 == 1) ? "ON" : "OFF"}' /etc/apt/apt.conf.d/20auto-upgrades
)
Download_Upgradeable_Packages=$(
awk -F'"' '/APT::Periodic::Download-Upgradeable-Packages/ {print ($2 == 1) ? "ON" : "OFF"}' /etc/apt/apt.conf.d/20auto-upgrades
)
fi
# read values from 50unattended-upgrades
if [[ -f "/etc/apt/apt.conf.d/50unattended-upgrades" ]]; then
AutoFixInterruptedDpkg=$(
awk -F'"' '/Unattended-Upgrade::AutoFixInterruptedDpkg/ {print ($2 == "true") ? "ON" : "OFF"}' /etc/apt/apt.conf.d/50unattended-upgrades
)
Remove_New_Unused_Dependencies=$(
awk -F'"' '/Unattended-Upgrade::Remove-New-Unused-Dependencies/ {print ($2 == "true") ? "ON" : "OFF"}' /etc/apt/apt.conf.d/50unattended-upgrades
)
Automatic_Reboot=$(
awk -F'"' '/Unattended-Upgrade::Automatic-Reboot "/ {print ($2 == "true") ? "ON" : "OFF"}' /etc/apt/apt.conf.d/50unattended-upgrades
)
Automatic_Reboot_WithUsers=$(
awk -F'"' '/Unattended-Upgrade::Automatic-Reboot-WithUsers/ {print ($2 == "true") ? "ON" : "OFF"}' /etc/apt/apt.conf.d/50unattended-upgrades
)
Remove_Unused_Dependencies=$(
awk -F'"' '/Unattended-Upgrade::Remove-Unused-Dependencies/ {print ($2 == "true") ? "ON" : "OFF"}' /etc/apt/apt.conf.d/50unattended-upgrades
)
fi
# toggle options
if target_sync=$($DIALOG --title "Select an Option" --notags --checklist \
"\nConfigure unattended-upgrade options:" 16 73 8 \
"Unattended-Upgrade" "Automatic security and package updates system." ${Unattended_Upgrade:-ON} \
"Update-Package-Lists" "Automatically updates the list of available packages." ${Update_Package_Lists:-OFF} \
"Download-Upgradeable-Packages" "Downloads upgradeable packages without installing them." ${Download_Upgradeable_Packages:-OFF} \
"AutoFixInterruptedDpkg" "Fixes interrupted package installations during upgrades." ${AutoFixInterruptedDpkg:-OFF} \
"Remove-New-Unused-Dependencies" "Removes dependencies no longer required after upgrades." ${Remove_New_Unused_Dependencies:-OFF} \
"Automatic-Reboot" "Reboots the system automatically if required after upgrades. " ${Automatic_Reboot:-OFF} \
"Automatic-Reboot-WithUsers" "Reboots even if users are logged in." ${Automatic_Reboot_WithUsers:-OFF} \
"Remove-Unused-Dependencies" "Removes packages that are no longer required after upgrades." ${Remove_Unused_Dependencies:-OFF} 3>&1 1>&2 2>&3); then
# set all to 0 or false
sed -i 's/"[0-9]"/"0"/g' /etc/apt/apt.conf.d/20auto-upgrades
sed -i 's/"true"/"false"/g' /etc/apt/apt.conf.d/50unattended-upgrades
for choice in $(echo ${target_sync} | tr -d '"'); do
sed -i "s/\($choice \"\)0\(\";\)/\11\2/" /etc/apt/apt.conf.d/20auto-upgrades
sed -i "s/\($choice \"\)false\(\";\)/\1true\2/" /etc/apt/apt.conf.d/50unattended-upgrades
done
fi
srv_restart unattended-upgrades
;;
"${commands[3]}")
if pkg_installed unattended-upgrades; then
return 0
else
return 1
fi
;;
"${commands[4]}")

# global options
cat > "/etc/apt/apt.conf.d/20auto-upgrades" <<- EOT
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";
EOT

# unattended-upgrades
cat > "/etc/apt/apt.conf.d/50unattended-upgrades" <<- EOT
// armbian-config generated
Unattended-Upgrade::Allowed-Origins {
"origin=${distro_id},${distro_codename}-security";
"origin=${distro_id},${distro_codename}-updates";
"origin=${distro_id}:${distro_codename}-proposed";
"origin=${distro_id},${distro_codename}-backports";
};
// black list
// Unattended-Upgrade::Package-Blacklist {
// "armbian-";
// "linux-";
//};
// This option allows you to control if on a unclean dpkg exit
// unattended-upgrades will automatically run
// dpkg --force-confold --configure -a
// The default is true, to ensure updates keep getting installed
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
// Do automatic removal of newly unused dependencies after the upgrade
Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
// Do automatic removal of unused packages after the upgrade
// (equivalent to apt-get autoremove)
Unattended-Upgrade::Remove-Unused-Dependencies "true";
// Automatically reboot *WITHOUT CONFIRMATION* if
// the file /var/run/reboot-required is found after the upgrade
Unattended-Upgrade::Automatic-Reboot "true";
// Automatically reboot even if there are users currently logged in
// when Unattended-Upgrade::Automatic-Reboot is set to true
Unattended-Upgrade::Automatic-Reboot-WithUsers "true";
EOT

;;
"${commands[5]}")
echo -e "\nUsage: ${module_options["module_armbian_upgrades,feature"]} <command> [switches]"
echo -e "Commands: ${module_options["module_armbian_upgrades,example"]}"
echo -e "Available commands:\n"
echo -e "\tinstall\t\t- Install Armbian $title."
echo -e "\tremove\t\t- Remove $title."
echo -e "\tconfigure\t- Configure $title."
echo -e "\tstatus\t\t- Status of $title."
echo -e "\tdefaults\t- Set to Armbian defalt $title config."
echo
;;
*)
${module_options["module_armbian_upgrades,feature"]} ${commands[5]}
;;
esac
}

0 comments on commit 530d75f

Please sign in to comment.