git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/bin/os-patching-adhoc
diff options
context:
space:
mode:
authormail_redacted_for_web 2026-02-08 15:38:49 +0100
committermail_redacted_for_web 2026-02-08 15:38:49 +0100
commit41e882403cc99eac6e0bba7afde564044b439568 (patch)
treee1b1fb9e3a652b848bac86c9061449cc7c69d9de /bin/os-patching-adhoc
parent9672020142d1f03528c573ccb4d9315c8d9d0990 (diff)
downloados-patch-41e882403cc99eac6e0bba7afde564044b439568.tar.bz2
Introduce update counts to RHEL and derivative patchingHEADv0.11.0master
Diffstat (limited to 'bin/os-patching-adhoc')
-rwxr-xr-xbin/os-patching-adhoc49
1 files changed, 31 insertions, 18 deletions
diff --git a/bin/os-patching-adhoc b/bin/os-patching-adhoc
index 5e62bf4..ae0b7d0 100755
--- a/bin/os-patching-adhoc
+++ b/bin/os-patching-adhoc
@@ -250,31 +250,44 @@ case "$ID_LIKE" in
"rhel"*|"centos"*)
# we do not use --skip-broken here - we keep our systems tidy, so any pollution may and should
# cause an error :-)
-
+
+ # On RHEL and derivatives, dnf populates separate caches for each user, requiring us to do something
+ # like "list updates" as well as root (or inefficiently build the cache twice). :-}
+ # This is scripted, so for now this script has to be called as root. We could consider using sudo below
+ # in the future; however this would be a decision for the whole script as for now, we don't do escalations
+ # anywhere.
header 'Starting package list update'
mystart="$(/usr/bin/date '+%s')"
/usr/bin/dnf -d1 makecache && printf 'OK.\n' || exit 110
myend="$(/usr/bin/date '+%s')"
footer "...done ($((myend - mystart)) seconds)."
+ ULIST="$(/usr/bin/dnf -d0 list --upgrades | grep -v '^Available Upgrades')"
+ UPDATENUM="$(printf '%b\n' "$ULIST" | grep -vcP '^$')"
+ printf '\033[3m\033[1m%b update(s) found.\033[0m\n' "$UPDATENUM"
- header 'Starting package upgrade'
- mystart="$(/usr/bin/date '+%s')"
- /usr/bin/dnf --comment='os_patching_adhoc' -d1 --obsoletes --best -y upgrade &&\
- printf 'OK.\n' || exit 111
- myend="$(/usr/bin/date '+%s')"
- footer "...done ($((myend - mystart)) seconds)."
-
- header 'Checking reboot requirement'
- if ! /usr/bin/dnf -d1 needs-restarting -r; then
- footer 'Outdated libraries or kernel found, rebooting.'
- /usr/bin/systemctl reboot
+ # No updates found?
+ if [ "$UPDATENUM" -lt 1 ]; then
+ printf '\033[3m\033[1m\033[2mSkipping updates.\033[0m\n'
else
- if [ -x "$OSPBIN" ]; then
- header 'Starting os_patching_fact_generation.sh'
- ospstart="$(/usr/bin/date '+%s')"
- "$OSPBIN"
- ospend="$(/usr/bin/date '+%s')"
- footer "...done ($((ospend - ospstart)) seconds)."
+ header 'Starting package upgrade'
+ mystart="$(/usr/bin/date '+%s')"
+ /usr/bin/dnf --comment='os_patching_adhoc' -d1 --obsoletes --best -y upgrade &&\
+ printf 'OK.\n' || exit 111
+ myend="$(/usr/bin/date '+%s')"
+ footer "...done ($((myend - mystart)) seconds)."
+
+ header 'Checking reboot requirement'
+ if ! /usr/bin/dnf -d1 needs-restarting -r; then
+ footer 'Outdated libraries or kernel found, rebooting.'
+ /usr/bin/systemctl reboot
+ else
+ if [ -x "$OSPBIN" ]; then
+ header 'Starting os_patching_fact_generation.sh'
+ ospstart="$(/usr/bin/date '+%s')"
+ "$OSPBIN"
+ ospend="$(/usr/bin/date '+%s')"
+ footer "...done ($((ospend - ospstart)) seconds)."
+ fi
fi
fi
;;