Home | History | Annotate | Line # | Download | only in rc.d
bootconf.sh revision 1.12
      1 #!/bin/sh
      2 #
      3 # $NetBSD: bootconf.sh,v 1.12 2009/09/11 18:17:43 apb Exp $
      4 #
      5 
      6 # PROVIDE: bootconf
      7 # REQUIRE: mountcritlocal
      8 # KEYWORD: interactive
      9 
     10 $_rc_subr_loaded . /etc/rc.subr
     11 
     12 name="bootconf"
     13 start_cmd="bootconf_start"
     14 stop_cmd=":"
     15 
     16 bootconf_start()
     17 {
     18 		# Refer to newbtconf(8) for more information
     19 		#
     20 
     21 	if [ ! -e /etc/etc.current ]; then
     22 		return 0
     23 	fi
     24 	if [ -h /etc/etc.default ]; then
     25 		def=$(ls -ld /etc/etc.default 2>&1)
     26 		default="${def##*-> *etc.}"
     27 	else
     28 		default=current
     29 	fi
     30 	if [ "$default" = "current" ]; then
     31 		def=$(ls -ld /etc/etc.current 2>&1)
     32 		default="${def##*-> *etc.}"
     33 	fi
     34 
     35 	spc=""
     36 	for i in /etc/etc.*; do
     37 		name="${i##/etc/etc.}"
     38 		case $name in
     39 		current|default|\*)
     40 			continue
     41 			;;	
     42 		*)
     43 			if [ "$name" = "$default" ]; then
     44 				echo -n "${spc}[${name}]"
     45 			else
     46 				echo -n "${spc}${name}"
     47 			fi
     48 			spc=" "
     49 			;;
     50 		esac
     51 	done
     52 	echo
     53 	master=$$
     54 	_DUMMY=/etc/passwd
     55 	conf=${_DUMMY}
     56 	while [ ! -d /etc/etc.$conf/. ]; do
     57 		trap "conf=$default; echo; echo Using default of $default" ALRM
     58 		echo -n "Which configuration [$default] ? "
     59 		(sleep 30 && kill -ALRM $master) >/dev/null 2>&1 &
     60 		read conf
     61 		trap : ALRM
     62 		if [ -z $conf ] ; then
     63 			conf=$default
     64 		fi
     65 		if [ ! -d /etc/etc.$conf/. ]; then
     66 			conf=${_DUMMY}
     67 		fi
     68 	done
     69 
     70 	rc_print_metadata "note:Using configuration \"${conf}\""
     71 
     72 	case  $conf in
     73 	current|default)
     74 		;;
     75 	*)
     76 		rm -f /etc/etc.current
     77 		ln -s etc.$conf /etc/etc.current
     78 		;;
     79 	esac
     80 
     81 	if [ -f /etc/rc.conf ] ; then
     82 		. /etc/rc.conf
     83 	fi
     84 }
     85 
     86 load_rc_config $name
     87 run_rc_command "$1"
     88