This morning, Wouter blogged about whereami and guessnet. I once tried using these tools as well, but found them to be too deterministic, whereas my networking setups are often somewhat more wishy washy. As Wouter notes, even deterministically, the tools don't really work all that well.
Instead of trying to let my laptop guess where I am based on potentially variable environment "constants", I prefer to tell my laptop precisely what to do based on what I know to be true.
To this end, I use a number of shell-scripts under $HOME/bin with a naming convention of @location. For instance, my @home script looks like this:
#!/bin/sh
IFACE=ath0
CONF=/etc/wpa_supplicant.conf
sudo rmmod ath_pci
sudo modprobe ath_pci
sudo iwpriv ath0 mode 11g
sudo ifconfig ath0 down
sudo ifconfig ath0 up
sudo rm -rf /etc/dhcpcd
sleep 10
echo running wpa_supplicant
sudo /usr/local/sbin/wpa_supplicant -D madwifi -c ${CONF} -i ${IFACE} -Bw
sleep 5
echo running dhcpcd
sudo dhcpcd -d -o ${IFACE}
sudo ntpdate angua.home.paeps.cx
rm -f $HOME/@*
touch $HOME/@home
ssh-add
I am well aware that this looks unbelievably hackish. But therein lies the flexibility of the system. If I change some network parameter at home, I have only to hack the relevant magic into my script.
Many of the tools I use have wrapper scripts in $HOME/bin and behave differently based on the presence of @* files under $HOME. For instance, svn will automatically call svn switch --relocate when it sees that I am home or away. Other wrapper scripts are a bit more tricky. Such as this one for Mutt:
#!/bin/sh
if [ -f $HOME/@home ]; then
HOST=carrot.home.paeps.cx
PORT=22
elif [ -f $HOME/@work ]; then
HOST=localhost
PORT=2222
else
HOST=home.paeps.cx
PORT=2202
fi
pgrep awesome >/dev/null
rc=$?
if [ $rc = 0 ]; then
URXVT="urxvtc -name mutt -e"
else
URXVT=
fi
exec $URXVT ssh -p ${PORT} -t ${HOST} mutt
There is a script on carrot which tries to attach to a screen running Mutt or starts a new one.
I like things to be simple. Don't guess. Know!
Copyright © 2005–2010 Philip Paeps
All rights reserved.