"Linux Gazette...making Linux just a little more fun!"


Using a Laptop in Different Environments

By Gerd Bavendiek, [email protected]


Do you use a laptop at home ? In the office ? At a customers site ?

If yes, you should read on. I would like to show you how I integrate my laptop in different network environments. The basic idea is really simple. Using lilo as bootmanager, I boot with an additional variable assignment. The kernel passes this to the init-processes shell environment. So all processes started by init can use it. Example:

linux netoff=

This sets up the variable netoff. It is assigned nothing. I use it as a flag meaning "now I am in the office". Booting with linux netetc= means "now I am at customer site". Using lowercase variable names is just for convenient typing. If you prefer, you can use something like NETENVIRON=123.

The real work of processing this variables is done in my /etc/init.d/netenv. Take a look at this code fragment:

NETENV=/tmp/netenv	# When located in /tmp, script must be called
                        # AFTER wiping out /tmp has been done ...

...

elif env | grep '^netoff=' > /dev/null; then
   (
   echo ""# Networkenvironment: Laptop at office (Network-Interface: Ethernet)"
   echo "export PROFILE=31"
   echo "IPADDR=\"123.456.78.123\""
   echo "NETMASK=\"255.255.255.0\""
   echo "NETWORK=\"123.456.78.0\""
   echo "BROADCAST=\"123.456.78.255\""
   echo "GATEWAY=\"123.456.78.1\""
   echo "DOMAIN=\"rw.sni.de\""
   echo "DNS_1=\"123.456.89.9\""

   echo "export RLPR_PRINTHOST=printer-off"
   echo "export PRINTER=pr1"
   ) > $NETENV
elif env | grep '^netetc=' > /dev/null; then
   (
   echo "# Networkenvironment: Laptop at customer site (Network-Interface: Ethernet)"
   echo "export PROFILE=32"
   
   ...

   echo "export RLPR_PRINTHOST=printer-etc"
   echo "export PRINTER=pr1"
   ) > $NETENV
Output ist written to a world readable file. Scripts which shall use the assignments simply have to do something like

. /tmp/netenv

For further details you may refer to the included netenv.

As you can see from the code, I do assign not only network stuff, but also a Variable PROFILE as well as printing stuff. This makes it possible, to have e.g. ONE .fvwm95rc.

I would like to show you how to do that when I come back from my vacation.

So far !

Kind regards

Gerd


Gerd Bavendiek


Copyright © 1997, Gerd Bavendiek
Published in Issue 20 of the Linux Gazette, August 1997


[ TABLE OF CONTENTS ] [ FRONT PAGE ]  Back  Next