No empty .Rs/.Re
[netbsd-mini2440.git] / sbin / newbtconf / newbtconf.sh
blob2d6d50567b129baa00a360b07bc76bd26a1ddc58
1 #!/bin/sh
3 # Setup a new config directory
5 if [ $# -lt 1 ] ; then
6 echo "usage: $0 <newconfig> [<baseconfig>]"
7 echo "usage: $0 init"
8 echo "usage: $0 revert"
9 exit 1;
11 dir=$1
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"
17 if [ $dir = init ] ; then
18 if [ -d /etc/etc.network -o -e /etc/etc.current ] ; then
19 echo "Error: multi-configuration already initialized"
20 exit 1
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 -o -d $i ] ; then
29 mv $i $dir
30 ln -s etc.current/$i .
32 done
33 echo "/etc/$dir has now been created and populated."
34 exit 0
37 if [ $dir = revert ] ; then
38 if [ ! -d /etc/etc.current ] ; then
39 echo "Error: multi-configuration not initialized"
40 exit 1
42 cd /etc
43 for i in ${FILES}; do
44 if [ -f $i -o -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 )
67 done
68 rm etc.current
69 rm etc.default
70 exit 0
73 if [ "`expr $dir : 'etc\.\(.*\)'`" != $dir ] ; then
74 dir=etc.$dir
76 if [ -e /etc/$dir ] ; then
77 echo "Error: $dir already exists"
78 exit 1;
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
88 if [ -z "`expr $orig : 'etc.\(.*\)'`" ] ; then
89 orig=etc.$orig
92 if [ ! -d /etc/$orig ] ; then
93 echo "Original directory /etc/$orig does not exist."
94 exit 1;
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