Merge from vendor branch LESS:
[dragonfly.git] / etc / rc.d / bootconf
1 #!/bin/sh
2 #
3 # $NetBSD: bootconf.sh,v 1.5 2002/03/25 03:22:10 wiz Exp $
4 # $FreeBSD: src/etc/rc.d/bootconf.sh,v 1.4 2002/10/12 10:31:31 schweikh Exp $
5 # $DragonFly: src/etc/rc.d/bootconf,v 1.1 2007/08/12 14:37:48 swildner Exp $
6 #
7
8 # PROVIDE: bootconf
9 # REQUIRE: root
10 # BEFORE:  mountcritlocal 
11
12 . /etc/rc.subr
13
14 bootconf_start()
15 {
16                 # Refer to newbtconf(8) for more information
17                 #
18
19         if [ ! -e /etc/etc.current ]; then
20                 return 0
21         fi
22         if [ -L /etc/etc.default ]; then
23                 def=`ls -ld /etc/etc.default 2>&1`
24                 default="${def##*-> etc.}"
25         else
26                 default=current
27         fi
28         if [ "$default" = "current" ]; then
29                 def=`ls -ld /etc/etc.current 2>&1`
30                 default="${def##*-> etc.}"
31         fi
32
33         spc=""
34         for i in /etc/etc.*; do
35                 name="${i##/etc/etc.}"
36                 case $name in
37                 current|default|\*)
38                         continue
39                         ;;
40                 *)
41                         if [ "$name" = "$default" ]; then
42                                 echo -n "${spc}[${name}]"
43                         else
44                                 echo -n "${spc}${name}"
45                         fi
46                         spc=" "
47                         ;;
48                 esac
49         done
50         echo
51         master=$$
52         _DUMMY=/etc/passwd
53         conf=${_DUMMY}
54         while [ ! -d /etc/etc.$conf/. ]; do
55                 trap "conf=$default; echo; echo Using default of $conf" ALRM
56                 echo -n "Which configuration [$default] ? "
57                 (sleep 30 && kill -ALRM $master) >/dev/null 2>&1 &
58                 read conf
59                 trap : ALRM
60                 if [ -z $conf ]; then
61                         conf=$default
62                 fi
63                 if [ ! -d /etc/etc.$conf/. ]; then
64                         conf=${_DUMMY}
65                 fi
66         done
67
68         case  $conf in
69         current|default)
70                 ;;
71         *)
72                 rm -f /etc/etc.current
73                 ln -s /etc/etc.$conf /etc/etc.current
74                 ;;
75         esac
76
77         if [ -f /etc/rc.conf ]; then
78                 . /etc/rc.conf
79         fi
80 }
81
82 case "$1" in
83 *start)
84         bootconf_start
85         ;;
86 esac
87
88 dummy_rc_command $1 XXX
89