upgrade.sh revision 1.16.2.1
1#!/bin/sh 2# $NetBSD: upgrade.sh,v 1.16.2.1 1999/04/13 17:20:42 is 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 $MDSETS" 70 71# Files that moved between 1.2 and 1.3 72RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumpfs /usr/sbin/dumpfs" 73RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumplfs /usr/sbin/dumplfs" 74RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/nfsd /usr/sbin/nfsd" 75RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/nfsiod /usr/sbin/nfsiod" 76RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/mountd /usr/sbin/mountd" 77RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/quotacheck /usr/sbin/quotacheck" 78RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/rtquery /usr/sbin/rtquery" 79 80rm_relocated_files() 81{ 82 # ($n, $(n+1)): pairs of (old,new) locations of relocated files 83 while [ $# -ge 2 ]; do 84 if [ -f "$2" ]; then 85 echo Removing "$1"; 86 rm -f "$1" 87 fi 88 shift 2 89 done 90} 91 92# Good {morning,afternoon,evening,night}. 93md_welcome_banner 94echo -n "Proceed with upgrade? [n] " 95getresp "n" 96case "$resp" in 97 y*|Y*) 98 echo "Cool! Let's get to it..." 99 ;; 100 *) 101 md_not_going_to_install 102 exit 103 ;; 104esac 105 106# Deal with terminal issues 107md_set_term 108 109# XXX Work around vnode aliasing bug (thanks for the tip, Chris...) 110ls -l /dev > /dev/null 2>&1 111 112# Make sure we can write files (at least in /tmp) 113# This might make an MFS mount on /tmp, or it may 114# just re-mount the root with read-write enabled. 115md_makerootwritable 116 117while [ "X${ROOTDISK}" = "X" ]; do 118 getrootdisk 119done 120 121# Assume partition 'a' of $ROOTDISK is for the root filesystem. Confirm 122# this with the user. Check and mount the root filesystem. 123resp="" # force one iteration 124while [ "X${resp}" = "X" ]; do 125 echo -n "Root filesystem? [${ROOTDISK}a] " 126 getresp "${ROOTDISK}a" 127 _root_filesystem="/dev/`basename $resp`" 128 if [ ! -b ${_root_filesystem} ]; then 129 echo "Sorry, ${resp} is not a block device." 130 resp="" # force loop to repeat 131 fi 132done 133 134echo "Checking root filesystem..." 135if ! fsck -pf ${_root_filesystem}; then 136 echo "ERROR: can't check root filesystem!" 137 exit 1 138fi 139 140echo "Mounting root filesystem..." 141if ! mount -o ro ${_root_filesystem} /mnt; then 142 echo "ERROR: can't mount root filesystem!" 143 exit 1 144fi 145 146# Grab the fstab so we can munge it for our own use. 147if [ ! -f /mnt/etc/fstab ]; then 148 echo "ERROR: no /etc/fstab!" 149 exit 1 150fi 151 152# Grab the hosts table so we can use it. 153if [ ! -f /mnt/etc/hosts ]; then 154 echo "ERROR: no /etc/hosts!" 155 exit 1 156fi 157cp /mnt/etc/hosts /tmp/hosts 158 159# Start up the network in same/similar configuration as the installed system 160# uses. 161cat << \__network_config_1 162 163The upgrade program would now like to enable the network. It will use the 164configuration already stored on the root filesystem. This is required 165if you wish to use the network installation capabilities of this program. 166 167__network_config_1 168echo -n "Enable network? [y] " 169getresp "y" 170case "$resp" in 171 y*|Y*) 172 if ! enable_network; then 173 echo "ERROR: can't enable network!" 174 exit 1 175 fi 176 177 cat << \__network_config_2 178 179You will now be given the opportunity to escape to the command shell to 180do any additional network configuration you may need. This may include 181adding additional routes, if needed. In addition, you might take this 182opportunity to redo the default route in the event that it failed above. 183 184__network_config_2 185 echo -n "Escape to shell? [n] " 186 getresp "n" 187 case "$resp" in 188 y*|Y*) 189 echo "Type 'exit' to return to upgrade." 190 sh 191 ;; 192 193 *) 194 ;; 195 esac 196 ;; 197 *) 198 ;; 199esac 200 201# Now that the network has been configured, it is safe to configure the 202# fstab. We remove all but ufs/ffs. 203( 204 > /tmp/fstab 205 while read _dev _mp _fstype _rest ; do 206 if [ "X${_fstype}" = X"ufs" -o \ 207 "X${_fstype}" = X"ffs" ]; then 208 if [ "X${_fstype}" = X"ufs" ]; then 209 # Convert ufs to ffs. 210 _fstype=ffs 211 fi 212 echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab 213 fi 214 done 215) < /mnt/etc/fstab 216 217echo "The fstab is configured as follows:" 218echo "" 219cat /tmp/fstab 220cat << \__fstab_config_1 221 222You may wish to edit the fstab. For example, you may need to resolve 223dependencies in the order which the filesystems are mounted. Note that 224this fstab is only for installation purposes, and will not be copied into 225the root filesystem. 226 227__fstab_config_1 228echo -n "Edit the fstab? [n] " 229getresp "n" 230case "$resp" in 231 y*|Y*) 232 ${EDITOR} /tmp/fstab 233 ;; 234 235 *) 236 ;; 237esac 238 239echo "" 240munge_fstab /tmp/fstab /tmp/fstab.shadow 241 242if ! umount /mnt; then 243 echo "ERROR: can't unmount previously mounted root!" 244 exit 1 245fi 246 247# Check all of the filesystems. 248check_fs /tmp/fstab.shadow 249 250# Mount filesystems. 251mount_fs /tmp/fstab.shadow 252 253echo -n "Are the upgrade sets on one of your normally mounted (local) filesystems? [y] " 254getresp "y" 255case "$resp" in 256 y*|Y*) 257 get_localdir /mnt 258 ;; 259 *) 260 ;; 261esac 262 263# Install sets. 264install_sets 265 266# Remove files that have just been installed in a new location 267# from the old location 268rm_relocated_files `eval echo \\$RELOCATED_FILES_${VERSION}` 269 270# Get timezone info 271get_timezone 272 273# Fix up the fstab. 274echo -n "Converting ufs to ffs in /etc/fstab..." 275( 276 > /tmp/fstab 277 while read _dev _mp _fstype _rest ; do 278 if [ "X${_fstype}" = X"ufs" ]; then 279 # Convert ufs to ffs. 280 _fstype=ffs 281 fi 282 echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab 283 done 284) < /mnt/etc/fstab 285echo "done." 286echo -n "Would you like to edit the resulting fstab? [y] " 287getresp "y" 288case "$resp" in 289 y*|Y*) 290 ${EDITOR} /tmp/fstab 291 ;; 292 293 *) 294 ;; 295esac 296 297# Copy in configuration information and make devices in target root. 298( 299 cd /tmp 300 for file in fstab; do 301 if [ -f $file ]; then 302 echo -n "Copying $file..." 303 cp $file /mnt/etc/$file 304 echo "done." 305 fi 306 done 307 308 echo -n "Installing timezone link..." 309 rm -f /mnt/etc/localtime 310 ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime 311 echo "done." 312 313 echo -n "Making devices..." 314 _pid=`twiddle` 315 cd /mnt/dev 316 sh MAKEDEV all 317 kill $_pid 318 echo "done." 319 320 md_copy_kernel 321 322 md_installboot ${ROOTDISK} 323) 324 325unmount_fs /tmp/fstab.shadow 326 327# Pat on the back. 328md_congrats 329 330# ALL DONE! 331exit 0 332