If yes, the small package "netenv" might be useful for you. When booting your laptop it provides you with a simple interface from which you can choose the current network environment. If you are the first time in an environment, you can enter the basic data for later reuse.
Netenv sets up a file containing variable assignments which describe the current environment. This can be used by the pcmcia setup scheme (e.g. like the one that comes with Debian and perhaps others).
Have a look at netenv's chooser box:
Besides the basic functionality of configuring the network interface, the netenv data can be used for thinks like:
Think of using your laptop standalone with touchpad vs. connected to a CRT monitor along with an external mouse.
You can set up your windowmanager according to the current location of your machine.
The netenv data can easily be used to set up the printing environment.
Netenv is available as Debian package as well as tarball. It depends on dialog(1) for the menu system.
A word to all gurus: In this docu I try to explain things with Linux novices in mind, so be patient.
You may start reading about Basics, or begin with Installation. Having the Debian package you should be able to proceed to Configuration.
But if you are like me, you may want to directly jump to my Examples section. For those of you who really reach this line, here is a link to all the other stuff.
This is done using dialog(1), thus providing a well known user interface. This way choosing a network environment is quite comfortable. For details see below.
Alternatively you can input on the boot prompt. This is done as follows: When "lilo" prompts, type e.g.
linux NETENV=offThis sets up a shell variable "NETENV", containing "off" (this means for me: I'm attaching my laptop to the LAN in the office). The kernel starts the init process with "NETENV" as part of its environment, so does init. So the netenv script can check for "NETENV".
After having set up NETENV, a corresponding configuration file located in /etc/netenv is copied to /tmp/netenv, eg. /etc/netenv/lulu-off, being on a machine named lulu, having entered linux NETENV=off. When using a pcmcia network adapter, it is no longer necessary to deal with /etc/pcmcia/network.opts. Replace the assignment section in this file simply with
. /tmp/netenv/tmp/netenv is world readable and can be used by user processes for additional setup tasks, see the Examples section.
All the others should untar the netenv package. It consists of the shell script called - you guessed it - netenv, example configuration files and documentation files.
You should copy the script netenv to the proper place. This can be /etc/init.d, but that depends ... Probably you may want to make a link, so that netenv is executed when your laptop comes up to run level 2. There is no need to do anything when the laptop is shut down.
Obviously netenv should be run before the network setup starts.
On a Debian system this is done by putting netenv in the directory /etc/rc.boot. You probably will find there 0setserial. You then may copy netenv to /etc/rc.boot/1netenv. To deal with the pcmcia setup scheme via network.opts as mentioned before, you may copy my network.opts to /etc/pcmcia.
/etc/netenv/<NODE-NAME>-<VALUE-OF-VARIABLE-NETENV>The files in /etc/netenv contain assignments in shell syntax, e.g.
IPADDR=123.456.78.9 DOMAIN=buzz.foobar.orgNow you really should have a look in the Examples section ...
I would like to explain two example configurations. My laptop's node name is lulu. This laptop is my main machine even at home, where I use it connected to external CRT, keyboard and mouse.
This is the netenv-file, which I simply call /etc/netenv/lulu, thus making it the default:
netenv_id=Laptop_at_home_crt_3button_mouse export PROFILE=30 IPADDR=192.168.123.2 NETMASK=255.255.0.0 NETWORK=192.168.0.0 BROADCAST=192.168.255.255 GATEWAY=192.168.123.1 DOMAIN=rw.sni.de DNS_1=123.123.12.12 export PRINTER=printer-nana-deskjet NETENV_SCRIPT=/etc/netenv/netenv_setup XF86CONFIG_FILE=/etc/X11/XF86Config-crtYou will find this file in the doc-subdirectory.
As I hopefully mentioned earlier, this file is sourced by shell scripts, so shell syntax rules apply. Everthing on a line after a hash is comment only.
The line
netenv_id=Laptop_at_home_crt_3button_mousedefines the verbose description in netenv's chooser box. Please, do not use spaces here. You have been warned ...
netenv_id=This_string_must_contain_no_blanks_nor_special_charactersIf the assignment netenv_id is not found, the entry will be labeled "unknown".
PROFILE=30I use this variable for setting up my windowmanager according to the current location of my laptop. I still use fvwm95. To have the details look at my .fvwm95rc-cpp. This file is precompiled by means of the variable "PROFILE". This way I can use one source for different displays and so on, see http://www.ssc.com/lg/issue21/fvwm.html
IPADDR=192.168.123.2 NETMASK=255.255.0.0 NETWORK=192.168.0.0 BROADCAST=192.168.255.255 GATEWAY=192.168.123.1 DOMAIN=rw.sni.de DNS_1=123.123.12.12This defines netenv's basic functionality: It sets up my network interface as well as /etc/resolv.conf. Look at my remarks on the DNS stuff. As I connect to the net transparently via an ISDN router, setting GATEWAY is important.
Last not least this is the right place to define once and only once my printing environment:
export PRINTER=printer-nana-deskjet export COLOR_PRINTER=printer-off-color-deskjetOf course I source this in my .xsession. Look at this snippet:
if [ -r /tmp/netenv ]; then . /tmp/netenv fiFor the whole story here is my .xsession and my .Xdefaults
But what is this:
NETENV_SCRIPT=/etc/netenv/netenv_setupIf netenv finds an executable under this filename, it will execute it (to be precise: source it).
Beware ! This is run during early stage of going multi user ! No network setup has been done yet ! It's done as root ! You have been warned !
So far legal terms and conditions. This is my script:
#!/bin/sh # Simple way to configure the X-Server if [ -r $XF86CONFIG_FILE ]; then echo $XF86CONFIG_FILE will be used for configuring the X-Server ... mv /etc/X11/XF86Config /etc/X11/XF86Config.old ln -s $XF86CONFIG_FILE /etc/X11/XF86Config fiAs you can see it depends on a variable XF86CONFIG_FILE. That is why my netenv configurations file has this line
XF86CONFIG_FILE=/etc/X11/XF86Config-crtOf course there are other ways of switching between different X-server setups - hey, this is Linux ! The one I choosed has the disadvantage, that you have to define the variable XF86CONFIG_FILE in each netenv-file. So, if you are on the LCD and the Xserver comes up with the CRT-XF86Config, you know what to change ...
# Networkenvironment: Laptop at office (Network-Interface: Ethernet) netenv_id=Laptop_at_office PROFILE=31 IPADDR=123.123.35.134 NETMASK=255.255.255.0 NETWORK=123.123.35.0 BROADCAST=123.123.35.255 GATEWAY=123.123.35.1 DOMAIN=rw.sni.de DNS_1=123.123.12.12 export PRINTER=printer-off-ps export COLOR_PRINTER=printer-off-color-deskjet NETENV_SCRIPT=/etc/netenv/netenv_setup XF86CONFIG_FILE=/etc/X11/XF86Config-lcdThere are no substantial differences. I use the laptop's LCD, the ethernet card is configured with appropiate values, the printing environment changes.
# Update DNS stuff cp /etc/resolv.conf /etc/resolv.new echo "# $DEVICE begin" >> /etc/resolv.new test "$DOMAIN" && echo "domain $DOMAIN" >> /etc/resolv.new if [ "$DNSSRVS $DNS_1 $DNS_2 $DNS_3" != " " ] ; then for DNS in $DNSSRVS $DNS_1 $DNS_2 $DNS_3 ; do echo "nameserver $DNS" >> /etc/resolv.new done fi echo "# $DEVICE end" >> /etc/resolv.new mv /etc/resolv.new /etc/resolv.confThe file /etc/resolv.conf is copied to a temporary file. If any of the variables DOMAIN, DNSSRVS, DNS_1, DNS_2 or DNS_3 have a value not equal null, the appropiate commands will be added. This new section is starts with e.g. # eth0 begin and ends with e.g. # eth0 end. This is needed when stopping the pcmcia services to remove the section. Your /etc/resolv.conf will then be in the original state.
# Networkenvironment: Tower at home (Network-Interface: Plip) export PROFILE=10 PLIP_START=yes PLIP_IPADDR=200.0.0.1 PLIP_PARTNER=lulu PRINTER=home-deskjetTo be able to do so, plip MUST be called after kerneld is started ! (plip is available only as module, eventually the module lp has been inserted already, see the script for further details).