summaryrefslogtreecommitdiff
path: root/distrib/miniroot/install.sub
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2003-09-22 01:31:40 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2003-09-22 01:31:40 +0000
commita18dc065fc7e5c93941eaf68464e80399b13b8de (patch)
tree70e6916b143b98236fa56069c35f166150432709 /distrib/miniroot/install.sub
parentd0bcdade658eb1148291424b21f52edd32f75a4e (diff)
Introduce a function ask_yn() to use when asking 'yes or no'
questions. ask_yn() always returns a 'y' or 'n' in $resp, vastly simplifying the logic used to check the user response. ask_yn() insists on the user responding with a 'y', 'n', 'yes', or 'no'. Case is ignored. Previously almost any input was accepted as either a yes or a no depending on the question. ask_yn() reduces the chance of user error, e.g. by answering the next question (default route) instead of the posed one (Use DNS server now?). All 'yes or no' questions now use ask_yn(). All questions show the full default answer, i.e. 'yes' or 'no' rather than 'y' or 'n'. Some minor logic cleanups of the usual sort, but no changes to logic flow or questions bar minor verbiage adjustment. Inspired by a Bob Beck install nit.
Diffstat (limited to 'distrib/miniroot/install.sub')
-rw-r--r--distrib/miniroot/install.sub126
1 files changed, 62 insertions, 64 deletions
diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub
index 9763d879c1b..8d3c5a09304 100644
--- a/distrib/miniroot/install.sub
+++ b/distrib/miniroot/install.sub
@@ -1,4 +1,4 @@
-# $OpenBSD: install.sub,v 1.320 2003/08/23 22:22:02 krw Exp $
+# $OpenBSD: install.sub,v 1.321 2003/09/22 01:31:39 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
@@ -66,7 +66,7 @@
# The following functions must be provided:
# md_congrats() - display friendly message
# md_installboot() - install boot-blocks on disk
-# md_prep_disklabel() - label the root disk
+# md_prep_disklabel() - put an OpenBSD disklabel on the disk
# md_set_term() - set up terminal
#
# The following variables can be provided if required:
@@ -80,7 +80,7 @@
. install.md
set_term() {
- [ "$TERM" ] && return
+ [[ -n $TERM ]] && return
ask "Terminal type?" ${MDTERM:-vt220}
TERM=$resp
export TERM
@@ -89,6 +89,8 @@ set_term() {
}
welcome() {
+ local _q
+
cat << __EOT
Welcome to the $OBSD $MODE program.
@@ -119,7 +121,7 @@ NOTE: once your system has been upgraded, you must manually merge any changes
to files in the 'etc' set into the files already on your system.
__EOT
- ask "Proceed with upgrade?" n
+ _q="Proceed with upgrade?"
;;
install)
@@ -135,24 +137,24 @@ You seem to be trying to restart an interrupted installation! You can skip
the disk preparation steps and continue, or you can reboot and start over.
__EOT
- ask "Skip disk initialization?" n
+ _q="Skip disk initialization?"
else
- ask "Proceed with install?" n
+ _q="Proceed with install?"
fi
;;
esac
- case $resp in
- y*|Y*) echo "Cool! Let's get to it..."
- ;;
- *) cat << __EOT
+ ask_yn "$_q"
+ if [[ $resp == n ]]; then
+ cat << __EOT
Enter 'halt' at the prompt to gracefully exit OpenBSD. You can then
power cycle the machine and boot your original OS.
__EOT
exit
- ;;
- esac
+ fi
+
+ echo "Cool! Let's get to it..."
}
get_dkdevs() {
@@ -191,7 +193,7 @@ askpass() {
#
# Allow the user to escape to shells ('!') or execute commands
# ('!foo') before entering the input.
-ask() {
+ask () {
local _question=$1 _default=$2
set -o noglob
@@ -226,6 +228,26 @@ ask_until () {
done
}
+# Ask the user for a y or n, and insist on 'y', 'yes', 'n' or 'no'.
+#
+# $1 = the question to ask the user
+# $2 = the default answer (assumed to be 'n' if empty).
+#
+# Return 'y' or 'n' in $resp.
+ask_yn () {
+ local _q=$1 _a=${2:-no} _resp
+ typeset -l _resp
+
+ while : ; do
+ ask "$_q" "$_a"
+ _resp=$resp
+ case $_resp in
+ y|yes) resp=y ; return ;;
+ n|no) resp=n ; return ;;
+ esac
+ done
+ }
+
# Ask for the user to select a device from a list generated by scanning
# /var/run/dmesg.boot, and make the device if it doesn't exist.
#
@@ -343,23 +365,16 @@ save_comments () {
edit_tmp_file () {
local _file=$1
- ask "Edit $_file with ${EDITOR}?" n
- case $resp in
- y*|Y*) ${EDITOR} /tmp/$_file
- ;;
- esac
+ ask_yn "Edit $_file with $EDITOR?"
+ [[ $resp == y ]] && $EDITOR /tmp/$_file
}
# Offer to shell out for manual network configuration, and do so if
# the user accepts the offer.
manual_net_cfg () {
- ask "Do you want to do any manual network configuration?" n
+ ask_yn "Do you want to do any manual network configuration?"
- case $resp in
- y*|Y*) echo "Type 'exit' to return to ${MODE}."
- sh
- ;;
- esac
+ [[ $resp == y ]] && { echo "Type 'exit' to return to $MODE." ; sh ; }
}
# log in via ftp to host $1 as user $2 with password $3
@@ -568,9 +583,9 @@ configure_ifs() {
The default media for $_ifs is
$(ifconfig -m $_ifs | sed -n '/supported/D;/media:/p')
__EOT
- ask "Do you want to change the default media?" n
+ ask_yn "Do you want to change the default media?"
case $resp in
- y*|Y*) cat << __EOT
+ y) cat << __EOT
Supported media options for $_ifs are:
$_media
__EOT
@@ -578,7 +593,7 @@ __EOT
_media=$resp
ifconfig $_ifs $_media down || return 1
;;
- *) _media=
+ n) _media=
;;
esac
fi
@@ -794,10 +809,8 @@ __EOT
[[ -n $resp ]] || return
_get_sets=$resp
- ask "Ready to $MODE sets?" y
- case $resp in
- n*|N*) return ;;
- esac
+ ask_yn "Ready to $MODE sets?" yes
+ [[ $resp = n ]] && return
for _f in $THESETS ; do
isin $_f $_get_sets || continue
@@ -858,12 +871,9 @@ install_url() {
[[ $resp == none ]] || export ftp_proxy=$resp http_proxy=$resp
rm -f $SERVERLIST
- ask "Display the list of known $_url_type servers?" "${_get_server_list:-y}"
- case $resp in
- n*|N*) _get_server_list=n
- ;;
- *)
- _get_server_list=y
+ ask_yn "Display the list of known $_url_type servers?" "${_get_server_list:-yes}"
+ _get_server_list=$resp
+ if [[ $_get_server_list == y ]]; then
# ftp.openbsd.org == 129.128.5.191 and will remain at
# that address for the forseeable future.
echo -n "Getting the list from 129.128.5.191 (ftp.openbsd.org)..."
@@ -878,8 +888,7 @@ install_url() {
echo "FAILED."
cat /tmp/ftplisterr
fi
- ;;
- esac
+ fi
# Get server IP address or hostname
: ${_prompt:="Server? (IP address, hostname or 'done')"}
@@ -913,15 +922,13 @@ install_url() {
# Irrelevant if using a proxy.
if [[ $_url_type == ftp && -z $ftp_proxy ]]; then
case $_ftp_active in
- -A) resp=n ;;
- *) resp=y ;;
+ -A) resp=no ;;
+ *) resp=yes ;;
esac
- ask "Does the server support passive mode ftp?" "$resp"
- case $resp in
- n*|N*) _ftp_active=-A ;;
- *) unset _ftp_active ;;
- esac
+ unset _ftp_active
+ ask_yn "Does the server support passive mode ftp?" $resp
+ [[ $resp == n ]] && _ftp_active=-A
fi
# Get server directory
@@ -1191,13 +1198,9 @@ install_nfs() {
_nfs_server_path=$resp
# Determine use of TCP
- ask "Use TCP transport? (only works with capable NFS server)" n
- case $resp in
- y*|Y*) _nfs_tcp=-T
- ;;
- *) _nfs_tcp=
- ;;
- esac
+ _nfs_tcp=
+ ask_yn "Use TCP transport? (only works with capable NFS server)"
+ [[ $resp == y ]] && _nfs_tcp=-T
# Mount the server
if ! mount_nfs $_nfs_tcp -o ro ${_nfs_server_ip}:${_nfs_server_path} /mnt2 ; then
@@ -1582,11 +1585,8 @@ donetconfig() {
for _ns in $resp; do
echo "nameserver $_ns" >> /tmp/resolv.conf
done
- ask "Use the nameserver now?" y
- case $resp in
- y*|Y*) cp /tmp/resolv.conf /tmp/resolv.conf.shadow
- ;;
- esac
+ ask_yn "Use the nameserver now?"
+ [[ $resp == y ]] && cp /tmp/resolv.conf /tmp/resolv.conf.shadow
fi
# Get/Confirm the default route.
@@ -1614,15 +1614,13 @@ populateusrlocal() {
}
set_machdep_apertureallowed() {
- [ "$MDXAPERTURE" ] || return
+ [[ -n $MDXAPERTURE ]] || return
- ask "Do you expect to run the X Window System?" y
- case $resp in
- y*|Y*)
+ ask_yn "Do you expect to run the X Window System?" yes
+ if [[ $resp == y ]]; then
sed -e "/^#\(machdep\.allowaperture=${MDXAPERTURE}\)/s//\1 /" \
/mnt/etc/sysctl.conf > /tmp/sysctl.conf
- ;;
- esac
+ fi
}
finish_up() {