Mercurial > index.cgi > dotfiles
view .ssh/athome @ 266:33541d73d6d7
RHEL8 at least has different syntax for which, this should allow both to work
without incident
author | Steve Huston <huston@princeton.edu> |
---|---|
date | Wed, 24 Apr 2024 16:53:52 -0400 |
parents | df0b24d4fabd |
children | 6dc992e4fc4a |
line wrap: on
line source
#!/usr/bin/env bash # Check to see if we're at home - does our externally routable IP address # match the one on my home network. This should be fast, and needs to be # portable so it works in multiple ways, but if everything else fails we'll # return false which should still allow things to work. # Logic swap for negating outputs on=0 off=1 if [[ "$1" == "--not" ]] ; then shift on=1 off=0 fi # Start by getting our current IP, this is surprisingly easy thanks to Amazon MYIP=`curl -s checkip.amazonaws.com` # Now how to get the home IP.. let's loop through ways it's possible HOMEDNS="b6800200.eero.online" if which -s getent awk > /dev/null 2>&1 ; then HOMEIP=`getent ahostsv4 $HOMEDNS | awk '{print $1; exit}'` elif which -s dig ; then HOMEIP=`dig +short $HOMEDNS` else exit $off fi [[ $MYIP == $HOMEIP ]] && exit $on || exit $off