upgrade.sh revision 1.12
1#!/bin/sh 2# $NetBSD: upgrade.sh,v 1.12 1997/10/09 07:25:52 jtc Exp $ 3# 4# Copyright (c) 1996 The NetBSD Foundation, Inc. 5# All rights reserved. 6# 7# This code is derived from software contributed to The NetBSD Foundation 8# by Jason R. Thorpe. 9# 10# Redistribution and use in source and binary forms, with or without 11# modification, are permitted provided that the following conditions 12# are met: 13# 1. Redistributions of source code must retain the above copyright 14# notice, this list of conditions and the following disclaimer. 15# 2. Redistributions in binary form must reproduce the above copyright 16# notice, this list of conditions and the following disclaimer in the 17# documentation and/or other materials provided with the distribution. 18# 3. All advertising materials mentioning features or use of this software 19# must display the following acknowledgement: 20# This product includes software developed by the NetBSD 21# Foundation, Inc. and its contributors. 22# 4. Neither the name of The NetBSD Foundation nor the names of its 23# contributors may be used to endorse or promote products derived 24# from this software without specific prior written permission. 25# 26# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36# POSSIBILITY OF SUCH DAMAGE. 37# 38 39# NetBSD installation script. 40# In a perfect world, this would be a nice C program, with a reasonable 41# user interface. 42 43ROOTDISK="" # filled in below 44 45trap "unmount_fs -fast /tmp/fstab.shadow > /dev/null 2>&1; rm -f /tmp/fstab.shadow" 0 46 47MODE="upgrade" 48 49# include machine-dependent functions 50# The following functions must be provided: 51# md_copy_kernel() - copy a kernel to the installed disk 52# md_get_diskdevs() - return available disk devices 53# md_get_cddevs() - return available CD-ROM devices 54# md_get_ifdevs() - return available network interfaces 55# md_get_partition_range() - return range of valid partition letters 56# md_installboot() - install boot-blocks on disk 57# md_labeldisk() - put label on a disk 58# md_welcome_banner() - display friendly message 59# md_not_going_to_install() - display friendly message 60# md_congrats() - display friendly message 61 62# include machine dependent subroutines 63. install.md 64 65# include common subroutines 66. install.sub 67 68# which sets? 69THESETS="$UPGRSETS" 70 71# Files that moved between 1.2 and 1.3 72RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/mountd /usr/sbin/mountd" 73RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/rtquey /usr/sbin/rtquery" 74RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/quotacheck /usr/sbin/quotacheck" 75RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumpfs /usr/sbin/dumpfs" 76RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumplfs /usr/sbin/dumplfs" 77 78rm_relocated_files() 79{ 80 # ($n, $(n+1)): pairs of (old,new) locations of relocated files 81 while [ $# -ge 2 ]; do 82 if [ -f "$2" ]; then 83 echo Removing "$1"; 84 rm -f "$1" 85 fi 86 shift 2 87 done 88} 89 90# Good {morning,afternoon,evening,night}. 91md_welcome_banner 92echo -n "Proceed with upgrade? [n] " 93getresp "n" 94case "$resp" in 95 y*|Y*) 96 echo "Cool! Let's get to it..." 97 ;; 98 *) 99 md_not_going_to_install 100 exit 101 ;; 102esac 103 104# Deal with terminal issues 105md_set_term 106 107# XXX Work around vnode aliasing bug (thanks for the tip, Chris...) 108ls -l /dev > /dev/null 2>&1 109 110# Make sure we can write files (at least in /tmp) 111# This might make an MFS mount on /tmp, or it may 112# just re-mount the root with read-write enabled. 113md_makerootwritable 114 115while [ "X${ROOTDISK}" = "X" ]; do 116 getrootdisk 117done 118 119# Assume partition 'a' of $ROOTDISK is for the root filesystem. Confirm 120# this with the user. Check and mount the root filesystem. 121resp="" # force one iteration 122while [ "X${resp}" = "X" ]; do 123 echo -n "Root filesystem? [${ROOTDISK}a] " 124 getresp "${ROOTDISK}a" 125 _root_filesystem="/dev/`basename $resp`" 126 if [ ! -b ${_root_filesystem} ]; then 127 echo "Sorry, ${resp} is not a block device." 128 resp="" # force loop to repeat 129 fi 130done 131 132echo "Checking root filesystem..." 133if ! fsck -pf ${_root_filesystem}; then 134 echo "ERROR: can't check root filesystem!" 135 exit 1 136fi 137 138echo "Mounting root filesystem..." 139if ! mount -o ro ${_root_filesystem} /mnt; then 140 echo "ERROR: can't mount root filesystem!" 141 exit 1 142fi 143 144# Grab the fstab so we can munge it for our own use. 145if [ ! -f /mnt/etc/fstab ]; then 146 echo "ERROR: no /etc/fstab!" 147 exit 1 148fi 149 150# Grab the hosts table so we can use it. 151if [ ! -f /mnt/etc/hosts ]; then 152 echo "ERROR: no /etc/hosts!" 153 exit 1 154fi 155cp /mnt/etc/hosts /tmp/hosts 156 157# Start up the network in same/similar configuration as the installed system 158# uses. 159cat << \__network_config_1 160 161The upgrade program would now like to enable the network. It will use the 162configuration already stored on the root filesystem. This is required 163if you wish to use the network installation capabilities of this program. 164 165__network_config_1 166echo -n "Enable network? [y] " 167getresp "y" 168case "$resp" in 169 y*|Y*) 170 if ! enable_network; then 171 echo "ERROR: can't enable network!" 172 exit 1 173 fi 174 175 cat << \__network_config_2 176 177You will now be given the opportunity to escape to the command shell to 178do any additional network configuration you may need. This may include 179adding additional routes, if needed. In addition, you might take this 180opportunity to redo the default route in the event that it failed above. 181 182__network_config_2 183 echo -n "Escape to shell? [n] " 184 getresp "n" 185 case "$resp" in 186 y*|Y*) 187 echo "Type 'exit' to return to upgrade." 188 sh 189 ;; 190 191 *) 192 ;; 193 esac 194 ;; 195 *) 196 ;; 197esac 198 199# Now that the network has been configured, it is safe to configure the 200# fstab. We remove all but ufs/ffs. 201( 202 > /tmp/fstab 203 while read _dev _mp _fstype _rest ; do 204 if [ "X${_fstype}" = X"ufs" -o \ 205 "X${_fstype}" = X"ffs" ]; then 206 if [ "X${_fstype}" = X"ufs" ]; then 207 # Convert ufs to ffs. 208 _fstype=ffs 209 fi 210 echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab 211 fi 212 done 213) < /mnt/etc/fstab 214 215echo "The fstab is configured as follows:" 216echo "" 217cat /tmp/fstab 218cat << \__fstab_config_1 219 220You may wish to edit the fstab. For example, you may need to resolve 221dependencies in the order which the filesystems are mounted. Note that 222this fstab is only for installation purposes, and will not be copied into 223the root filesystem. 224 225__fstab_config_1 226echo -n "Edit the fstab? [n] " 227getresp "n" 228case "$resp" in 229 y*|Y*) 230 ${EDITOR} /tmp/fstab 231 ;; 232 233 *) 234 ;; 235esac 236 237echo "" 238munge_fstab /tmp/fstab /tmp/fstab.shadow 239 240if ! umount /mnt; then 241 echo "ERROR: can't unmount previously mounted root!" 242 exit 1 243fi 244 245# Check all of the filesystems. 246check_fs /tmp/fstab.shadow 247 248# Mount filesystems. 249mount_fs /tmp/fstab.shadow 250 251echo -n "Are the upgrade sets on one of your normally mounted (local) filesystems? [y] " 252getresp "y" 253case "$resp" in 254 y*|Y*) 255 get_localdir /mnt 256 ;; 257 *) 258 ;; 259esac 260 261# Install sets. 262install_sets 263 264# Remove files that have just been installed in a new location 265# from the old location 266rm_relocated_files `eval echo \\$RELOCATED_FILES_${VERSION}` 267 268# Get timezone info 269get_timezone 270 271# Fix up the fstab. 272echo -n "Converting ufs to ffs in /etc/fstab..." 273( 274 > /tmp/fstab 275 while read _dev _mp _fstype _rest ; do 276 if [ "X${_fstype}" = X"ufs" ]; then 277 # Convert ufs to ffs. 278 _fstype=ffs 279 fi 280 echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab 281 done 282) < /mnt/etc/fstab 283echo "done." 284echo -n "Would you like to edit the resulting fstab? [y] " 285getresp "y" 286case "$resp" in 287 y*|Y*) 288 ${EDITOR} /tmp/fstab 289 ;; 290 291 *) 292 ;; 293esac 294 295# Copy in configuration information and make devices in target root. 296( 297 cd /tmp 298 for file in fstab; do 299 if [ -f $file ]; then 300 echo -n "Copying $file..." 301 cp $file /mnt/etc/$file 302 echo "done." 303 fi 304 done 305 306 echo -n "Installing timezone link..." 307 rm -f /mnt/etc/localtime 308 ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime 309 echo "done." 310 311 echo -n "Making devices..." 312 _pid=`twiddle` 313 cd /mnt/dev 314 sh MAKEDEV all 315 kill $_pid 316 echo "done." 317 318 md_copy_kernel 319 320 md_installboot ${ROOTDISK} 321) 322 323unmount_fs /tmp/fstab.shadow 324 325# Pat on the back. 326md_congrats 327 328# ALL DONE! 329exit 0 330