-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck_softwareupdate_helper
executable file
·52 lines (46 loc) · 1.46 KB
/
check_softwareupdate_helper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh
#
# (c)2019 Christian Kujau <[email protected]>
#
# Helper script for "check_softwareupdate.sh cron", which will expect
# a readable text file listing available package updates. Each line
# is expected to start with "Package: " but sed(1) can help with that.
#
# A cron job would look like this:
#
# 0 */12 * * * /usr/local/sbin/check_softwareupdate_helper apk /var/tmp/nagios_updates.txt
# 0 */12 * * * /usr/local/sbin/check_softwareupdate_helper dnf /var/run/nrpe/nagios_updates.txt
# 0 */12 * * * /usr/local/sbin/check_softwareupdate_helper opkg /tmp/opkg_list-upgradable.txt
#
_usage() {
echo "Usage: $(basename "$0") [apk|dnf|opkg] [state file]"
echo " Ex: $(basename "$0") apk /var/tmp/nagios_updates.txt"
echo " Ex: $(basename "$0") dnf ~nrpe/nagios_updates.txt"
echo " Ex: $(basename "$0") opkg /tmp/opkg_list-upgradable.txt"
exit 1
}
# Sanity check
[ $# -eq 2 ] && STATE="$2" || _usage
# Readable STATE file?
if [ -f "${STATE}" ] && [ ! -O "${STATE}" ]; then
echo "State file ${STATE} already in place but not owned by UID $(id -u)!"
exit 1
else
touch "${STATE}" && chmod a+r "${STATE}"
fi
case $1 in
apk)
apk update --quiet
apk upgrade --simulate | grep Upgrading | sed 's/.*Upgrading/Package:/' > "${STATE}"
;;
dnf)
dnf check-update | grep -Ev '^Last metadata|^$' | sed 's/^/Package: /' > "${STATE}"
;;
opkg)
opkg update > /dev/null
opkg list-upgradable | awk '{print "Package:", $1}' | sort > "${STATE}"
;;
*)
_usage
;;
esac