Dmitry S. Makovey <dmitry <at> athabascau.ca> writes:

> 
> Hi everybody,
> 
> Brief:
> I've got simple question: is it possible to support multiple environment 
> configuration with gentoo like "netenv" in Debian?
> 
> Full:
> I've got laptop which I use in several different environments: home, office, 
> presentation, server room, etc. Each requires number of configuration files 
> to be altered (xorg.conf, net, hostname, etc.) and different services to be 
> run.  Now I've read about custom "run-levels" for gentoo but couldn't figure 
> out how to apply it to different sets of config files. 
> 
> So far I've developed set of scripts to manage environment changes by simply 
> copying files from /etc/laptop.d/<env_name> to /etc so everything works fine, 
> BUT when I try to use those scripts on startup I have a problem: I need to 
> run my script after local systems are mounted (I have helper scripts 
> in /usr/local/sbin so I can reconfigure laptop "on-the-fly" without reboot) 
> but before hostname is set up and network interfaces are brought up. Doing 
> any combination of "after", "before" and "needs" in my rc-script I just can't 
> make it run when I need it to (i.e. just after localmount and before 
> hostname).
> 
> Any suggestions and hints are welcome.
> 

Hi,

i resolved this problem in the following way:

1) i created several entries in grub.conf for the same kernel, passing a kernel
parameter like this:
kernel (hd0,5)/boot/kernel-2.6.8.r3 root=/dev/hda6 acpi=on netlocation=home

The name of the parameter has been chosen by me.

2) i created a script that is executed during startup with the following action:
<snip>
#!/bin/sh
# description: copy network config file according to boot parameters

netlocation=
for copt in $(< /proc/cmdline)
   do
     case "${copt%=*}" in
         "netlocation")
             netlocation="${copt##*=}"
             ;;
     esac
   done
if [ -n ${netlocation} ]
then
    cp /etc/conf.d/netlocation/${netlocation}/net /etc/conf.d/net
    cp /etc/conf.d/netlocation/${netlocation}/hosts /etc/hosts
fi
exit 0
</snip>

This examines the command line of the kernel for the existence of the parameter
netlocation, takes it value to construct a path and copies the files found there
in the right positions.

3) created the folders required (see the two cp statements at the end of the
script).

This can be extended to almost any config file, maybe there should be a test for
existence of each file before copying to have the choice which files will be
overwritten for each configuration.

Best regards,

Jens




--
gentoo-user@gentoo.org mailing list

Reply via email to