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