1 1.1 leo #!/bin/sh 2 1.5 andvar # $NetBSD: install.sh,v 1.5 2022/12/30 09:08:47 andvar Exp $ 3 1.1 leo # 4 1.1 leo # Copyright (c) 1996 The NetBSD Foundation, Inc. 5 1.1 leo # All rights reserved. 6 1.1 leo # 7 1.1 leo # This code is derived from software contributed to The NetBSD Foundation 8 1.1 leo # by Jason R. Thorpe. 9 1.1 leo # 10 1.1 leo # Redistribution and use in source and binary forms, with or without 11 1.1 leo # modification, are permitted provided that the following conditions 12 1.1 leo # are met: 13 1.1 leo # 1. Redistributions of source code must retain the above copyright 14 1.1 leo # notice, this list of conditions and the following disclaimer. 15 1.1 leo # 2. Redistributions in binary form must reproduce the above copyright 16 1.1 leo # notice, this list of conditions and the following disclaimer in the 17 1.1 leo # documentation and/or other materials provided with the distribution. 18 1.1 leo # 19 1.1 leo # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 leo # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 leo # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 leo # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 leo # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 leo # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 leo # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 leo # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 leo # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 leo # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 leo # POSSIBILITY OF SUCH DAMAGE. 30 1.1 leo # 31 1.1 leo 32 1.1 leo # NetBSD installation script. 33 1.1 leo # In a perfect world, this would be a nice C program, with a reasonable 34 1.1 leo # user interface. 35 1.1 leo 36 1.4 andvar FILESYSTEMS="/tmp/filesystems" # used throughout 37 1.1 leo MODE="install" 38 1.1 leo 39 1.1 leo # include machine-dependent functions 40 1.1 leo # The following functions must be provided: 41 1.1 leo # md_prep_disklabel() - label the root disk 42 1.1 leo # md_welcome_banner() - display friendly message 43 1.1 leo # md_congrats() - display friendly message 44 1.1 leo # md_makerootwritable() - make root writable (at least /tmp) 45 1.1 leo 46 1.1 leo # we need to make sure .'s below work if this directory is not in $PATH 47 1.3 christos case $0 in 48 1.3 christos */*) Mydir=${0%/*};; 49 1.3 christos *) Mydir=.;; 50 1.3 christos esac 51 1.3 christos Mydir=$(cd "${Mydir}" && pwd) 52 1.1 leo 53 1.1 leo # 54 1.1 leo # Sub-parts 55 1.1 leo # 56 1.1 leo getresp() { 57 1.1 leo read resp 58 1.3 christos if [ -z "$resp" ]; then 59 1.1 leo resp=$1 60 1.1 leo fi 61 1.1 leo } 62 1.1 leo 63 1.1 leo isin() { 64 1.5 andvar # test the first argument against the remaining ones, return success on a match 65 1.3 christos local a=$1 66 1.3 christos shift 67 1.1 leo while [ $# != 0 ]; do 68 1.3 christos if [ "$a" = "$1" ]; then return 0; fi 69 1.1 leo shift 70 1.1 leo done 71 1.1 leo return 1 72 1.1 leo } 73 1.1 leo 74 1.1 leo getrootdisk() { 75 1.1 leo cat << \__getrootdisk_1 76 1.1 leo 77 1.1 leo The installation program needs to know which disk to consider 78 1.1 leo the root disk. Note the unit number may be different than 79 1.1 leo the unit number you used in the standalone installation 80 1.1 leo program. 81 1.1 leo 82 1.1 leo Available disks are: 83 1.1 leo 84 1.1 leo __getrootdisk_1 85 1.1 leo _DKDEVS=`md_get_diskdevs` 86 1.1 leo echo "$_DKDEVS" 87 1.1 leo echo "" 88 1.1 leo echo -n "Which disk is the root disk? " 89 1.1 leo getresp "" 90 1.1 leo if isin $resp $_DKDEVS ; then 91 1.1 leo ROOTDISK="$resp" 92 1.1 leo else 93 1.1 leo echo "" 94 1.1 leo echo "The disk $resp does not exist." 95 1.1 leo ROOTDISK="" 96 1.1 leo fi 97 1.1 leo } 98 1.1 leo 99 1.1 leo labelmoredisks() { 100 1.1 leo cat << \__labelmoredisks_1 101 1.1 leo 102 1.1 leo You may label the following disks: 103 1.1 leo 104 1.1 leo __labelmoredisks_1 105 1.1 leo echo "$_DKDEVS" 106 1.1 leo echo "" 107 1.1 leo echo -n "Label which disk? [done] " 108 1.1 leo getresp "done" 109 1.1 leo case "$resp" in 110 1.1 leo "done") 111 1.1 leo ;; 112 1.1 leo 113 1.1 leo *) 114 1.1 leo if isin $resp $_DKDEVS ; then 115 1.1 leo md_labeldisk $resp 116 1.1 leo else 117 1.1 leo echo "" 118 1.1 leo echo "The disk $resp does not exist." 119 1.1 leo fi 120 1.1 leo ;; 121 1.1 leo esac 122 1.1 leo } 123 1.1 leo 124 1.1 leo # 125 1.1 leo # include machine dependent subroutines 126 1.1 leo . $Mydir/install.md 127 1.1 leo 128 1.1 leo # Good {morning,afternoon,evening,night}. 129 1.1 leo md_welcome_banner 130 1.1 leo echo -n "Proceed? [n] " 131 1.1 leo getresp "n" 132 1.1 leo case "$resp" in 133 1.1 leo y*|Y*) 134 1.1 leo echo "Cool! Let's get to it..." 135 1.1 leo ;; 136 1.1 leo *) 137 1.1 leo md_not_going_to_install 138 1.1 leo exit 139 1.1 leo ;; 140 1.1 leo esac 141 1.1 leo 142 1.1 leo # XXX Work around vnode aliasing bug (thanks for the tip, Chris...) 143 1.1 leo ls -l /dev > /dev/null 2>&1 144 1.1 leo 145 1.1 leo # Deal with terminal issues 146 1.1 leo md_set_term 147 1.1 leo 148 1.1 leo # Make sure we can write files (at least in /tmp) 149 1.1 leo # This might make an MFS mount on /tmp, or it may 150 1.1 leo # just re-mount the root with read-write enabled. 151 1.1 leo md_makerootwritable 152 1.1 leo 153 1.1 leo while [ "X${ROOTDISK}" = "X" ]; do 154 1.1 leo getrootdisk 155 1.1 leo done 156 1.1 leo 157 1.1 leo # Deal with disklabels, including editing the root disklabel 158 1.1 leo # and labeling additional disks. This is machine-dependent since 159 1.1 leo # some platforms may not be able to provide this functionality. 160 1.1 leo md_prep_disklabel ${ROOTDISK} 161 1.1 leo 162 1.1 leo # Pat on the back. 163 1.1 leo md_congrats 164 1.1 leo 165 1.1 leo # ALL DONE! 166 1.1 leo exit 0 167