summaryrefslogtreecommitdiff
path: root/distrib
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2003-06-30 17:49:15 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2003-06-30 17:49:15 +0000
commitec46948c955ded5dcd149fc79465c26e0913c945 (patch)
tree4f435213a9e621c8809bae7b3d6ec74b6f953ad8 /distrib
parent805152b57ec6da677e4e03e27faf16294a42f4ce (diff)
Cleanup ask_which() logic.
Use first device in supplied list as default unless overridden. Eliminates repeated 'echo XXX | cutword 1' constructs. Use 'set -- $_devs' to parse _devs and find out if there are any devices in the list. Then use '_devs="$*" to eliminate all extraneous whitespace from _devs, rather than just a single trailing blank. Usual [...] -> [[...]], `` -> $(), extra '{}' and '"' eliminations in areas being fixed up.
Diffstat (limited to 'distrib')
-rw-r--r--distrib/miniroot/install.sh8
-rw-r--r--distrib/miniroot/install.sub55
2 files changed, 31 insertions, 32 deletions
diff --git a/distrib/miniroot/install.sh b/distrib/miniroot/install.sh
index 8cb75b36b71..bea8c128c12 100644
--- a/distrib/miniroot/install.sh
+++ b/distrib/miniroot/install.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# $OpenBSD: install.sh,v 1.131 2003/06/27 22:40:40 krw Exp $
+# $OpenBSD: install.sh,v 1.132 2003/06/30 17:49:14 krw Exp $
# $NetBSD: install.sh,v 1.5.2.8 1996/08/27 18:15:05 gwr Exp $
#
# Copyright (c) 1997-2002 Todd Miller, Theo de Raadt, Ken Westerback
@@ -98,8 +98,10 @@ if [ ! -f /etc/fstab ]; then
cat /dev/null >$FILESYSTEMS
cat /dev/null >$SWAPLIST
else
- ask_which "disk" "do you wish to initialize?" "$_DKDEVS"
- [ "$resp" = "done" ] && break
+ # Force the user to think and type in a disk name by
+ # making 'done' the default choice.
+ ask_which "disk" "do you wish to initialize?" "$_DKDEVS" done
+ [[ $resp == done ]] && break
fi
DISK=$resp
diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub
index eee708c0cf5..1dbdfa557ff 100644
--- a/distrib/miniroot/install.sub
+++ b/distrib/miniroot/install.sub
@@ -1,4 +1,4 @@
-# $OpenBSD: install.sub,v 1.308 2003/06/30 14:25:53 krw Exp $
+# $OpenBSD: install.sub,v 1.309 2003/06/30 17:49:14 krw Exp $
# $NetBSD: install.sub,v 1.5.2.8 1996/09/02 23:25:02 pk Exp $
#
# Copyright (c) 1997-2003 Todd Miller, Theo de Raadt, Ken Westerback
@@ -230,38 +230,36 @@ ask_until () {
# $1 = device name (disk, cd, etc.)
# $2 = question to ask
# $3 = list of devices from /var/run/dmesg.boot scan
-# $4 = default device
+# $4 = default device. If it is not specified, use the first device in $3.
#
# $resp holds device selected at exit, or 'done'
ask_which () {
local _name=$1 _query=$2 _devs=$3 _defdev=$4
-
- # If not default device is supplied, assume 'done'.
- : ${_defdev:=done}
-
- # A trailing space may be present if _devs list
- # was manipulated by rmel().
- _devs=${_devs% }
-
- resp=
- if [[ -z $_devs ]]; then
+
+ set -- $_devs
+ if [[ $# < 1 ]]; then
echo "Done - no available ${_name}s found."
resp=done
+ return
fi
+ : ${_defdev:=$1}
- while [ -z "$resp" ]; do
+ # Eliminate extraneous (especially trailing) whitespace in _devs.
+ _devs="$*"
+
+ while : ; do
# Put both lines in ask prompt, rather than use a
- # separate 'echo', to ensure entire question is
- # re-ask'ed after a '!' '!foo' shell escape.
+ # separate 'echo' to ensure the entire question is
+ # re-ask'ed after a '!' or '!foo' shell escape.
ask "Available ${_name}s are: ${_devs}.\nWhich one $_query (or 'done')" "$_defdev"
+ [[ $resp == done ]] && break
# Quote $resp to prevent user from confusing isin() by
# entering something like 'a a'.
- if isin "$resp" $_devs ; then
- makedev $resp || resp=
- elif [ "$resp" != "done" ]; then
+ if isin "$resp" $_devs; then
+ makedev $resp && break
+ else
echo "'$resp' is not a valid choice."
- resp=
fi
done
}
@@ -433,9 +431,6 @@ makedev() {
get_rootdisk() {
local _defdsk
- _defdsk=$(echo $DKDEVS | cutword 1)
- [[ $_defdsk == $DKDEVS ]] || _defdsk=
-
if [[ $MODE == install && ! -f /etc/fstab ]]; then
cat << __EOT
@@ -450,6 +445,9 @@ fi
ROOTDEV=
SWAPDEV=
+ set -- $DKDEVS
+ [[ $# > 1 ]] && _defdsk=done
+
ask_which "disk" "is the root disk?" "$DKDEVS" "$_defdsk"
[[ $resp == done ]] && exit
@@ -531,9 +529,8 @@ configure_all_interfaces() {
while : ; do
_IFDEVS=`rmel "$_ifs" $_IFDEVS`
- ask_which "interface" "do you wish to initialize?" "$_IFDEVS" "`echo $_IFDEVS | cutword 1`"
-
- [ "$resp" = "done" ] && break
+ ask_which "interface" "do you wish to initialize?" "$_IFDEVS"
+ [[ $resp == done ]] && break
_ifs=$resp
configure_ifs $_ifs || _ifs=
@@ -1054,8 +1051,8 @@ install_mounted_fs() {
install_cdrom() {
local _drive _part _fstype _directory _n
- ask_which "CD-ROM" "contains the ${MODE} media?" "$CDDEVS" "`echo $CDDEVS | cutword 1`"
- [ "$resp" = "done" ] && return
+ ask_which "CD-ROM" "contains the ${MODE} media?" "$CDDEVS"
+ [[ $resp == done ]] && return
_drive=$resp
@@ -1139,8 +1136,8 @@ mount_a_disk() {
local _drive _def_partition _partition_range _partition
local _fstype _fsopts
- ask_which "disk" "contains the ${MODE} sets?" "$DKDEVS" "`echo $DKDEVS | cutword 1`"
- [ "$resp" = "done" ] && return 1
+ ask_which "disk" "contains the ${MODE} sets?" "$DKDEVS"
+ [[ $resp == done ]] && return 1
_drive=$resp