f.zz.de
posts /

roaming and printing

Posted Sun 01 Nov 2009 11:04:23 AM CET
in

I always wanted my laptop to automatically detect my network location and set some configs for the location. One of the problematic areas was printing. I have a print server everywhere and probably a default printer - but i dont want to select the right print server everytime i move subnet etc ... So i cam up with this solution which is based on network-manager (yeah i know - bad software) and cups (client only - no server e.g. cupsys)

/etc/NetworkManager/dispatcher.d/02printer

`

!/bin/sh

IFACE="$1"
ADDRESS=$DHCP4_IP_ADDRESS

remove_printerconf() {
rm -f /etc/cups/client.conf
}

detect_location() {
place=""

case "$ADDRESS" in
195.71.4.|195.71.5.)
place="work"
;;
193.189.251.*)
place="home"
;;
esac

/usr/bin/logger -p daemon.info -t location Found location to be ${place} for ip adress ${ADDRESS}

rm -f /etc/cups/client.conf

if [ -f /etc/cups/client.conf.${place} ]; then
/usr/bin/logger -p daemon.info -t location Setting new printer config
ln -s /etc/cups/client.conf.${place} /etc/cups/client.conf
fi
}

case "$2" in
up)
detect_location
;;
down)
remove_printerconf
;;
esac
`

So basically - whenever a new interface comes up i check for its ip address and have it set a symlink for /etc/cups/client.conf - The only problem left is with network-managers bad habit of connecting the wireless additionally to the wired network - so i have both networks connected and they'll come up one
after the other ...