Skip to content

Instantly share code, notes, and snippets.

@rjhornsby
Last active March 5, 2016 14:15
Show Gist options
  • Save rjhornsby/4d96a5e701923b1d6096 to your computer and use it in GitHub Desktop.
Save rjhornsby/4d96a5e701923b1d6096 to your computer and use it in GitHub Desktop.
Shell script to notify if the GFNB software version changes
#!/bin/bash
# We will try to determine your GFNB address automatically by using
# your system's gateway address.
#
# If that doesn't work, or you want to override the detected
# value, uncomment the following line and set the value you want
#
# gfnb_ip=192.168.1.1
# Where do you want the notifications sent?
# use /dev/null to turn off email notifications
[email protected]
# tmp location where logs and state file will be stored
tmp=~/tmp
# Don't change anything below this line #
# Try to guess the gfnb IP address
if [ -z $gfnb_ip ]; then
os=$(uname)
case $os in
'Darwin')
gateway=$(netstat -rn -f inet | awk '/^default/ {print $2}')
;;
'Linux')
gateway=$(route -n | awk '/^0.0.0.0/ {print $2}')
;;
*)
if [ -z "$gateway" ]; then
echo 'Unable to reliably determine your gateway address. Please set gfnb_ip'
exit 1
fi
;;
esac
gfnb_ip=$gateway
fi
mkdir -p $tmp 2> /dev/null
gfnb_ver=$tmp/gfnb_ver
log=$tmp/gfnb_ver.log
if [ ! -e $gfnb_ver ]; then touch $gfnb_ver; fi
prev_ver=$(cat $gfnb_ver)
curr_ver=$(curl -s "http://$gfnb_ip/content.json?checksum=0&_=0" | ruby -rjson -e 'puts JSON.parse(STDIN.read)["softversion"]')
if [[ ! -z $prev_ver && $prev_ver != $curr_ver ]]; then
echo "$(date): Version changed to $curr_ver" >> $log
mail -s "gfnb version change" $mail_to < $log
fi
echo $curr_ver > $gfnb_ver
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment