26 Apr 2009
One of the features that I miss from OS X is a degree of location awareness. As shipped, it's nothing too special, but when combined with Marco Polo it becomes fantastically effective. There's no real equivalent under Ubuntu. The closest offering is a package called whereami by Andrew McMillan. It is a rule based approach to automatically configuring network access, so out of the box it duplicates much of the functionality of NetworkManager. Rather then sensing current network settings as Marco Polo does, it attempts to configure each interface in order, as defined in detect.conf. Once it has determined what location(s) are relevant, it will perform actions as defined in whereami.conf. There are good manpages for both files. The multiple location bit is surprisingly handy. I've defined openvpn as any location that is not home, for example. Including whereami, Ubuntu would have three different network configuration systems in place: /etc/network/interfaces, whereami and NetworkManager, each with different abilities. However, whereami adheres to the unix philosophy; each individual test is a separate script. So it is possible to make whereami and NetworkManager to play nice with eachother, providing those tests are non-destructive. To that end I've written to little shell scripts:
- testif will return 0 if an interface is configured and running.
- testip will return 0 if an interface has a configured ip address in a given range.
default unknown # Assume VPN access. always at openvpn # What interfaces are up? (or present?) always testif eth0 wired always testif ra0 wireless # Wired networking takes priority. if wired set INTERFACE eth0 notat wireless elif wireless set INTERFACE ra0 else # No connectivity; running a VPN won't help. notat openvpn fi testip 192.168.235.1/24 home testip 184.108.40.206/16 uoguelph # Networks where I don't need a VPN. if home notat openvpn endSo now whereami doesn't attempt to reconfigure any interfaces. The next step is to have NetworkManager call whereami on any kind of status change. Fortunately, Olivier Berger already figured that one out. An appropriate shell script in /etc/NetworkManager/dispatcher.d will call whereami on if-up and if-post-down events. I've included a copy of Olivier's script here, as his website has inserted unicode quotes. So, now whereami is called on interface changes identified by NetworkManager. Lastly, I wanted to have some kind of spiffy notifier, to match the rest of Ubuntu 9.04. The trick here is to use notify-send. It's a command line utility, that is part of the libnotify-bin package. Here's an example whereami.conf that shows how to call notify-send as a root user. This solution is not tightly integrated. The FreeDesktop people are doing something much more sophisticated with geoclue, that will probably suit the gnome philosophy a little better. But this works pretty well for only a few hours of hacking.
02 Apr 2009