1#!/bin/sh 2# 3# Copyright (c) 1994 Christopher G. Demetriou 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 3. All advertising materials mentioning features or use of this software 15# must display the following acknowledgement: 16# This product includes software developed by Christopher G. Demetriou. 17# 4. The name of the author may not be used to endorse or promote products 18# derived from this software without specific prior written permission 19# 20# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30# 31# $NetBSD: upgrade.sh,v 1.5 1999/01/25 23:34:20 garbled Exp $ 32 33# NetBSD upgrade script. 34# In a perfect world, this would be a nice C program, with a reasonable 35# user interface. 36 37#DONTDOIT=echo 38 39VERSION=1.2 40 41getresp() { 42 read resp 43 if [ "X$resp" = "X" ]; then 44 resp=$1 45 fi 46} 47 48getvar() { 49 echo $(eval $(echo "echo \$$1")) 50} 51 52shiftvar() { 53 local - var 54 var="$1" 55 list="$(getvar $var)" 56 set -- $list 57 shift 58 setvar $var "$*" 59} 60 61getparts() { 62 disklabel $1 2>/dev/null | sed -e '/^[ ][ ][ad-p]/!d' | 63 sed -e 's,^[ ]*\([a-p]\):[ ]*[0-9]*[ ]*[0-9]*[ ][ ]*\([a-zA-Z0-9.]*\).*,\1 \2,' | 64 sed -e ':a 65 N;${s/\n/ /g;p;d;} 66 ba' 67} 68 69getdrives() { 70 local du thispart 71 for du in /dev/rsd?a; do 72 dd if=$du of=/dev/null bs=1b count=1 >/dev/null 2>&1 73 if [ $? -eq 0 ]; then 74 thisunit=`echo $du | sed -e 's,/dev/r\(...\)a,\1,g'` 75 driveunits="$driveunits $thisunit" 76 else 77 continue; 78 fi 79 setvar $thisunit "$(getparts $thisunit)" 80 export $thisunit 81 done 82 export drivenunits 83} 84 85Convert_fstab() { 86 if [ ! -e /mnt/etc/fstab.ufs ]; then 87 mv /mnt/etc/fstab /mnt/etc/fstab.ufs 88 fi 89 sed "s/ufs/ffs/" /mnt/etc/fstab.ufs >/mnt/etc/fstab 90} 91 92echo "Welcome to the NetBSD ${VERSION} upgrade program." 93echo "" 94echo "This program is designed to help you put the new version of NetBSD" 95echo "on your hard disk, in a simple and rational way. To upgrade, you" 96echo "must have plenty of free space on all partitions which will be" 97echo "upgraded. If you have at least 1MB free on your root partition," 98echo "and several free on your /usr patition, you should be fine." 99echo "" 100echo "As with anything which modifies your hard drive's contents, this" 101echo "program can cause SIGNIFICANT data loss, and you are advised" 102echo "to make sure your hard drive is backed up before beginning the" 103echo "upgrade process." 104echo "" 105echo "Default answers are displayed in brackets after the questions." 106echo "You can hit Control-C at any time to quit, but if you do so at a" 107echo "prompt, you may have to hit return. Also, quitting in the middle of" 108echo "the upgrade may leave your system in an inconsistent (and unusable)" 109echo "state." 110echo "" 111echo -n "Proceed with upgrade? [n] " 112getresp "n" 113case "$resp" in 114 y*|Y*) 115 echo "Cool! Let's get to it..." 116 ;; 117 *) 118 echo "" 119 echo "OK, then. Enter 'halt' at the prompt to halt the" 120 echo "machine. Once the machine has halted, remove the" 121 echo "floppy and press any key to reboot." 122 exit 123 ;; 124esac 125 126# find out what units are possible, and query the user. 127 128getdrives 129 130if [ "X${driveunits}" = "X" ]; then 131 echo "FATAL ERROR:" 132 echo "No disk devices." 133 echo "This is probably a bug in the install disks." 134 echo "Exiting install program." 135 exit 136fi 137 138echo "" 139echo "The following disks are supported by this upgrade procedure:" 140echo " "${driveunits} 141echo "" 142echo "If your system was previously completely contained within the" 143echo "disks listed above (i.e. if your system didn't occupy any space" 144echo "on disks NOT listed above), this upgrade disk can upgrade your" 145echo "system. If it cannot, hit Control-C at the prompt." 146echo "" 147while [ "X${drivename}" = "X" ]; do 148 echo -n "Which disk contains your root partion? " 149 getresp 150 otherdrives=`echo "${driveunits}" | sed -e s,${resp},,` 151 if [ "X${driveunits}" = "X${otherdrives}" ]; then 152 echo "" 153 echo "\"${resp}\" is an invalid drive name. Valid choices" 154 echo "are: "${driveunits} 155 echo "" 156 else 157 drivename=${resp} 158 fi 159done 160 161echo "" 162echo "Root partition is on ${drivename}a." 163 164echo "" 165echo "If you've still installed 0.9 or earlier on your machine or you" 166echo "haven't upgraded your pre-1.0 filesystems, then you might want to" 167echo "upgrade the filesystem to the version introduced with 1.0." 168echo "" 169echo "Would you like to upgrade your file systems to the new file system" 170echo -n "format? [y] " 171getresp "y" 172case "$resp" in 173 n*|N*) 174 echo "" 175 echo "You should upgrade your file systems with 'fsck -c 2'" 176 echo "as soon as is feasible, because the new file system" 177 echo "code is better-tested and more performant." 178 upgradefs=NO 179 ;; 180 *) 181 upgradefs=YES 182 ;; 183esac 184 185if [ $upgradefs = YES ]; then 186 echo "" 187 echo "Upgrading the file system on ${drivename}a..." 188 189 $DONTDOIT fsck -p -c 2 /dev/r${drivename}a 190 if [ $? != 0 ]; then 191 echo "FATAL ERROR: FILE SYSTEM UPGRADE FAILED." 192 echo "You should probably reboot the machine, fsck your" 193 echo "disk(s), and try the upgrade procedure again." 194 exit 1 195 fi 196 echo "Done." 197fi 198 199echo "" 200echo "Mounting root partition on /mnt..." 201$DONTDOIT mount /dev/${drivename}a /mnt 202if [ $? != 0 ]; then 203 echo "FATAL ERROR: MOUNT FAILED." 204 echo "You should verify that your system is set up as you" 205 echo "described, and re-attempt the upgrade procedure." 206 exit 1 207fi 208echo "Done." 209 210#<<<<<<<<<<<<<<<<<<<<<<<< update etc/fstab to ffs? >>>>>>>>>>>>>>>>>>>>>>>> 211echo "" 212echo -n "Converting ufs entries in fstab to ffs..." 213$DONTDOIT Convert_fstab 214echo "Done." 215 216if [ $upgradefs = YES ]; then 217 echo "" 218 echo -n "Copying new fsck binary to your hard disk..." 219 if [ ! -d /mnt/sbin ]; then 220 $DONTDOIT mkdir /mnt/sbin 221 fi 222 $DONTDOIT cp /sbin/fsck /mnt/sbin/fsck 223 if [ $? != 0 ]; then 224 echo "FATAL ERROR: COPY FAILED." 225 echo "It in unclear why this error would occur. It looks" 226 echo "like you may end up having to upgrade by hand." 227 exit 1 228 fi 229 $DONTDOIT sync 230 echo " Done." 231 232 echo "" 233 echo "Re-mounting root partition read-only..." 234 $DONTDOIT mount -u -o ro /dev/${drivename}a /mnt 235 if [ $? != 0 ]; then 236 echo "FATAL ERROR: RE-MOUNT FAILED." 237 echo "It in unclear why this error would occur. It looks" 238 echo "like you may end up having to upgrade by hand." 239 exit 1 240 fi 241 echo "Done." 242 243 echo "" 244 echo "Upgrading the rest of your file systems..." 245 $DONTDOIT chroot /mnt fsck -p -c 2 246 if [ $? != 0 ]; then 247 echo "FATAL ERROR: FILE SYSTEM UPGRADE(S) FAILED." 248 echo "You should probably reboot the machine, fsck your" 249 echo "file system(s), and try the upgrade procedure" 250 echo "again." 251 exit 1 252 fi 253 echo "Done." 254 255 echo "" 256 echo "Re-mounting root partition read-write..." 257 $DONTDOIT mount -u -o rw /dev/${drivename}a /mnt 258 if [ $? != 0 ]; then 259 echo "FATAL ERROR: RE-MOUNT FAILED." 260 echo "It in unclear why this error would occur. It looks" 261 echo "like you may end up having to upgrade by hand." 262 exit 1 263 fi 264 echo "Done." 265fi 266 267echo "" 268echo "Copying bootstrapping binaries and config files to the hard drive..." 269$DONTDOIT pax -rwpe sbin/mount_ffs /mnt 270 271echo "" 272echo "Mounting remaining partitions..." 273$DONTDOIT chroot /mnt mount -at ffs > /dev/null 2>&1 274echo "Done." 275 276echo "" 277echo "" 278echo "OK! The preliminary work of setting up your disk is now complete," 279echo "and you can now upgrade the actual NetBSD software." 280echo "" 281echo "Right now, your hard disk is mounted on /mnt. You should consult" 282echo "the installation notes to determine how to load and install the new" 283echo "NetBSD distribution sets, and how to clean up after the upgrade" 284echo "software, when you are done." 285echo "" 286echo "GOOD LUCK!" 287echo "" 288