check-rules green; shellcheck fixes to dpkg.sh/os-updates.sh (legacy backticks, unquoted vars, array-quoted command builders); Discourse pointers added to basis docs; awx/k8s/compliance repos referenced. https://projects.knownelement.com/issues/454
27 lines
709 B
Bash
27 lines
709 B
Bash
#!/bin/bash
|
|
# Cache the file for 30 minutes
|
|
# If you want to override this, put the command in cron.
|
|
# We cache because it is a 1sec delay, which is painful for the poller
|
|
if [ -x /usr/bin/dpkg-query ]; then
|
|
DATE=$(date +%s)
|
|
FILE=/var/cache/librenms/agent-local-dpkg
|
|
|
|
[ -d /var/cache/librenms ] || mkdir -p /var/cache/librenms
|
|
|
|
refresh() {
|
|
dpkg-query -W --showformat='${Status} ${Package} ${Version} ${Architecture} ${Installed-Size}\n' \
|
|
| grep " installed " | cut -d\ -f4- > "$FILE"
|
|
}
|
|
|
|
if [ ! -e "$FILE" ]; then
|
|
refresh
|
|
fi
|
|
FILEMTIME=$(stat -c %Y "$FILE")
|
|
FILEAGE=$((DATE - FILEMTIME))
|
|
if [ "$FILEAGE" -gt 1800 ]; then
|
|
refresh
|
|
fi
|
|
echo "<<<dpkg>>>"
|
|
cat "$FILE"
|
|
fi
|