#!/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