comparison .ssh/athome @ 265:df0b24d4fabd

Think I'm ready to check this all in now; shared dotfiles that can be "sent" through an SSH connection to be used and cleaned up when finished.
author Steve Huston <huston@srhuston.net>
date Wed, 24 Apr 2024 16:15:40 -0400
parents
children 33541d73d6d7
comparison
equal deleted inserted replaced
264:bb69763716a7 265:df0b24d4fabd
1 #!/usr/bin/env bash
2
3 # Check to see if we're at home - does our externally routable IP address
4 # match the one on my home network. This should be fast, and needs to be
5 # portable so it works in multiple ways, but if everything else fails we'll
6 # return false which should still allow things to work.
7
8 # Logic swap for negating outputs
9 on=0
10 off=1
11 if [[ "$1" == "--not" ]] ; then
12 shift
13 on=1
14 off=0
15 fi
16
17 # Start by getting our current IP, this is surprisingly easy thanks to Amazon
18 MYIP=`curl -s checkip.amazonaws.com`
19
20 # Now how to get the home IP.. let's loop through ways it's possible
21 HOMEDNS="b6800200.eero.online"
22
23 if which -s getent awk ; then
24 HOMEIP=`getent ahostsv4 $HOMEDNS | awk '{print $1; exit}'`
25 elif which -s dig ; then
26 HOMEIP=`dig +short $HOMEDNS`
27 else
28 exit $off
29 fi
30
31 [[ $MYIP == $HOMEIP ]] && exit $on || exit $off