1#!/bin/sh 2#- 3# Copyright (c) 2011 Nathan Whitehorn 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# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# 27# $FreeBSD$ 28 29echo "Begun Installation at $(date)" > $BSDINSTALL_LOG 30 31error() { 32 dialog --backtitle "FreeBSD Installer" --title "Abort" \ 33 --no-label "Exit" --yes-label "Restart" --yesno \ 34 "An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0 35 if [ $? -ne 0 ]; then 36 exit 37 else 38 test -f $PATH_FSTAB && bsdinstall umount 39 exec $0 40 fi 41} 42 43 44rm -rf $BSDINSTALL_TMPETC 45mkdir $BSDINSTALL_TMPETC 46 47trap true SIGINT # This section is optional 48bsdinstall keymap 49 50trap error SIGINT # Catch cntrl-C here 51bsdinstall hostname || error 52 53LIB32="" 54[ `uname -p` = amd64 -o `uname -p` = powerpc64 ] && \ 55 LIB32="lib32 \"32-bit compatibility\" on" 56 57DISTMENU="doc \"Additional documentation\" on \ 58 games \"Games (fortune, etc.)\" on \ 59 $LIB32 \ 60 ports \"Ports tree\" on \ 61 src \"System source code\" off" 62 63exec 3>&1 64EXTRA_DISTS=$(echo $DISTMENU | xargs dialog --backtitle "FreeBSD Installer" \ 65 --title "Distribution Select" --nocancel --separate-output \ 66 --checklist "Choose optional system components to install:" \ 67 0 0 0 \ 682>&1 1>&3) 69DISTRIBUTIONS="base.txz kernel.txz" 70for dist in $EXTRA_DISTS; do 71 export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz" 72done 73 74FETCH_DISTRIBUTIONS="" 75for dist in $DISTRIBUTIONS; do 76 if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then 77 FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist" 78 fi 79done 80 81if [ ! -z "$FETCH_DISTRIBUTIONS" -a ! -z $BSDINSTALL_CONFIGCURRENT ]; then 82 dialog --backtitle "FreeBSD Installer" --title "Network Installation" --msgbox "No installation files were found on the boot volume. The next few screens will allow you to configure networking so that they can be downloaded from the Internet." 0 0 83 bsdinstall netconfig || error 84 NETCONFIG_DONE=yes 85fi 86 87rm $PATH_FSTAB 88touch $PATH_FSTAB 89 90dialog --backtitle "FreeBSD Installer" --title "Partitioning" --extra-button \ 91 --extra-label "Manual" --ok-label "Guided" --cancel-label "Shell" \ 92 --yesno "Would you like to use the guided partitioning tool (recommended for beginners) or to set up partitions manually (experts)? You can also open a shell and set up partitions entirely by hand." 0 0 93 94case $? in 950) # Guided 96 bsdinstall autopart || error 97 bsdinstall mount || error 98 ;; 991) # Shell 100 clear 101 echo "Use this shell to set up partitions for the new system. When finished, mount the system at $BSDINSTALL_CHROOT and place an fstab file for the new system at $PATH_FSTAB. Then type 'exit'. You can also enter the partition editor at any time by entering 'bsdinstall partedit'." 102 sh 103 ;; 1043) # Manual 105 bsdinstall partedit || error 106 bsdinstall mount || error 107 ;; 108*) 109 error 110 ;; 111esac 112 113if [ ! -z "$FETCH_DISTRIBUTIONS" ]; then 114 ALL_DISTRIBUTIONS="$DISTRIBUTIONS" 115 116 # Download to a directory in the new system as scratch space 117 BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/bsdinstall-dist" 118 mkdir -p "$BSDINSTALL_FETCHDEST" || error 119 120 export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS" 121 # Try to use any existing distfiles 122 [ -d $BSDINSTALL_DISTDIR -a "$FETCH_DISTRIBUTIONS" != "$ALL_DISTRIBUTIONS" ] && mount_unionfs "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR" 123 124 # Otherwise, fetch everything 125 if [ $? -ne 0 ]; then 126 export DISTRIBUTIONS="$ALL_DISTRIBUTIONS" 127 export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST" 128 fi 129 130 bsdinstall distfetch || error 131 export DISTRIBUTIONS="$ALL_DISTRIBUTIONS" 132fi 133 134bsdinstall distextract || error 135bsdinstall rootpass || error 136 137trap true SIGINT # This section is optional 138if [ "$NETCONFIG_DONE" != yes ]; then 139 bsdinstall netconfig # Don't check for errors -- the user may cancel 140fi 141bsdinstall time 142bsdinstall services 143 144dialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \ 145 "Would you like to add users to the installed system now?" 0 0 && \ 146 bsdinstall adduser 147 148finalconfig() { 149 exec 3>&1 150 REVISIT=$(dialog --backtitle "FreeBSD Installer" \ 151 --title "Final Configuration" --no-cancel --menu \ 152 "Setup of your FreeBSD system is nearly complete. You can now modify your configuration choices or apply more complex changes using a shell." 0 0 0 \ 153 "Add User" "Add a user to the system" \ 154 "Root Password" "Change root password" \ 155 "Hostname" "Set system hostname" \ 156 "Network" "Networking configuration" \ 157 "Services" "Set daemons to run on startup" \ 158 "Time Zone" "Set system timezone" \ 159 "Shell" "Open a shell in the new system" \ 160 "Reboot" "Apply configuration and reboot" 2>&1 1>&3) 161 exec 3>&- 162 163 case "$REVISIT" in 164 "Add User") 165 bsdinstall adduser 166 finalconfig 167 ;; 168 "Root Password") 169 bsdinstall rootpass 170 finalconfig 171 ;; 172 "Hostname") 173 bsdinstall hostname 174 finalconfig 175 ;; 176 "Network") 177 bsdinstall netconfig 178 finalconfig 179 ;; 180 "Services") 181 bsdinstall services 182 finalconfig 183 ;; 184 "Time Zone") 185 bsdinstall time 186 finalconfig 187 ;; 188 "Shell") 189 clear 190 echo This shell is operating in a chroot in the new system. \ 191 When finished making configuration changes, type \"exit\". 192 chroot "$BSDINSTALL_CHROOT" /bin/sh 193 # Don't hose local rc.conf changes 194 cp $BSDINSTALL_CHROOT/etc/rc.conf $BSDINSTALL_TMPETC/rc.conf.manual 195 finalconfig 196 ;; 197 esac 198} 199 200# Allow user to change his mind 201finalconfig 202 203trap error SIGINT # SIGINT is bad again 204bsdinstall config || error 205 206if [ ! -z "$BSDINSTALL_FETCHDEST" ]; then 207 [ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \ 208 umount "$BSDINSTALL_DISTDIR" 209 rm -rf "$BSDINSTALL_FETCHDEST" 210fi 211 212echo "Installation Completed at $(date)" >> $BSDINSTALL_LOG 213 214