Customizing Cups Default Printer using NetworkManager

Recently I discovered the scripting abilities of NetworkManager. I
finally wrote a very small script which calls lpadmin depending on my
current network environment.

NetworkManager looks for scripts in
/etc/NetworkManager/dispatcher.d. Currently I have:

lulu:/etc/NetworkManager/dispatcher.d> ls
01ifupdown 97customize-lulu

01ifupdown came with Karmic, 97customize-lulu is my new script.
NetworkManager calls the scripts in /etc/NetworkManager/dispatcher.d
with two arguments. If I e.g. plug in a patch cable with WLAN
disabled, the scripts will be run like so:

01ifupdown eth0 up
97customize-lulu eth0 up

In my 97customize-lulu, I figure out the current IPADDRESS using the
ip-command and a bit of perl. In a simple case I call lpadmin
appropriately. Finally I call logger to get some information in my

When the script is called to unconfigure a nic, I umount all NFS and
CIFS based filesystems to avoid hanging IOs.


case "$2" in
IPADDRESS=`ip -o addr show $NIC | perl -ne 'if(/inet ([\d\.]*)\/\d\d/) {print $1, "\n";}'`
case "$IPADDRESS" in
192.168.178.*) lpadmin -d Home-HP-OfficeJet-G85
lpadmin -d Lab-X
172.18.*.*) lpadmin -d Site-Foo
logger 97customize-lulu: NIC: $NIC ACTION: $ACTION IP: $IPADDRESS
umount -a -t nfs,cifs
logger 97customize-lulu: NIC: $NIC ACTION: $ACTION IP: $IPADDRESS RC$


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: