summaryrefslogtreecommitdiff
path: root/distrib
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
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')
-rw-r--r--distrib/i386/common/install.md29
-rw-r--r--distrib/macppc/ramdisk/install.md52
-rw-r--r--distrib/miniroot/install.sh20
-rw-r--r--distrib/miniroot/install.sub126
-rw-r--r--distrib/miniroot/upgrade.sh8
-rw-r--r--distrib/mvmeppc/ramdisk/install.md52
6 files changed, 120 insertions, 167 deletions
diff --git a/distrib/i386/common/install.md b/distrib/i386/common/install.md
index 661bf079462..11c87848dfc 100644
--- a/distrib/i386/common/install.md
+++ b/distrib/i386/common/install.md
@@ -1,4 +1,4 @@
-# $OpenBSD: install.md,v 1.19 2003/09/21 02:11:42 krw Exp $
+# $OpenBSD: install.md,v 1.20 2003/09/22 01:31:39 krw Exp $
#
#
# Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -47,15 +47,9 @@ ARCH=ARCH
md_set_term() {
local _tables
- ask "Do you wish to select a keyboard encoding table?" n
+ ask_yn "Do you wish to select a keyboard encoding table?"
+ [[ $resp == n ]] && return
- case $resp in
- Y*|y*) ;;
- *) return
- ;;
- esac
-
- resp=
while : ; do
ask "Select your keyboard type: (P)C-AT/XT, (U)SB or 'done'" P
case $resp in
@@ -119,11 +113,11 @@ md_checkfordisklabel() {
return $rval
}
-md_prep_fdisk()
-{
- local _disk=$1 _whole=$2
+md_prep_fdisk() {
+ local _disk=$1
- if [ -n "$_whole" ]; then
+ ask_yn "Do you want to use *all* of $_disk for OpenBSD?"
+ if [[ $resp == y ]]; then
echo -n "Putting all of $_disk into an active OpenBSD MBR partition (type 'A6')..."
fdisk -e ${_disk} << __EOT > /dev/null
reinit
@@ -155,15 +149,10 @@ $(fdisk ${_disk})
__EOT
}
-md_prep_disklabel()
-{
+md_prep_disklabel() {
local _disk=$1
- ask "Do you want to use *all* of $_disk for OpenBSD?" no
- case $resp in
- y*|Y*) md_prep_fdisk ${_disk} Y ;;
- *) md_prep_fdisk ${_disk} ;;
- esac
+ md_prep_fdisk $_disk
cat << __EOT
diff --git a/distrib/macppc/ramdisk/install.md b/distrib/macppc/ramdisk/install.md
index fe8fe5995d9..0337e00343a 100644
--- a/distrib/macppc/ramdisk/install.md
+++ b/distrib/macppc/ramdisk/install.md
@@ -1,4 +1,4 @@
-# $OpenBSD: install.md,v 1.21 2003/09/21 02:11:42 krw Exp $
+# $OpenBSD: install.md,v 1.22 2003/09/22 01:31:39 krw Exp $
#
#
# Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -84,11 +84,8 @@ OpenFirmware manual -and- the PowerPC OpenBSD Installation Guide for doing
setup this way.
__EOT
- ask "Do you want to initialize the MBR and the MSDOS partition?" y
- case $resp in
- n*|N*) exit 0 ;;
- *) ;;
- esac
+ ask_yn "Do you want to initialize the MBR and the MSDOS partition?" yes
+ [[ $resp == n ]] && exit
cat << __EOT
An MBR record with an OpenBSD usable partition table will now be copied to your
@@ -149,16 +146,13 @@ __EOT
md_checkforMBRdisklabel() {
local _disk=$1 rval=0
- ask "Are you *sure* you want to put a MBR disklabel on the disk?" n
- case $resp in
- n*|N*) echo "aborting install"
- exit 0;;
- esac
+ ask_yn "Are you *sure* you want to put a MBR disklabel on the disk?"
+ [[ $resp == n ]] && exit
- ask "Have you initialized an MSDOS partition using OpenFirmware?" n
+ ask_yn "Have you initialized an MSDOS partition using OpenFirmware?"
case $resp in
- n*|N*) md_init_mbr $_disk;;
- *) cat << __EOT
+ n) md_init_mbr $_disk;;
+ y) cat << __EOT
You may keep your current setup if you want to be able to use any already
loaded OS. However you will be asked to prepare an empty partition for OpenBSD
later. There must also be at least ~0.5MB free space in the boot partition to
@@ -168,10 +162,8 @@ Also note that the boot partition must be included as partition 'i' in the
OpenBSD disklabel.
__EOT
- ask "Do you want to keep the current MSDOS partition setup?" y
- case $resp in
- n*|N*) md_init_mbr $_disk;;
- esac
+ ask_yn "Keep the current MSDOS partition setup?" yes
+ [[ $resp == n ]] && md_init_mbr $_disk
;;
esac
@@ -236,12 +228,8 @@ $(fdisk $_disk)
(You will be permitted to edit this information again.)
-------------------------------------------------------
__EOT
- ask "Is the above information correct?" n
-
- case $resp in
- n*|N*) ;;
- *) break ;;
- esac
+ ask_yn "Is the above information correct?"
+ [[ $resp == y ]] && break
done
cat << __EOT
@@ -256,25 +244,25 @@ __EOT
}
md_prep_disklabel() {
- local _disk=$1
+ local _disk=$1 _q
md_checkfordisklabel $_disk
case $? in
- 0) ask "Do you wish to edit the existing disklabel on $_disk?" y
+ 0) _q="Do you wish to edit the existing disklabel on $_disk?"
;;
1) md_prep_fdisk $_disk
echo "WARNING: $_disk has no label"
- ask "Do you want to create one with the disklabel editor?" y
+ _q="Do you want to create one with the disklabel editor?"
;;
2) echo "WARNING: The disklabel on $_disk is invalid."
- ask "Do you want to try and repair the damage using the disklabel editor?" y
+ _q="Do you want to try and repair the damage using the disklabel editor?"
;;
esac
- case $resp in
- y*|Y*) ;;
- *) return ;;
- esac
+ if [[ -n $_q ]]; then
+ ask_yn "$_q" yes
+ [[ $resp == n ]] && return
+ fi
# display example
cat << __EOT
diff --git a/distrib/miniroot/install.sh b/distrib/miniroot/install.sh
index 61a6d7dc7c5..497e1f98313 100644
--- a/distrib/miniroot/install.sh
+++ b/distrib/miniroot/install.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# $OpenBSD: install.sh,v 1.136 2003/08/17 18:18:50 krw Exp $
+# $OpenBSD: install.sh,v 1.137 2003/09/22 01:31:39 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
@@ -240,13 +240,8 @@ $(<$FILESYSTEMS)
The next step creates a filesystem on each partition, ERASING existing data.
__EOT
- ask "Are you really sure that you're ready to proceed?" n
- case $resp in
- y*|Y*) ;;
- *) echo "ok, try again later..."
- exit
- ;;
- esac
+ ask_yn "Are you really sure that you're ready to proceed?"
+ [[ $resp == n ]] && { echo "ok, try again later..." ; exit ; }
# Read $FILESYSTEMS, creating a new filesystem on each listed
# partition and saving the partition and mount point information
@@ -353,16 +348,13 @@ cat > /tmp/hosts << __EOT
127.0.0.1 $(hostname -s)
__EOT
-ask "Configure the network?" y
-case $resp in
-y*|Y*) donetconfig ;;
-*) ;;
-esac
+ask_yn "Configure the network?" yes
+[[ $resp == y ]] && donetconfig
_oifs=$IFS
IFS=
resp=
-while [ -z "$resp" ]; do
+while [[ -z $resp ]]; do
askpass "Password for root account? (will not echo)"
_password=$resp
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() {
diff --git a/distrib/miniroot/upgrade.sh b/distrib/miniroot/upgrade.sh
index c2147aded02..b4106866698 100644
--- a/distrib/miniroot/upgrade.sh
+++ b/distrib/miniroot/upgrade.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# $OpenBSD: upgrade.sh,v 1.54 2003/09/09 23:33:34 deraadt Exp $
+# $OpenBSD: upgrade.sh,v 1.55 2003/09/22 01:31:39 krw Exp $
# $NetBSD: upgrade.sh,v 1.2.4.5 1996/08/27 18:15:08 gwr Exp $
#
# Copyright (c) 1997-2002 Todd Miller, Theo de Raadt, Ken Westerback
@@ -86,10 +86,8 @@ for _file in fstab hosts myname; do
done
hostname $(< /tmp/myname)
-ask "Enable network using configuration stored on root filesystem?" y
-case $resp in
-y*|Y*) enable_network ;;
-esac
+ask_yn "Enable network using configuration stored on root filesystem?" yes
+[[ $resp == y ]] && enable_network
# Offer the user the opportunity to tweak, repair, or create the network
# configuration by hand.
diff --git a/distrib/mvmeppc/ramdisk/install.md b/distrib/mvmeppc/ramdisk/install.md
index 70e6d7a04bc..5bab3309052 100644
--- a/distrib/mvmeppc/ramdisk/install.md
+++ b/distrib/mvmeppc/ramdisk/install.md
@@ -1,4 +1,4 @@
-# $OpenBSD: install.md,v 1.19 2003/09/21 02:11:42 krw Exp $
+# $OpenBSD: install.md,v 1.20 2003/09/22 01:31:39 krw Exp $
#
#
# Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -84,11 +84,8 @@ OpenFirmware manual -and- the PowerPC OpenBSD Installation Guide for doing
setup this way.
__EOT
- ask "Do you want to initialize the MBR and the MSDOS partition?" y
- case $resp in
- n*|N*) exit 0 ;;
- *) ;;
- esac
+ ask_yn "Do you want to initialize the MBR and the MSDOS partition?" yes
+ [[ $resp == n ]] && exit
cat << __EOT
An MBR record with an OpenBSD usable partition table will now be copied to your
@@ -149,16 +146,13 @@ __EOT
md_checkforMBRdisklabel() {
local _disk=$1 rval=0
- ask "Are you *sure* you want to put a MBR disklabel on the disk?" n
- case $resp in
- n*|N*) echo "aborting install"
- exit 0;;
- esac
+ ask_yn "Are you *sure* you want to put a MBR disklabel on the disk?"
+ [[ $resp == n ]] && exit
- ask "Have you initialized an MSDOS partition using OpenFirmware?" n
+ ask_yn "Have you initialized an MSDOS partition using OpenFirmware?"
case $resp in
- n*|N*) md_init_mbr $_disk;;
- *) cat << __EOT
+ n) md_init_mbr $_disk;;
+ y) cat << __EOT
You may keep your current setup if you want to be able to use any already
loaded OS. However you will be asked to prepare an empty partition for OpenBSD
later. There must also be at least ~0.5MB free space in the boot partition to
@@ -168,10 +162,8 @@ Also note that the boot partition must be included as partition 'i' in the
OpenBSD disklabel.
__EOT
- ask "Do you want to keep the current MSDOS partition setup?" y
- case $resp in
- n*|N*) md_init_mbr $_disk;;
- esac
+ ask_yn "Keep the current MSDOS partition setup?" yes
+ [[ $resp == n ]] && md_init_mbr $_disk
;;
esac
@@ -236,12 +228,8 @@ $(fdisk $_disk)
(You will be permitted to edit this information again.)
-------------------------------------------------------
__EOT
- ask "Is the above information correct?" n
-
- case $resp in
- n*|N*) ;;
- *) break ;;
- esac
+ ask_yn "Is the above information correct?"
+ [[ $resp == y ]] && break
done
cat << __EOT
@@ -256,25 +244,25 @@ __EOT
}
md_prep_disklabel() {
- local _disk=$1
+ local _disk=$1 _q
md_checkfordisklabel $_disk
case $? in
- 0) ask "Do you wish to edit the existing disklabel on $_disk?" y
+ 0) _q="Do you wish to edit the existing disklabel on $_disk?"
;;
1) md_prep_fdisk $_disk
echo "WARNING: $_disk has no label"
- ask "Do you want to create one with the disklabel editor?" y
+ _q="Do you want to create one with the disklabel editor?"
;;
2) echo "WARNING: The disklabel on $_disk is invalid."
- ask "Do you want to try and repair the damage using the disklabel editor?" y
+ _q="Do you want to try and repair the damage using the disklabel editor?"
;;
esac
- case $resp in
- y*|Y*) ;;
- *) return ;;
- esac
+ if [[ -n $_q ]]; then
+ ask_yn "$_q" yes
+ [[ $resp == n ]] && return
+ fi
# display example
cat << __EOT