Last active
December 7, 2025 17:59
-
-
Save pyrodex/214c88de12071eb2f113910096ba16cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Setting up logging | |
| LOGDIR=/var/log | |
| LOG="$LOGDIR/update_check.log" | |
| # Sample | |
| # echo "$(date "+[%Y-%m-%d - %H:%M:%S%p]"): ERROR: " > $LOG 2>&1 | |
| # Since we need JQ for a lot of the clean up of the JSON return let's see if it is installed | |
| if cmd=$(command -v jq); then | |
| JQ=$cmd | |
| else | |
| echo "$(date "+[%Y-%m-%d - %H:%M:%S%p]"): ERROR: Required binary jq is missing, please install it" > $LOG 2>&1 | |
| exit 1 | |
| fi | |
| # Since we need curl let's see if it is installed | |
| if cmd=$(command -v curl); then | |
| CURL=$cmd | |
| else | |
| echo "$(date "+[%Y-%m-%d - %H:%M:%S%p]"): ERROR: Required binary curl is missing, please install it" > $LOG 2>&1 | |
| exit 1 | |
| fi | |
| # Variables | |
| FW_HOST=192.168.1.1 | |
| ## This are API keys from the system | |
| FW_USER="fwuserapi" | |
| FW_PASS="fwpassapi" | |
| # pushover settings | |
| userkey="userkey" | |
| apitoken="apitoken" | |
| device="device1,device2" | |
| # Pushover notification function | |
| notify () { | |
| message=$1 | |
| sound=$2 | |
| curl -s https://api.pushover.net/1/messages.json -d "token=${apitoken}&user=${userkey}&title=OPNSense%20Updates&message=${message}×tamp=${ts}&device=${device}&sound=${sound}" | |
| } | |
| # Let's pull the current data from the API call and see if there is even an update available | |
| UPDATE_STATUS=$($CURL -s -k -u "$FW_USER":"$FW_PASS" https://$FW_HOST/api/core/firmware/status | $JQ -r .status) | |
| if [ "$UPDATE_STATUS" == "error" ]; then | |
| # There is an error and we need to report that via SLACK | |
| notify "OPNsense is reporting error in the update status, please review the website for details." "siren" | |
| elif [ "$UPDATE_STATUS" == "none" ]; then | |
| # There is no update, lets stop here and quit | |
| notify "No updates detected!" "gamelan" | |
| exit 0 | |
| elif [ "$UPDATE_STATUS" == "update" ]; then | |
| # There is an update! | |
| notify "OPNsense has an update!" "alien" | |
| update_message=$($CURL -s -k -u "$FW_USER":"$FW_PASS" https://$FW_HOST/api/core/firmware/status | $JQ -r .status_msg) | |
| notify "$update_message" "alien" | |
| else | |
| # Unknown status | |
| notify "Unknown status" "siren" | |
| fi |
Author
pyrodex
commented
Dec 2, 2025

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment