This repository has been archived on 2023-09-23. You can view files and clone it, but cannot push or open issues or pull requests.
awesome-scripts/update-notify.sh

31 lines
740 B
Bash
Raw Normal View History

#!/bin/bash
GOTIFY_FILE=$(<~/.gotify)
GOTIFY_TOKEN=${GOTIFY_FILE##*( )}
HOST="$(hostname)"
TITLE="Updates available on $HOST"
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
apt update
UPDATE=$(apt list --upgradable)
echo "$UPDATE"
if [[ $UPDATE == *$'\n'* ]]; then
curl -F "title=$TITLE" -F "message=$UPDATE" -F "priority=5" "https://push.sp-codes.de/message?token=$GOTIFY_TOKEN"
fi
if [ -f /var/run/reboot-required ]; then
TITLE="Reboot required on $HOST"
MESSAGE="Reboot required\n"
if [ -f /var/run/reboot-required.pkgs ]; then
MESSAGE+=$(cat /var/run/reboot-required.pkgs)
fi
curl -F "title=$TITLE" -F "message=$MESSAGE" -F "priority=5" "https://push.sp-codes.de/message?token=$GOTIFY_TOKEN"
fi