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