diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2002-07-13 13:18:06 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2002-07-13 13:18:06 +0000 |
commit | 8ef33bae0f96f0dc240e4f1a003da2d8232658f8 (patch) | |
tree | 43dff20a39ee89c7ba2e45c18317fd1cecc820cf /distrib | |
parent | d82db1eba0ccbed6d4fafed20d718cb86847c7c7 (diff) |
More cleanup/simplification/shrinkage.
1) Factor out inquiring for a device. ask_fordev()
now does this for root disk determination, other
disk initialization, install sets disk or cd
inquiry. Also ensures cd devices are created on
the fly like disk devices already were, and
shortens some verbiage.
2) Just ask for root disk if install is skipping
disk initialization, rather than doing the
'df /mnt ...' scan, since 1) we just end up asking
anyway and 2) everything *should* have been
umount'ed when previous install was finished or
interrupted.
3) getrootdisk -> get_rootdisk to conform to
get_<global> naming convention.
4) Add and use new global ROOTDEV rather than
constantly adding 'a' to ROOTDISK. ROOTDEV
default is set in get_rootdisk().
5) Put loop inside get_rootdisk rather than
always putting one around it. If no rootdisk
found/specified just exit install/update.
6) Eliminate getanotherdisk since ask_fordev()
does most of the work.
7) Eliminate parameter to check_fs, just use
ROOTDEV instead.
8) Some typographical and minor code tweaks.
Diffstat (limited to 'distrib')
-rw-r--r-- | distrib/miniroot/install.sh | 49 | ||||
-rw-r--r-- | distrib/miniroot/install.sub | 125 | ||||
-rw-r--r-- | distrib/miniroot/upgrade.sh | 28 |
3 files changed, 86 insertions, 116 deletions
diff --git a/distrib/miniroot/install.sh b/distrib/miniroot/install.sh index ed9d6996b0a..33978852ca1 100644 --- a/distrib/miniroot/install.sh +++ b/distrib/miniroot/install.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: install.sh,v 1.105 2002/07/01 14:58:42 krw Exp $ +# $OpenBSD: install.sh,v 1.106 2002/07/13 13:18:05 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 @@ -83,7 +83,11 @@ MODE=install # include common subroutines and initialization code . install.sub -if [ ! -f /etc/fstab ]; then +# If /etc/fstab already exists we skip disk initialization, but we still +# need to know the root disk. +if [ -f /etc/fstab ]; then + get_rootdisk +else # Install the shadowed disktab file; lets us write to it for temporary # purposes without mounting the miniroot read-write. if [ -f /etc/disktab.shadow ]; then @@ -92,18 +96,19 @@ if [ ! -f /etc/fstab ]; then while : ; do if [ -z "$ROOTDISK" ]; then - while [ -z "$ROOTDISK" ]; do - getrootdisk - done + # Get ROOTDISK and default ROOTDEV + get_rootdisk DISK=$ROOTDISK + echo "${ROOTDEV} /" > $FILESYSTEMS else - DISK= - while [ -z "$DISK" ]; do - getanotherdisk - done - if [ "$DISK" = "done" ]; then - break - fi + cat << __EOT + +Now you can select another disk to initialize. (Do not re-select a disk +you have already entered information for). +__EOT + ask_fordev "Which disk do you wish to initialize?" "$DKDEVS" + [ "$resp" = "done" ] && break + DISK=$resp fi # Deal with disklabels, including editing the root disklabel @@ -111,8 +116,7 @@ if [ ! -f /etc/fstab ]; then # some platforms may not be able to provide this functionality. md_prep_disklabel ${DISK} - # Assume partition 'a' of $ROOTDISK is for the root filesystem. - # Loop and get the rest. + # Assume $ROOTDEV is the root filesystem, but loop to get the rest. # XXX ASSUMES THAT THE USER DOESN'T PROVIDE BOGUS INPUT. cat << __EOT @@ -126,11 +130,10 @@ __EOT cat << __EOT The following partitions will be used for the root filesystem and swap: - ${ROOTDISK}a / + ${ROOTDEV} / ${ROOTDISK}b swap __EOT - echo "${ROOTDISK}a /" > ${FILESYSTEMS} fi # XXX - allow the user to name mount points on disks other than ROOTDISK @@ -148,7 +151,7 @@ __EOT # Removing the partition size leaves us with the partition name _pp=${_p%${_ps}} - [ "$DISK" = "$ROOTDISK" -a "$_pp" = "a" ] && continue + [ "${DISK}${_pp}" = "$ROOTDEV" ] && continue _partitions[$_npartitions]=$_pp _psizes[$_npartitions]=$_ps @@ -185,10 +188,8 @@ __EOT ;; esac done - _i=$(( ${_i} + 1 )) - if [ $_i -ge $_npartitions ]; then - _i=0 - fi + _i=$(( $_i + 1 )) + [ $_i -ge $_npartitions ] && _i=0 done # Now write it out, sorted by mount point @@ -238,12 +239,6 @@ __EOT newfs -q /dev/r${_device_name} done ) < ${FILESYSTEMS} -else - # Get the root device - ROOTDISK=`df /mnt | sed -e '/^\//!d' -e 's/\/dev\/\([^ ]*\)[a-p] .*/\1/'` - while [ -z "$ROOTDISK" ]; do - getrootdisk - done fi # Get network configuration information, and store it for placement in the diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index 93c5c07d782..bf23bbde21e 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,4 +1,4 @@ -# $OpenBSD: install.sub,v 1.245 2002/07/12 01:25:44 krw Exp $ +# $OpenBSD: install.sub,v 1.246 2002/07/13 13:18:05 krw Exp $ # $NetBSD: install.sub,v 1.5.2.8 1996/09/02 23:25:02 pk Exp $ # # Copyright (c) 1997-2002 Todd Miller, Theo de Raadt, Ken Westerback @@ -205,6 +205,33 @@ ask_until () { 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. +# +# $1 = question to ask +# $2 = list of devices from /var/run/dmesg.boot scan +# $3 = default device +# +# $resp holds device selected at exit, or 'done' +ask_fordev () { + local _query=$1 _devs=$2 _defdev=$3 + + [ "$_defdev" ] || _defdev=done + + resp= + while [ -z "$resp" ]; do + echo "\nAvailable devices are:\n\n${_devs}\n" + ask "$_query (or done)" "$_defdev" + + if isin $resp $_devs ; then + makedev $resp || resp= + elif [ "$resp" != "done" ]; then + echo "\n'$resp' does not exist." + resp= + fi + done +} + # test the first argument against the remaining ones, return success on a match isin() { local _a=$1 _b @@ -366,30 +393,11 @@ makedev() { fi } -getanotherdisk() { - cat << __EOT - -Now you can select another disk to initialize. (Do not re-select a disk -you have already entered information for). Available disks are: - -$DKDEVS - -__EOT - ask "Which one?" done - if [ "$resp" = "done" ]; then - DISK=done - elif isin $resp $DKDEVS ; then - DISK=$resp - makedev $resp || DISK= - else - echo "\nThe disk $resp does not exist." - DISK= - fi -} - -getrootdisk() { +get_rootdisk() { local _defdsk + ROOTDISK= + _defdsk=`echo $DKDEVS | cutlast` [ "$_defdsk" = "$DKDEVS" ] || _defdsk= @@ -398,19 +406,12 @@ getrootdisk() { The installation program needs to know which disk to consider the root disk. Note the unit number may be different than the unit number you used in the boot program (especially on a machine with multiple disk controllers). -Available disks are: - -$DKDEVS - __EOT - ask "Which disk is the root disk?" "$_defdsk" - if isin $resp $DKDEVS ; then - ROOTDISK=$resp - makedev $resp || ROOTDISK= - else - echo "\nThe disk '$resp' does not exist." - ROOTDISK= - fi + ask_fordev "Which disk is the root disk?" "$DKDEVS" "$_defdsk" + [ "$resp" = "done" ] && exit + + ROOTDISK=$resp + ROOTDEV=${ROOTDISK}a } # Create an entry in the hosts file. If an entry with the @@ -1175,28 +1176,14 @@ install_cdrom() { cat << __EOT -The following CD-ROM devices are installed on your system. Please make sure the CD is in the CD-ROM drive and select -the device containing the CD with the installation sets: - -$CDDEVS - +the device containing the CD with the installation sets. __EOT - _drive=`echo $CDDEVS | cutword 1` - ask "Which CD-ROM contains the installation media?" "$_drive" - case $resp in - abort) echo "Aborting." - return - ;; - *) if isin $resp $CDDEVS ; then - _drive=$resp - else - echo "\nThe CD-ROM $resp does not exist.\nAborting." - return - fi - ;; - esac + ask_fordev "Which CD-ROM contains the installation media?" "$CDDEVS" "`echo $CDDEVS | cutword 1`" + [ "$resp" = "done" ] && return + + _drive=$resp # If it is an ISO9660 CD-ROM, we don't need to ask any other questions _n=0 @@ -1281,27 +1268,14 @@ mount_a_disk() { cat << __EOT -The following disk devices are installed on your system; please select -the disk device containing the partition with the installation sets: - -$DKDEVS - +Please select the disk device containing the partition with the +installation sets. __EOT - ask "Which is the disk with the installation sets?" abort + ask_fordev "Which is the disk with the installation sets?" "$DKDEVS" + [ "$resp" = "done" ] && return 1 - case $resp in - abort) echo "Aborting." - return 1 - ;; - *) if isin $resp $DKDEVS ; then - _drive=$resp - else - echo "\nThe disk $resp does not exist.\nAborting." - return 1 - fi - ;; - esac + _drive=$resp # Get partition cat << __EOT @@ -1766,17 +1740,17 @@ remount_fs() { } # Preen all filesystems in /etc/fstab, showing individual results, -# but skipping the root filesystem device given in $1. This was +# but skipping the root filesystem device $ROOTDEV. This was # already fsck'ed successfully. # # Exit if any fsck's fail (but do them all before exiting!). check_fs() { - local _dev _rest _fail _root=$1 + local _dev _rest _fail echo "Checking non-root filesystems..." while read _dev _rest; do - [ "$_dev" = "$_root" ] && continue + [ "$_dev" = "/dev/$ROOTDEV" ] && continue echo -n "fsck -p ${_dev}..." if ! fsck -fp ${_dev} > /dev/null 2>&1; then echo "FAILED. You must fsck this device manually." @@ -2021,6 +1995,7 @@ __EOT # ####################################################################### ROOTDISK= +ROOTDEV= VERSION=31 VERSION_MAJOR=$(( $VERSION / 10 )) VERSION_MINOR=$(( $VERSION % 10 )) diff --git a/distrib/miniroot/upgrade.sh b/distrib/miniroot/upgrade.sh index be3a03dda9f..f555ea34372 100644 --- a/distrib/miniroot/upgrade.sh +++ b/distrib/miniroot/upgrade.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: upgrade.sh,v 1.37 2002/07/06 03:19:36 krw Exp $ +# $OpenBSD: upgrade.sh,v 1.38 2002/07/13 13:18:05 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 @@ -59,31 +59,31 @@ THESETS=`echo $THESETS | sed -e 's/ etc / /'` # XXX Work around vnode aliasing bug (thanks for the tip, Chris...) ls -l /dev > /dev/null 2>&1 -while [ -z "$ROOTDISK" ]; do - getrootdisk -done +# Get ROOTDISK and default ROOTDEV +get_rootdisk -# Assume partition 'a' of $ROOTDISK is for the root filesystem. Confirm +# Assume $ROOTDEV is the root filesystem. Confirm # this with the user. Check and mount the root filesystem. resp= while [ -z "$resp" ]; do - ask "Root filesystem?" "${ROOTDISK}a" - _root_filesystem=/dev/${resp##*/} - if [ ! -b ${_root_filesystem} ]; then - echo "Sorry, ${_root_filesystem} is not a block device." + ask "Root filesystem?" "$ROOTDEV" + resp=${resp##*/} + if [ ! -b /dev/$resp ]; then + echo "Sorry, ${resp} is not a block device." resp= fi done +ROOTDEV=$resp -echo -n "Checking root filesystem (fsck -fp ${_root_filesystem}) ... " -if ! fsck -fp ${_root_filesystem} > /dev/null 2>&1; then - echo "FAILED.\nYou must fsck ${_root_filesystem} manually." +echo -n "Checking root filesystem (fsck -fp /dev/${ROOTDEV}) ... " +if ! fsck -fp /dev/$ROOTDEV > /dev/null 2>&1; then + echo "FAILED.\nYou must fsck ${ROOTDEV} manually." exit fi echo "OK." echo -n "Mounting root filesystem ... " -if ! mount -o ro ${_root_filesystem} /mnt; then +if ! mount -o ro /dev/$ROOTDEV /mnt; then echo "ERROR: can't mount root filesystem!" exit fi @@ -159,7 +159,7 @@ echo munge_fstab # fsck -p non-root filesystems in /etc/fstab. -check_fs $_root_filesystem +check_fs # Mount filesystems in /etc/fstab. if ! umount /mnt; then |