From e58b75730ad34bcceffee6f7dd50c070ac682c19 Mon Sep 17 00:00:00 2001 From: Heavy Date: Mon, 10 Jan 2022 08:50:46 +0100 Subject: [PATCH] Added script to check for Debian updates. --- bin/executable_deb-check.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 bin/executable_deb-check.sh diff --git a/bin/executable_deb-check.sh b/bin/executable_deb-check.sh new file mode 100644 index 0000000..fe8c073 --- /dev/null +++ b/bin/executable_deb-check.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Checks for debian updates and informs a gotify server. +# +# MUST RUN AS ROOT (best in a cronjob) +# + +token="https://heavy.uber.space/gotify/message?token=Apw3EgT7BpQZ0rs" +MYTEMPDIR="$(mktemp -d)" +MYAPT="$MYTEMPDIR/apt-update.txt" +trap 'rm -rf -- "$MYDIR"' EXIT + +apt update > "$MYAPT" 2>&1 +MSG=$(tail -1 "$MYAPT") + +if [[ $MSG =~ All.packages.are.up.to.date ]]; then + echo $MSG +else + SUMMARY=$(echo "$MSG" | awk -F "." '{print $1}') + LST="$(aptitude -F %p search '~U')" + LST="$(echo $LST | tr '\n' ' ')" + text="$SUMMARY ($(uname -n)):\n $LST" + curl -H "Content-Type: application/json" -X POST $token -d "{\"title\":\"Debian Update Checker\",\"message\":\"$text\"}" +fi +