Home | History | Annotate | Line # | Download | only in newbtconf
newbtconf.sh revision 1.8.96.1
      1 #!/bin/sh
      2 #
      3 # Setup a new config directory
      4 #
      5 if [ $# -lt 1 ] ; then
      6 	echo "usage: $0 <newconfig> [<baseconfig>]"
      7 	echo "usage: $0 init"
      8 	echo "usage: $0 revert"
      9 	exit 1;
     10 fi
     11 dir=$1
     12 
     13 FILES="defaultdomain fstab ifconfig.* inetd.conf mrouted.conf \
     14 	mygate myname netstart nsswitch.conf ntp.conf \
     15 	rc.conf rc.conf.d resolv.conf"
     16 
     17 if [ $dir = init ] ; then
     18 	if [ -d /etc/etc.network ] || [ -e /etc/etc.current ] ; then
     19 		echo "Error: multi-configuration already initialized"
     20 		exit 1
     21 	fi
     22 	dir=etc.network
     23 	cd /etc
     24 	mkdir -m 755 $dir
     25 	ln -s $dir etc.current
     26 	ln -s $dir etc.default
     27 	for i in ${FILES}; do
     28 		if [ -f $i ] || [ -d $i ] ; then
     29 			mv $i $dir
     30 			ln -s etc.current/$i .
     31 		fi
     32 	done
     33 	echo "/etc/$dir has now been created and populated."
     34 	exit 0
     35 fi
     36 
     37 if [ $dir = revert ] ; then
     38 	if [ !  -d /etc/etc.current ] ; then
     39 		echo "Error: multi-configuration not initialized"
     40 		exit 1
     41 	fi
     42 	cd /etc
     43 	for i in ${FILES}; do
     44 		if [ -f $i ] || [ -d $i ] ; then
     45 			stat="`ls -ld $i`"
     46 			case x"$stat" in
     47 				xl*) :;;
     48 				x*)
     49 				echo "$i: not a symlink, skipping"
     50 				continue ;;	
     51 			esac
     52 			linkto="${stat##*-> }"
     53 			case x"$linkto" in
     54 				xetc.current/*) :;;
     55 				x*)
     56 				echo "$i: does not symlink to etc.current, skipping"
     57 				continue ;;
     58 			esac
     59 			if [ -f $i ] ; then
     60 				rm $i
     61 				cp -p $linkto $i
     62 			else
     63 				rm $i
     64 				( cd etc.current && pax -rw -pe $i /etc )
     65 			fi
     66 		fi
     67 	done
     68 	rm etc.current
     69 	rm etc.default
     70 	exit 0
     71 fi
     72 
     73 if [ "`expr $dir : 'etc\.\(.*\)'`" != $dir ] ; then
     74 	dir=etc.$dir
     75 fi
     76 if [ -e /etc/$dir ] ; then
     77 	echo "Error: $dir already exists"
     78 	exit 1;
     79 fi
     80 newname=`expr $dir : 'etc.\(.*\)'`
     81 if [ $# -lt 2 ] ; then
     82 	orig=etc.current
     83 	echo "Using current config as base for $newname"
     84 else
     85 	orig=$2
     86 fi
     87 
     88 if [ -z "`expr $orig : 'etc.\(.*\)'`" ] ; then
     89 	orig=etc.$orig
     90 fi
     91 
     92 if [ ! -d /etc/$orig ] ; then
     93 	echo "Original directory /etc/$orig does not exist."
     94 	exit 1;
     95 fi
     96 mkdir -m 755 /etc/$dir
     97 cd /etc/$orig 
     98 pax -rw -pe . /etc/$dir
     99 echo "/etc/$dir has now been created and populated."
    100 exit 0
    101