whereami - Location Actions

| # whereami - Actions

## Actions

When I arrive at a new location the main thing I need to do is configure networking.

- I run a nameserver on my laptop and I want to configure that to use the local network nameserver as a forwarder
- I want to configure sendmail to use the local mailserver as a relay
- I want to change my Netscape settings to operate appropriately with the caches and proxies at the location
- I want to mount appropriate local network drives
- When I'm docked, I want to save any changes to various important files onto a disk in the docking station

## Configuration

The `/etc/whereami/whereami.conf` file contains lines much like a normal shell script, except that each line is prefixed by a string consisting of:

- a character indicating the circumstances in which the action applies
- the name of the location to which this action relates

#### Circumstances

Character | Situation in which the action applies
--- | ---
+ | The 'plus' sign indicates that this action will be performed when the system arrives at the specified location: that is, the system is now at the specified location but was previously at another location
- | The 'minus' sign indicates that this action will be performed when the system has left the specified location: that is, the system was previously at the specified location but is now at another location
= | The 'equals' sign indicates that this action will be performed when the system is now at the specified location regardless of where it was previously

#### Location

The location name may be one of those detected, or 'any', which matches any location. At some point in the future I will probably rewrite whereami to allow the location specification to be a regular expression.

#### Examples

Putting it 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 apply. The following three lines will apply whenever we 'arrive' at Catalyst. First `/etc/named.conf` will be modified so that named uses the DNS server on the LAN as a forwarder; second, Netscape will be configured to send outbound mail through the local mail server; finally, `/etc/mail/sendmail.cf` will be modified so that sendmail uses the local mail server as a relay.

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. :-)

The file can contain full shell 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 execute an 'if' statement and only do the mount and backup if the machine is docked.

## Action scripts

A number of useful scripts are included in the directory `/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 myself start using the program.

bind-forwarders | Use: "bind-forwarders <ip-address>" 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 place in your /etc/named.conf file.
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 <smarthost>" where <smarthost> is the IP name or address of the system to use as a mail relay 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.

whereami | Location Detection | © Andrew McMillan, 1999-2005 released under the GPL