diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2002-06-29 20:01:35 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2002-06-29 20:01:35 +0000 |
commit | 64000ff5df99694144a52581e276b307144ca8b6 (patch) | |
tree | 9aaeda5c38c56474bfa11b0d2ed94d478b9f648d /distrib | |
parent | ebdf93a4bdbd6612d42d6c47495c8c3e9d8e3d28 (diff) |
Some cleanup/simplification:
1) Put knowledge of /tmp/fstab in munge_fstab rather
than redirect input on calls. Check in munge_fstab
whether /etc/fstab was successfully created, and exit
install/upgrade with appropriate error if not. This
error condition is therefore checked on install and upgrade.
2) Don't bother specifying value in exit statements - no one
is checking whether it is 1, 2, or 0.
3) Put status messages inside check_fs rather than around
invocation, and exit from check_fs if a fsck fails, rather
than checking return value and exiting.
4) With above changes, simplify munge_fs/check_fs/mount_fs logic in
upgrade.sh.
5) Various cosmetic cleanups.
Diffstat (limited to 'distrib')
-rw-r--r-- | distrib/miniroot/install.sh | 4 | ||||
-rw-r--r-- | distrib/miniroot/install.sub | 42 | ||||
-rw-r--r-- | distrib/miniroot/upgrade.sh | 47 |
3 files changed, 45 insertions, 48 deletions
diff --git a/distrib/miniroot/install.sh b/distrib/miniroot/install.sh index 0237cb9187f..fe184358517 100644 --- a/distrib/miniroot/install.sh +++ b/distrib/miniroot/install.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: install.sh,v 1.103 2002/06/25 00:31:59 krw Exp $ +# $OpenBSD: install.sh,v 1.104 2002/06/29 20:01:34 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 @@ -275,7 +275,7 @@ if [ ! -f /etc/fstab ]; then done ) < ${FILESYSTEMS} > /tmp/fstab - munge_fstab < /tmp/fstab + munge_fstab fi mount_fs "-o async" diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index dc8d8d5d28f..3e2fdd6e1d4 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,4 +1,4 @@ -# $OpenBSD: install.sub,v 1.235 2002/06/25 00:31:59 krw Exp $ +# $OpenBSD: install.sub,v 1.236 2002/06/29 20:01:34 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 @@ -1803,8 +1803,13 @@ __EOT done } -# Create a fstab to use for fsck'ing, mounting and unmounting all -# of the target filesystems relative to /mnt. +# Create a /etc/fstab from /tmp/fstab. Ensure /etc/fstab +# 1) contains only ffs filesystems +# 2) contains only filesystems without the 'noauto' option +# 3) contains no 'softdep' options +# 4) mounts all filesystems relative to /mnt +# +# If no /etc/fstab is created, do not proceed with install/upgrade. munge_fstab() { local _dev _mp _fstype _opt _rest @@ -1832,7 +1837,13 @@ munge_fstab() { fi echo $_dev /mnt$_mp $_fstype $_opt $_rest - done > /etc/fstab + done < /tmp/fstab > /etc/fstab + + # If no /etc/fstab was created, we have nowhere to ${MODE} to. + if [ ! -s /etc/fstab ]; then + echo "Unable to create valid /etc/fstab." + exit + fi } # Must mount filesystems manually, one at a time, so we can make @@ -1863,14 +1874,10 @@ __EOT # Script is exiting. Clean up as much as possible. cleanup_on_exit() { - local _bad_devs - echo "\nCleaning up..." # Kill any running dhclient, so a restart will not - # find /dev/bpf0 busy. Do this first so a user who - # interrupts out of any fsck'ing will not be stuck - # with an active dhclient. + # find /dev/bpf0 busy. if [ -f /var/run/dhclient.pid ]; then echo "Stopping dhclient" @@ -1894,31 +1901,34 @@ remount_fs() { local _dev _mp _fstype _opt _rest while read _dev _mp _fstype _opt _rest; do - if ! mount -u -o $_opt $_dev $_mp ; then - # error message displayed by mount - exit 1 - fi + mount -u -o $_opt $_dev $_mp || exit done < /etc/fstab } # Preen all filesystems in /etc/fstab, showing individual results, # but skipping the root filesystem device given in $1. This was # already fsck'ed successfully. +# +# Exit if any fsck's fail (but do them all before exiting!). check_fs() { - local _dev _rest _badfsck=0 _root=$1 + local _dev _rest _fail _root=$1 + + echo "Checking non-root filesystems..." while read _dev _rest; do [ "$_dev" = "$_root" ] && continue echo -n "fsck -p ${_dev}..." if ! fsck -fp ${_dev} > /dev/null 2>&1; then echo "FAILED. You must fsck this device manually." - _badfsck=1 + _fail=y else echo "OK." fi done < /etc/fstab - return $_badfsck + echo "...Done." + + [ "$_fail" ] && exit } # Find LAST instance of DOMAIN or SEARCH and extract first domain name diff --git a/distrib/miniroot/upgrade.sh b/distrib/miniroot/upgrade.sh index 98e3c442cee..93b6ce490cf 100644 --- a/distrib/miniroot/upgrade.sh +++ b/distrib/miniroot/upgrade.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: upgrade.sh,v 1.35 2002/06/25 00:31:59 krw Exp $ +# $OpenBSD: upgrade.sh,v 1.36 2002/06/29 20:01:34 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 @@ -76,26 +76,24 @@ while [ -z "$resp" ]; do done echo -n "Checking root filesystem (fsck -fp ${_root_filesystem}) ... " -if fsck -fp ${_root_filesystem} > /dev/null 2>&1; then - echo "OK." -else +if ! fsck -fp ${_root_filesystem} > /dev/null 2>&1; then echo "FAILED.\nYou must fsck ${_root_filesystem} manually." - exit 1 + exit fi +echo "OK." echo -n "Mounting root filesystem ... " -if mount -o ro ${_root_filesystem} /mnt; then - echo "Done." -else +if ! mount -o ro ${_root_filesystem} /mnt; then echo "ERROR: can't mount root filesystem!" - exit 1 + exit fi +echo "Done." # fstab and hosts are required for upgrade for _file in fstab hosts; do if [ ! -f /mnt/etc/$_file ]; then echo "ERROR: no /etc/${_file}!" - exit 1 + exit fi cp /mnt/etc/$_file /tmp/$_file done @@ -114,7 +112,7 @@ case $resp in y*|Y*) if ! enable_network; then echo "ERROR: can't enable network!" - exit 1 + exit fi cat << __EOT @@ -157,29 +155,18 @@ esac echo -# Create a fstab containing only ffs filesystems w/o 'noauto'. -munge_fstab < /tmp/fstab +# Create /etc/fstab. +munge_fstab +# fsck -p non-root filesystems in /etc/fstab. +check_fs $_root_filesystem + +# Mount filesystems in /etc/fstab. if ! umount /mnt; then echo "ERROR: can't unmount previously mounted root!" - exit 1 -fi - -# Check filesystems. -echo "Checking non-root filesystems..." -if ! check_fs $_root_filesystem; then - # Prevent check_fs() invocation in cleanup_on_exit from fsck'ing. - # Remember /etc/fstab is a link, /tmp/fstab.shadow is the file! - rm /tmp/fstab.shadow -fi -echo "...Done." - -if [ ! -f /etc/fstab ]; then - exit 2 -else - # Mount filesystems. - mount_fs + exit fi +mount_fs # If Xfree86 v3 directories that would prevent upgrading to XFree86 v4 # are found, move them and replace them with links that the upgrade |