Add support for apt-mark hold warning (#4294)

* Add support for apt-mark hold warning

- we need to know if kernel packages are on hold
- when upgrade is finished, fix numbers and update list

* Add postupdate hook

* Bugfix

* Bugfix

* Small refactoring

* Improve UX

* Improve detection and change wording
This commit is contained in:
Igor Pečovnik 2022-10-18 09:24:36 +02:00 committed by GitHub
parent 9a0e449408
commit 0b9bd251c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View File

@ -0,0 +1 @@
DPkg::Post-Invoke {"/usr/lib/armbian/armbian-apt-updates";};

View File

@ -19,11 +19,21 @@ for f in $MOTD_DISABLE; do
done
NUM_UPDATES=0
NUM_UPDATES_ONHOLD=0
[[ -f /var/cache/apt/archives/updates.number ]] && . /var/cache/apt/archives/updates.number
if [[ $NUM_UPDATES -gt 0 ]]; then
echo -e "[\e[31m $NUM_SECURITY_UPDATES security updates available, $NUM_UPDATES updates total\e[0m: \e[1mapt upgrade\e[0m ]"
echo -en "[\e[31m $NUM_SECURITY_UPDATES security updates available, $NUM_UPDATES updates total\e[0m: \e[1mapt upgrade\e[0m "
fi
if [[ $NUM_UPDATES_ONHOLD -gt 0 ]] && grep -q linux /var/cache/apt/archives/updates.list 2>/dev/null; then
[[ $NUM_UPDATES -gt 0 ]] && echo -en "| " || echo -en "[ "
echo -en "\e[31mKernel and firmware upgrades disabled:\e[0m \e[1marmbian-config\e[0m "
fi
if [[ $NUM_UPDATES -gt 0 ]] || [[ $NUM_UPDATES_ONHOLD -gt 0 ]]; then
echo -e "]"
echo -e "Last check: \e[92m$DATE\e[0m"
echo
fi

View File

@ -34,6 +34,7 @@ fi
[[ "$((apt-get upgrade -s -qq) 2>&1)" == *"Unmet dependencies"* ]] && exit 0
myfile="/var/cache/apt/archives/updates.number"
myfiles="/var/cache/apt/archives/updates.list"
# update procedure
DISTRO=$(lsb_release -c | cut -d ":" -f 2 | tr -d '[:space:]') && DISTRO=${DISTRO,,}
@ -41,6 +42,7 @@ DISTRO=$(lsb_release -c | cut -d ":" -f 2 | tr -d '[:space:]') && DISTRO=${DIST
# run around the packages
upgrades=0
security_upgrades=0
while IFS= read -r LINE; do
# increment the upgrade counter
(( upgrades++ ))
@ -50,9 +52,13 @@ done < <(apt-get upgrade -s -qq | sed -n '/^Inst/p')
cat >|${myfile} <<EOT
NUM_UPDATES="${upgrades}"
NUM_UPDATES_ONHOLD="$(dpkg --list | grep ^hi | grep $(uname -r) | wc -l)"
NUM_SECURITY_UPDATES="${security_upgrades}"
DATE="$(date +"%Y-%m-%d %H:%M")"
EOT
# store packages list
apt list --upgradable 2>/dev/null | grep "/" >| ${myfiles}
exit 0