Mercurial > index.cgi > dotfiles
annotate .ssh/athome @ 271:e7e331a51f2c
Just remove the -s option since we're redirecting anyway
author | Steve Huston <huston@princeton.edu> |
---|---|
date | Thu, 25 Apr 2024 13:59:42 -0400 |
parents | 6dc992e4fc4a |
children |
rev | line source |
---|---|
265
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
1 #!/usr/bin/env bash |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
2 |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
3 # Check to see if we're at home - does our externally routable IP address |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
4 # match the one on my home network. This should be fast, and needs to be |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
5 # portable so it works in multiple ways, but if everything else fails we'll |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
6 # return false which should still allow things to work. |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
7 |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
8 # Logic swap for negating outputs |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
9 on=0 |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
10 off=1 |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
11 if [[ "$1" == "--not" ]] ; then |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
12 shift |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
13 on=1 |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
14 off=0 |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
15 fi |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
16 |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
17 # Start by getting our current IP, this is surprisingly easy thanks to Amazon |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
18 MYIP=`curl -s checkip.amazonaws.com` |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
19 |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
20 # Now how to get the home IP.. let's loop through ways it's possible |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
21 HOMEDNS="b6800200.eero.online" |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
22 |
271
e7e331a51f2c
Just remove the -s option since we're redirecting anyway
Steve Huston <huston@princeton.edu>
parents:
270
diff
changeset
|
23 if which getent awk > /dev/null 2>&1 ; then |
265
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
24 HOMEIP=`getent ahostsv4 $HOMEDNS | awk '{print $1; exit}'` |
271
e7e331a51f2c
Just remove the -s option since we're redirecting anyway
Steve Huston <huston@princeton.edu>
parents:
270
diff
changeset
|
25 elif which dig > /dev/null 2>&1 ; then |
265
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
26 HOMEIP=`dig +short $HOMEDNS` |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
27 else |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
28 exit $off |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
29 fi |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
30 |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
31 [[ $MYIP == $HOMEIP ]] && exit $on || exit $off |