1193326Sed#!/bin/sh 2193326Sed# $NetBSD: upgrade.sh,v 1.2 2002/05/07 14:47:45 lukem Exp $ 3193326Sed# 4193326Sed# Copyright (c) 1997 Perry E. Metzger 5193326Sed# Copyright (c) 1994 Christopher G. Demetriou 6193326Sed# All rights reserved. 7193326Sed# 8193326Sed# Redistribution and use in source and binary forms, with or without 9193326Sed# modification, are permitted provided that the following conditions 10193326Sed# are met: 11193326Sed# 1. Redistributions of source code must retain the above copyright 12193326Sed# notice, this list of conditions and the following disclaimer. 13193326Sed# 2. Redistributions in binary form must reproduce the above copyright 14193326Sed# notice, this list of conditions and the following disclaimer in the 15193326Sed# documentation and/or other materials provided with the distribution. 16193326Sed# 3. All advertising materials mentioning features or use of this software 17193326Sed# must display the following acknowledgement: 18193326Sed# This product includes software developed for the 19193326Sed# NetBSD Project. See http://www.NetBSD.org/ for 20193326Sed# information about NetBSD. 21193326Sed# 4. The name of the author may not be used to endorse or promote products 22193326Sed# derived from this software without specific prior written permission. 23193326Sed# 24193326Sed# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 25193326Sed# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26193326Sed# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27193326Sed# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 28193326Sed# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29193326Sed# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30193326Sed# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31193326Sed# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32193326Sed# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33193326Sed# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34193326Sed# 35193326Sed# <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> 36193326Sed 37193326Sed# NetBSD upgrade script. 38193326Sed# In a perfect world, this would be a nice C program, with a reasonable 39193326Sed# user interface. 40193326Sed 41193326SedDT=/etc/disktab # /etc/disktab 42193326SedFSTABDIR=/mnt/etc # /mnt/etc 43193326Sed#DONTDOIT=echo 44193326SedUARGS="-c 2" 45193326Sed 46193326SedFSTAB=${FSTABDIR}/fstab 47193326Sed 48193326Sedgetresp() { 49193326Sed read resp 50193326Sed if [ "X$resp" = "X" ]; then 51193326Sed resp=$1 52193326Sed fi 53193326Sed} 54193326Sed 55193326Sedecho "Welcome to the original NetBSD/alpha upgrade program." 56193326Sedgetresp 57193326Sedecho "This version of the program has been largely replaced by the new 58193326Sedecho "sysinst utility. Both programs are on this installation media set. 59193326Sedecho -n "Type the return key to continue..." 60193326Sedecho "" 61193326Sedecho "This program is designed to help you put the new version of NetBSD" 62193326Sedecho "on your hard disk, in a simple and rational way. To upgrade, you" 63193326Sedecho "must have plenty of free space on all partitions which will be" 64193326Sedecho "upgraded. If you have at least 1MB free on your root partition," 65193326Sedecho "and several free on your /usr patition, you should be fine." 66193326Sedecho "" 67193326Sedecho "As with anything which modifies your hard drive's contents, this" 68193326Sedecho "program can cause SIGNIFICANT data loss, and you are advised" 69193326Sedecho "to make sure your hard drive is backed up before beginning the" 70193326Sedecho "upgrade process." 71193326Sedecho "" 72193326Sedecho "Default answers are displyed in brackets after the questions." 73193326Sedecho "You can hit Control-C at any time to quit, but if you do so at a" 74193326Sedecho "prompt, you may have to hit return. Also, quitting in the middle of" 75193326Sedecho "the upgrade may leave your system in an inconsistent (and unusable)" 76193326Sedecho "state." 77193326Sedecho "" 78193326Sedecho -n "Proceed with upgrade? [n] " 79193326Sedgetresp "n" 80193326Sedcase "$resp" in 81193326Sed y*|Y*) 82193326Sed echo "Cool! Let's get to it..." 83193326Sed ;; 84193326Sed *) 85193326Sed echo "" 86193326Sed echo "OK, then. Enter 'halt' at the prompt to halt the" 87193326Sed echo "machine. Once the machine has halted, remove the" 88193326Sed echo "floppy and press any key to reboot." 89193326Sed exit 90193326Sed ;; 91193326Sedesac 92193326Sed 93193326Sed# find out what units are possible, and query the user. 94193326Seddriveunits=`echo /dev/[sw]d?a | sed -e 's,/dev/\(...\)a,\1,g'` 95193326Sedif [ "X${driveunits}" = "X" ]; then 96193326Sed echo "FATAL ERROR:" 97193326Sed echo "No disk devices." 98193326Sed echo "This is probably a bug in the install disks." 99193326Sed echo "Exiting install program." 100193326Sed exit 101193326Sedfi 102193326Sed 103193326Sedecho "" 104193326Sedecho "The following disks are supported by this upgrade procedure:" 105193326Sedecho " "${driveunits} 106193326Sedecho "If your system was previously completely contained within the" 107193326Sedecho "disks listed above (i.e. if your system didn't occupy any space" 108193326Sedecho "on disks NOT listed above), this upgrade disk can upgrade your" 109193326Sedecho "system. If it cannot, hit Control-C at the prompt." 110193326Sedecho "" 111193326Sedwhile [ "X${drivename}" = "X" ]; do 112193326Sed echo -n "Which disk contains your root partition? " 113193326Sed getresp 114193326Sed otherdrives=`echo "${driveunits}" | sed -e s,${resp},,` 115193326Sed if [ "X${driveunits}" = "X${otherdrives}" ]; then 116193326Sed echo "" 117193326Sed echo "\"${resp}\" is an invalid drive name. Valid choices" 118193326Sed echo "are: "${driveunits} 119193326Sed echo "" 120193326Sed else 121193326Sed drivename=${resp} 122193326Sed fi 123193326Seddone 124193326Sed 125193326Sedecho "" 126193326Sedecho "Root partition is on ${drivename}a." 127193326Sed 128193326Sedecho "" 129193326Sedecho "If (and only if!) you are upgrading from NetBSD 0.9 or below," 130193326Sedecho "you should upgrade to the new file system format. Do not answer" 131193326Sedecho "yes if you are upgrading from NetBSD 1.0 or above." 132193326Sedecho "Would you like to upgrade your file systems to the new file system" 133193326Sedecho -n "format? [y] " 134193326Sedgetresp "y" 135193326Sedcase "$resp" in 136193326Sed n*|N*) 137193326Sed echo "" 138193326Sed echo "If you are upgrading from NetBSD 0.9 or below," 139193326Sed echo "you should upgrade your file systems with 'fsck -c 2'" 140193326Sed echo "as soon as is feasible, because the new file system" 141193326Sed echo "code is better-tested and more performant." 142193326Sed upgrargs="" 143193326Sed upgradefs=NO 144193326Sed ;; 145193326Sed *) 146193326Sed upgrargs=$UARGS 147193326Sed upgradefs=YES 148193326Sed ;; 149193326Sedesac 150193326Sed 151193326Sedif [ $upgradefs = YES ]; then 152193326Sed echo "" 153193326Sed echo "your file systems will be upgraded while they are checked" 154193326Sedfi 155193326Sed 156193326Sedecho "checking the file system on ${drivename}a..." 157193326Sed 158193326Sedfsck -f -p $upgrargs /dev/r${drivename}a 159193326Sedif [ $? != 0 ]; then 160193326Sed echo "FATAL ERROR: FILE SYSTEM UPGRADE FAILED." 161193326Sed echo "You should probably reboot the machine, fsck your" 162193326Sed echo "disk(s), and try the upgrade procedure again." 163193326Sed exit 1 164193326Sedfi 165193326Sed 166193326Sedecho "" 167193326Sedecho "Mounting root partition on /mnt..." 168193326Sedmount /dev/${drivename}a /mnt 169193326Sedif [ $? != 0 ]; then 170193326Sed echo "FATAL ERROR: MOUNT FAILED." 171193326Sed echo "You should verify that your system is set up as you" 172193326Sed echo "described, and re-attempt the upgrade procedure." 173193326Sed exit 1 174193326Sedfi 175193326Sedecho "Done." 176193326Sed 177193326Sedecho "" 178193326Sedecho -n "Copying new fsck binary to your hard disk..." 179193326Sedif [ ! -d /mnt/sbin ]; then 180193326Sed mkdir /mnt/sbin 181193326Sedfi 182193326Sedcp /sbin/fsck /mnt/sbin/fsck 183193326Sedif [ $? != 0 ]; then 184193326Sed echo "FATAL ERROR: COPY FAILED." 185193326Sed echo "It in unclear why this error would occur. It looks" 186193326Sed echo "like you may end up having to upgrade by hand." 187193326Sed exit 1 188193326Sedfi 189193326Sedecho " Done." 190193326Sed 191193326Sedecho "" 192193326Sedecho "Re-mounting root partition read-only..." 193193326Sedmount -u -o ro /dev/${drivename}a /mnt 194193326Sedif [ $? != 0 ]; then 195193326Sed echo "FATAL ERROR: RE-MOUNT FAILED." 196193326Sed echo "It in unclear why this error would occur. It looks" 197193326Sed echo "like you may end up having to upgrade by hand." 198193326Sed exit 1 199193326Sedfi 200193326Sedecho "Done." 201193326Sed 202193326Sedecho "" 203193326Sedecho "checking the rest of your file systems..." 204193326Sedchroot /mnt fsck -f -p $upgrargs 205193326Sedif [ $? != 0 ]; then 206193326Sed echo "FATAL ERROR: FILE SYSTEM UPGRADE(S) FAILED." 207193326Sed echo "You should probably reboot the machine, fsck your" 208193326Sed echo "file system(s), and try the upgrade procedure" 209193326Sed echo "again." 210193326Sed exit 1 211193326Sedfi 212193326Sed echo "Done." 213193326Sed 214193326Sedecho "" 215193326Sedecho "Re-mounting root partition read-write..." 216193326Sedmount -u -o rw /dev/${drivename}a /mnt 217193326Sedif [ $? != 0 ]; then 218193326Sed echo "FATAL ERROR: RE-MOUNT FAILED." 219193326Sed echo "It in unclear why this error would occur. It looks" 220193326Sed echo "like you may end up having to upgrade by hand." 221193326Sed exit 1 222193326Sedfi 223193326Sedecho "Done." 224193326Sed 225193326Sedecho "" 226193326Sedecho "Updating boot blocks on ${drivename}..." 227193326Sed# shouldn't be needed, but... 228193326Sed$DONTDOIT rm -f /mnt/boot 229193326Sed$DONTDOIT cp /usr/mdec/boot /mnt/boot 230193326Sed$DONTDOIT /usr/sbin/installboot /dev/r${drivename}c /usr/mdec/bootxx_ffs 231193326Sedif [ $? != 0 ]; then 232193326Sed echo "FATAL ERROR: UPDATE OF DISK LABEL FAILED." 233193326Sed echo "It in unclear why this error would occur. It looks" 234193326Sed echo "like you may end up having to upgrade by hand." 235193326Sed exit 1 236193326Sedfi 237193326Sedecho "Done." 238193326Sed 239193326Sedecho "" 240193326Sedecho "Copying bootstrapping binaries and config files to the hard drive..." 241193326Sed$DONTDOIT cp /mnt/.profile /mnt/.profile.bak 242193326Sed$DONTDOIT pax -s '#^\./etc/.*##' -Xrwpe . /mnt 243193326Sed$DONTDOIT mv /mnt/etc/rc /mnt/etc/rc.bak 244193326Sed$DONTDOIT cp /tmp/.hdprofile /mnt/.profile 245193326Sed 246193326Sedecho "" 247193326Sedecho "Mounting remaining partitions..." 248193326Sedchroot /mnt mount -at ffs > /dev/null 2>&1 249193326Sedecho "Done." 250193326Sed 251193326Sedecho "" 252193326Sedecho "" 253193326Sedecho "OK! The preliminary work of setting up your disk is now complete," 254193326Sedecho "and you can now upgrade the actual NetBSD software." 255193326Sedecho "" 256193326Sedecho "Right now, your hard disk is mounted on /mnt. You should consult" 257193326Sedecho "the installation notes to determine how to load and install the new" 258193326Sedecho "NetBSD distribution sets, and how to clean up after the upgrade" 259193326Sedecho "software, when you are done." 260193326Sedecho "" 261193326Sedecho "GOOD LUCK!" 262193326Sedecho "" 263193326Sed