whereami - Location Actions


Actions

For myself, mostly when I am at a new location I want to configure all of my network to appropriate values.


Configuration

The /etc/whereami/whereami.conf file contains lines much like a normal shell script, but each line is prefixed by:

Situation Context

CharacterSituation in which the action applies
+The 'plus' indicates that this action applies whenever whereami finds that you are at the specified location now, and that you were at a different location last time.
-The 'minus' indicates that this action applies whenever whereami finds that you are not at the specified location, but that you were last time it was run.
=The 'equals' indicates that this action applies whenever whereami finds that you are in this location, regardless of whether your last location was different.

Location Context

The location context may be "any" which will match any location, or an exact match for the names of locations returned from your 'test' scripts.

At some point in the future I will probably rewrite whereami to allow the location context to be a full regular expression matching the location returned by the tests.

To be perfectly honest, the current implementation of whereami is a "quick hack" to implement a framework which I have been thinking about and refining for several years, and I believe that the most important part of this work (other than getting it out the door) is the component framework. A peer review of the component framework will do wonders for gauging its effectiveness in a much wider range of situations than I can experience.

Putting that together

Putting that all together you end up with lines like:

=any savelog -p /home/andrew/.netscape/preferences.js
=any cat /home/andrew/.netscape/preferences.js.0 >>/home/andrew/.netscape/preferences.js

# When we're at Catalyst
+catalyst bind-forwarders 192.168.2.80
+catalyst netscape-option /home/andrew/.netscape/preferences.js smtp_server \"mail.cat-it.co.nz\"
+catalyst setmailrelay mail.catalyst.net.nz

The first two lines above will always go into the beginning of the script that whereami creates (the script will be built with lines in the same sequence as in the configuration file). The following three lines will be included whenever we 'arrive' at Catalyst, firstly to adjust my /etc/named.conf file to set the forwarder to point to our LAN server, the second to set Netscape to send outbound mail though our local mail server, and finally the last one to set /etc/mail/sendmail.cf to use the local mail server as a smart host.

I'm sure someone is wondering why I do both of those last two, but really its just because I'm transitioning from one way to the other. :-)

Your config file can contain full script functionality, so this fragment:

=catalyst if ( grep "^docked" iam >/dev/null ) then
=catalyst   mount /dev/hde1 /dos/f -t vfat
=catalyst   mount /dev/hde2 /dock -t ext2
=catalyst   /root/bin/bkup2dock &
=catalyst fi

will build an 'if' statement and only do the mount and backup if I am docked.


Utility Scripts

The utility scripts are held in /usr/share/whereami, which is added to the end of the path for the execution of the script which whereami generates.

I'm hoping that this section will expand once people other than me start using the program.

bind-forwarders
 
 
This edits your /etc/named.conf file to change to the specified forwarder.

The line will be changed when it contains an IP address followed by a semi-colon, followed by the string "bind-forwarders" For example, a string such as:

		192.168.2.80;	// bind-forwarders

would be a reasonable choice to start with. Each invocation of "bind-forwarders" would then set the IP address appropriately. Naturally this line needs to be in the right location within your /etc/named.conf file.

kill-netscape
 
 
Simply kills all running instances of netscape, first by asking nicely and then escalating to the "terminate with extreme prejudice" signal!

This can be used to ensure that Netscape doesn't ignore changes to the netscape preferences file set with the next script.

netscape-option
 
 
This sets an option in a netscape preferences file.

Use "netscape-option <filename> <option name> <new value>"

You will probably need to review the preferences file yourself to figure the exact names of the options and appropriate values. If your option needs quotes around the value, you will need to put backslashes in front of them.

masqmail_route
 
 
This updates masqmail routing.

Use "masqmail_route <route name> "

Masqmail allows for multiple routing configurations to be set up in /etc/masqmail/masqmail.conf and other masqmail routing files.

See the masqmail.conf(5) man page for full details of the "online_routes" option. You will also want to look at the masqmail.route(5) manpage.

setmailrelay
 
 
This is configured through the /etc/whereami/mail-relay.conf file to set a default mail relay if desired, otherwise the script will change the mail relay in your sendmail or postfix configuration file.

Use "setmailrelay queue" for your 'on the road' configurations and your mail will be queued for sending next time you are on a permanent connection. You can add an optional third agrument, which is the IP or name of the system to use as mail relay when flushing the queue. This overrides the default relay specified in mail-relay.conf, and is handy if you have more than one way of dialing into the internet and need a different mail relay per connection.

Use "setmailrelay none" for when you don't need a smarthost at all and can send mail directly.

Use "setmailrelay " where is the IP or name of the system to use as smarthost from this location.

This script was originally supplied by Jos Visser and I've made a few minor adjustments to suit this use.

setresolver
 
 
 
 
This script is used to adjust your resolv.conf file to suit the current environment.

The setresolver script essentially accepts an entire resolv.conf file on one single command line, separating it into it's correct component parts and inserting it at the start of your existing resolv.conf.

You should review the manpage for resolv.conf (5) for full details of the information in this file, but in basic form you can:

  • search <domain> [<domain> ...]
  • nameserver <ip address> [<ip address>] [<ip address>]

Which is pretty much what you will want to do. The domains listed after the search keyword are the ones that will be appended to any names queried in an attempt to resolve names. As the resolv.conf(5) manpage will tell you though: putting too many names in there can make name resolution slower, so keep it to a minimum.

If you have any suggestions, e-mail them to me and I'll distribute them along with future releases of whereami.

 


Andrew's Linux Page  |   The 'Whereami' Utility  |   Location Detection  |   Whereami Actions  |   © Andrew McMillan, 1999-2004 released under the GPL