whereami - Location Tests


Tests

whereami will run all scripts in the /etc/whereami/tests directory until one sets the LOCATED variable to 1.

Each script should echo location information onto the end of the ./iwillbe file, and the last line of this file is expected to indicate the new location.


Examples

In my situation I have around 7 different locations I want to identify:

I don't currently have scripts to detect all of these situations, but the ones that are most important to me are when I am in a client's office for a week and I need to be able to get onto the internet and send/receive my e-mail without jumping through hoops.

In most of these situations DHCP is set up, which makes things quite a bit easier because I can assume that the network adapter is already configured when whereami is run. At Catalyst I also use the lspci command to see if my computer is in its docking station.

For the home network I don't have DHCP set up yet, so my last check is to ifconfig the adaptor to my home network address and try and ping the server (yeah, I should use 'divine' :-)

Since the docking station doesn't mean that I'm at Catalyst (in a 'network' sense), I do that check first, followed by checks for all of the DHCP addresses I might have assigned. Fortunately these all assign addresses on different class C ranges, so I don't have to get complicated and do 'nslookups' on assigned IP addresses and so forth, but the possible approaches are almost endless.

If all of the DHCP addresses failed, then I attack the addresses that have to be probed. If they fail then I must be 'somewhere else' and I configure the system as if I wasn't on a network at all. At this point a utility called 'divine' can come into play. 'Divine' uses some of the more arcane aspects of TCP/IP networking to quickly identify the local network topography (much faster than an 'ifconfig; .. ping' loop). Unfortunately it is not yet packaged for Debian yet (9th October 1999) but I hear rumbles, so it should be soon...

Someday I will set some 'inertia' on the current location so that the last active location will weight my system's decision so that if I was last in Auckland it will assume that, since I am now off-line, I must be off-line in Auckland (so it could configure the defaults for ppp appropriately).


Constructing the Scripts

If you want, you can have a single script that works out your location, puts it into the ./iwillbe file, sets LOCATED=1 and returns. My examples don't do this simply because I find it easier to concentrate on finding out one thing at a time.

Having the detection of each location written in a separate script means that if you want a location to not be detected any longer, just move the script out of the 'tests' directory. If you have a new location that you want to add, just copy a similar example and change a couple of lines and its done.

Having the detection logic for each location in its own script makes these scripts very simple to put together (in general, anyway).

That said: one script, many scripts or something in between. You will make the decision they're all valid. If you're not string at scripting keep them separate and you'll find it easier to understand what each one is doing.


Having found out where you are, what actions do you want your system to take?

 


Andrew's Linux Page  |   The 'Whereami' Utility  |   Whereami Tests  |   Whereami Actions  |   © Andrew McMillan, 1999-2000 released under the GPL