Skip to content

Commit c296627

Browse files
committed
Fix update count for dnf4 compatibility
The fix introduced in b24592f for dnf5 compatibility inherently broke compatibility with dnf4. While that was fine at the time because sysmotd was only targeting Fedora versions using dnf5, sysmotd now also targets AlmaLinux after lolcat became available through the EPEL repository. AlmaLinux 9 and 10 still use dnf4. So enhance the logic to parse available upgrades to accommodate dnf4 and dnf5 output formats, and also include package installs (e.g. kernel) in the count. Signed-off-by: Manuel Fombuena <mfombuena@innovara.tech>
1 parent 5189602 commit c296627

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sysmotd/sysmotd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: GPL-3.0-or-later
33
# Copyright (C) 2022-2025 Manuel Fombuena <mfombuena@innovara.tech>
44
#
5-
# sysmotd - generates a MOTD (Message Of The Day) including system
5+
# sysmotd - generates a MOTD (Message Of The Day) including system
66
# information on Fedora Linux, and possibly other Red Hat-based distributions.
77
#
88
# This program is free software: you can redistribute it and/or modify
@@ -17,7 +17,7 @@
1717
#
1818
# You should have received a copy of the GNU General Public License
1919
# along with this program. If not, see <https://www.gnu.org/licenses/>.
20-
#
20+
#
2121

2222
# directory where the motd files will live
2323
rundir="/run/motd.d"
@@ -116,13 +116,17 @@ printf '%s %s %s %s %s\n' "${sysarray[@]}" | column -t -s $';' >> $sysinfo
116116
echo -e "" >> $sysinfo
117117

118118
# available updates refreshes every 60 minutes using CACHE.
119-
# dnf's cache is updated by the system using its own service and timer. The conservative
119+
# dnf's cache is updated by the system using its own service and timer. The conservative
120120
# approach is to not to change this.
121121
NEED_UPDATE="FALSE"
122122
[ -z "$(find "$updates" -newermt 'now-60 minutes' 2> /dev/null)" ] && NEED_UPDATE="TRUE"
123123

124124
if [[ "$NEED_UPDATE" = "TRUE" ]]; then
125-
n_updates=$(dnf update --assumeno --cacheonly --noplugins | awk '/^ Upgrading/ {print $2;}')
125+
n_updates=$(dnf upgrade --assumeno --cacheonly --noplugins 2>/dev/null | awk '
126+
/Upgrading:|Installing:|^Upgrade |^Install / { n+=$2 }
127+
END { print n+0 }
128+
')
129+
126130
if [[ $n_updates -eq 0 ]]; then
127131
echo -e "There were no updates available when last checked.\n" > $updates
128132
elif [[ $n_updates -eq 1 ]]; then

0 commit comments

Comments
 (0)