Subject: Multiple boot-up configurations
To: None <current-users@netbsd.org>
From: Darren Reed <darrenr@reed.wattle.id.au>
List: current-users
Date: 09/29/1999 23:21:43
--ELM938611303-27475-0_
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

Tired of having to manually reconfigure your laptop every time you
boot it up in a new environment without dhcp ?  Then maybe these
patches will help you.  Having brought up the idea on icb of having
a network and non-network bootup config for laptops, matt suggested
using subdirectories - a rather potent clue which I was lacking.
Anyway, the result is that if you run 'newbtconf init', it will create
a directory in /etc called etc.network, create a symbolic link called
etc.current to that and move a bunch of config files into there (fstab,
ifconfig.*, rc.conf, etc) with symlinks to them all via /etc/etc.current
back to their normal place in /etc.  So /etc/fstab -> etc.current/fstab
and etc.current -> etc.network.  To create alternate bootup configurations,
after the initial one, do 'netbtconf newconf' or 'netbtconf newconf orig'
if you would rather base 'newconf' on 'orig' rather than 'current'.  So
once you have done all that and have applied the rc patch below, when you
reboot you should get a prompt like this (to which you have 30 seconds to
answer and press return):

[network]
Which configuration [network] ?

If you have multiple configurations, it might appear like this:

train [network] home work1 work2
Which configuration [network] ?

the []'s signify the `default' selection.  Unfortunately, there isn't a
little clock ticking down from 30 to 0 and nor does it stop when you press
a key.  A dedicated C program could do that but I don't know if that's
worth it or making the timeout is better...

Anyway, is it worthy of committing or should it just stay a curiosity ?

Darren

--ELM938611303-27475-0_
Content-Type: text/plain; charset=US-ASCII
Content-Disposition: attachment; filename=rc.diff
Content-Description: patch for /etc/rc
Content-Transfer-Encoding: 7bit

*** rc.dist	Mon Sep 16 13:45:42 2019
--- rc	Wed Sep 29 06:15:19 1999
***************
*** 106,111 ****
--- 106,152 ----
  
  mount_critical_filesystems local
  
+ if [ -e /etc/etc.current ] ; then
+ 	if [ -h /etc/etc.default ] ; then
+ 		def=`ls -ld /etc/etc.default 2>&1`
+ 		default=`expr "$def" : '.*-> etc\.\(.*\)' 2>&1`
+ 	else
+ 		default=current
+ 	fi
+ 	spc=""
+ 	conflist=`cd /etc; ls -1d etc.* 2>&1 | egrep -v 'current|default'`
+ 	for i in $conflist; do
+ 		name=`expr $i : 'etc\.\(.*\)' 2>&1`
+ 		if [ $name = $default ] ; then
+ 			echo -n "${spc}[${name}]"
+ 		else
+ 			echo -n "${spc}${name}"
+ 		fi
+ 		spc=" "
+ 	done
+ 	echo
+ 	master=$$
+ 	conf=/etc/passwd
+ 	while [ ! -d /etc/etc.$conf ] ; do
+ 		trap 'conf=$default; echo; echo Using default of $conf' 14
+ 		echo -n "Which configuration [$default] ? "
+ 		(sleep 30 && kill -ALRM $master) >/dev/null 2>&1 &
+ 		read conf
+ 		trap "" 14
+ 		if [ -z $conf ] ; then
+ 			conf=$default
+ 		fi
+ 		if [ ! -d /etc/etc.$conf -a ! -h /etc/etc.$conf ] ; then
+ 			conf=/etc/passwd
+ 		fi
+ 	done
+ 	rm -f /etc/etc.current
+ 	ln -s /etc/etc.$conf /etc/etc.current
+ 	if [ -f /etc/rc.conf ] ; then
+ 		. /etc/rc.conf
+ 	fi
+ fi
+ 
  # set hostname, turn on network
  echo 'starting network'
  sh /etc/netstart

--ELM938611303-27475-0_
Content-Type: text/plain; charset=US-ASCII
Content-Disposition: attachment; filename=newbtconf
Content-Description: script to create new boot conf directories
Content-Transfer-Encoding: 7bit

#!/bin/sh
#
# Setup a new config directory
#
if [ $# -lt 1 ] ; then
	echo "Usage: $0 <newconfig> [<baseconfig>]"
	echo "Usage: $0 init"
	exit 1;
fi
dir=$1

if [ $dir = init ] ; then
	if [ -d /etc/etc.network -o -e /etc/etc/current ] ; then
		echo "Error: multi-configuration already initialized"
		exit 1
	fi
	dir=etc.network
	cd /etc
	mkdir -m 755 $dir
	ln -s $dir etc.current
	ln -s $dir etc.default
	for i in fstab rc.conf netstart mrouted.conf ntp.conf \
		 nsswitch.conf rbootd.conf inetd.conf ifconfig.*; do
		if [ -f $i ] ; then
			mv $i $dir
			ln -s etc.current/$i .
		fi
	done
	echo "/etc/$dir has now been created and populated."
	exit 0
fi

if [ "`expr $dir : 'etc\.\(.*\)'`" != $dir ] ; then
	dir=etc.$dir
fi
if [ -e /etc/$dir ] ; then
	echo "Error: $dir already exists"
	exit 1;
fi
newname=`expr $dir : 'etc.\(.*\)'`
if [ $# -lt 2 ] ; then
	orig=etc.current
	echo "Using current config as base for $newname"
else
	orig=$2
fi

if [ "`expr $orig : 'etc.\(.*\)'`" != $orig ] ; then
	orig=etc.$orig
fi

mkdir -m 755 /etc/$dir
cp -p /etc/$orig/* /etc/$dir
echo "/etc/$dir has now been created and populated."
exit 0

--ELM938611303-27475-0_--