1*2118f387SNathan Whitehorn#!/bin/sh 2*2118f387SNathan Whitehorn#- 3*2118f387SNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn 4*2118f387SNathan Whitehorn# All rights reserved. 5*2118f387SNathan Whitehorn# 6*2118f387SNathan Whitehorn# Redistribution and use in source and binary forms, with or without 7*2118f387SNathan Whitehorn# modification, are permitted provided that the following conditions 8*2118f387SNathan Whitehorn# are met: 9*2118f387SNathan Whitehorn# 1. Redistributions of source code must retain the above copyright 10*2118f387SNathan Whitehorn# notice, this list of conditions and the following disclaimer. 11*2118f387SNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright 12*2118f387SNathan Whitehorn# notice, this list of conditions and the following disclaimer in the 13*2118f387SNathan Whitehorn# documentation and/or other materials provided with the distribution. 14*2118f387SNathan Whitehorn# 15*2118f387SNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*2118f387SNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*2118f387SNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*2118f387SNathan Whitehorn# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*2118f387SNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*2118f387SNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*2118f387SNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*2118f387SNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*2118f387SNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*2118f387SNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*2118f387SNathan Whitehorn# SUCH DAMAGE. 26*2118f387SNathan Whitehorn# 27*2118f387SNathan Whitehorn# $FreeBSD$ 28*2118f387SNathan Whitehorn 29*2118f387SNathan Whitehornecho "Begun Installation at $(date)" > $BSDINSTALL_LOG 30*2118f387SNathan Whitehorn 31*2118f387SNathan Whitehornerror() { 32*2118f387SNathan Whitehorn dialog --backtitle "FreeBSD Installer" --title "Abort" \ 33*2118f387SNathan Whitehorn --no-label "Exit" --yes-label "Restart" --yesno \ 34*2118f387SNathan Whitehorn "An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0 35*2118f387SNathan Whitehorn if [ $? -ne 0 ]; then 36*2118f387SNathan Whitehorn exit 37*2118f387SNathan Whitehorn else 38*2118f387SNathan Whitehorn test -f $PATH_FSTAB && bsdinstall umount 39*2118f387SNathan Whitehorn exec $0 40*2118f387SNathan Whitehorn fi 41*2118f387SNathan Whitehorn} 42*2118f387SNathan Whitehorn 43*2118f387SNathan Whitehorn 44*2118f387SNathan Whitehornrm -rf $BSDINSTALL_TMPETC 45*2118f387SNathan Whitehornmkdir $BSDINSTALL_TMPETC 46*2118f387SNathan Whitehorn 47*2118f387SNathan Whitehorntrap true SIGINT # This section is optional 48*2118f387SNathan Whitehornbsdinstall keymap 49*2118f387SNathan Whitehorn 50*2118f387SNathan Whitehorntrap error SIGINT # Catch cntrl-C here 51*2118f387SNathan Whitehornbsdinstall hostname || error 52*2118f387SNathan Whitehorn 53*2118f387SNathan WhitehornFETCH_DISTRIBUTIONS="" 54*2118f387SNathan Whitehornfor dist in $DISTRIBUTIONS; do 55*2118f387SNathan Whitehorn if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then 56*2118f387SNathan Whitehorn FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist" 57*2118f387SNathan Whitehorn fi 58*2118f387SNathan Whitehorndone 59*2118f387SNathan Whitehorn 60*2118f387SNathan Whitehornif [ ! -z "$FETCH_DISTRIBUTIONS" -a ! -z $BSDINSTALL_CONFIGCURRENT ]; then 61*2118f387SNathan Whitehorn 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 62*2118f387SNathan Whitehorn bsdinstall netconfig || error 63*2118f387SNathan Whitehorn NETCONFIG_DONE=yes 64*2118f387SNathan Whitehornfi 65*2118f387SNathan Whitehorn 66*2118f387SNathan Whitehornrm $PATH_FSTAB 67*2118f387SNathan Whitehorntouch $PATH_FSTAB 68*2118f387SNathan Whitehorn 69*2118f387SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Partitioning" --extra-button \ 70*2118f387SNathan Whitehorn --extra-label "Manual" --ok-label "Guided" --cancel-label "Shell" \ 71*2118f387SNathan Whitehorn --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 72*2118f387SNathan Whitehorn 73*2118f387SNathan Whitehorncase $? in 74*2118f387SNathan Whitehorn0) # Guided 75*2118f387SNathan Whitehorn bsdinstall autopart || error 76*2118f387SNathan Whitehorn bsdinstall mount || error 77*2118f387SNathan Whitehorn ;; 78*2118f387SNathan Whitehorn1) # Shell 79*2118f387SNathan Whitehorn clear 80*2118f387SNathan Whitehorn 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'." 81*2118f387SNathan Whitehorn sh 82*2118f387SNathan Whitehorn ;; 83*2118f387SNathan Whitehorn3) # Manual 84*2118f387SNathan Whitehorn bsdinstall partedit || error 85*2118f387SNathan Whitehorn bsdinstall mount || error 86*2118f387SNathan Whitehorn ;; 87*2118f387SNathan Whitehorn*) 88*2118f387SNathan Whitehorn error 89*2118f387SNathan Whitehorn ;; 90*2118f387SNathan Whitehornesac 91*2118f387SNathan Whitehorn 92*2118f387SNathan Whitehornif [ ! -z "$FETCH_DISTRIBUTIONS" ]; then 93*2118f387SNathan Whitehorn ALL_DISTRIBUTIONS="$DISTRIBUTIONS" 94*2118f387SNathan Whitehorn 95*2118f387SNathan Whitehorn # Download to a directory in the new system as scratch space 96*2118f387SNathan Whitehorn BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/bsdinstall-dist" 97*2118f387SNathan Whitehorn mkdir -p "$BSDINSTALL_FETCHDEST" || error 98*2118f387SNathan Whitehorn 99*2118f387SNathan Whitehorn export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS" 100*2118f387SNathan Whitehorn # Try to use any existing distfiles 101*2118f387SNathan Whitehorn [ -d $BSDINSTALL_DISTDIR -a "$FETCH_DISTRIBUTIONS" != "$ALL_DISTRIBUTIONS" ] && mount_unionfs "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR" 102*2118f387SNathan Whitehorn 103*2118f387SNathan Whitehorn # Otherwise, fetch everything 104*2118f387SNathan Whitehorn if [ $? -ne 0 ]; then 105*2118f387SNathan Whitehorn export DISTRIBUTIONS="$ALL_DISTRIBUTIONS" 106*2118f387SNathan Whitehorn export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST" 107*2118f387SNathan Whitehorn fi 108*2118f387SNathan Whitehorn 109*2118f387SNathan Whitehorn bsdinstall distfetch || error 110*2118f387SNathan Whitehorn export DISTRIBUTIONS="$ALL_DISTRIBUTIONS" 111*2118f387SNathan Whitehornfi 112*2118f387SNathan Whitehorn 113*2118f387SNathan Whitehornbsdinstall distextract || error 114*2118f387SNathan Whitehornbsdinstall rootpass || error 115*2118f387SNathan Whitehorn 116*2118f387SNathan Whitehorntrap true SIGINT # This section is optional 117*2118f387SNathan Whitehornif [ "$NETCONFIG_DONE" != yes ]; then 118*2118f387SNathan Whitehorn bsdinstall netconfig # Don't check for errors -- the user may cancel 119*2118f387SNathan Whitehornfi 120*2118f387SNathan Whitehornbsdinstall time 121*2118f387SNathan Whitehornbsdinstall services 122*2118f387SNathan Whitehorn 123*2118f387SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \ 124*2118f387SNathan Whitehorn "Would you like to add users to the installed system now?" 0 0 && \ 125*2118f387SNathan Whitehorn bsdinstall adduser 126*2118f387SNathan Whitehorn 127*2118f387SNathan Whitehornfinalconfig() { 128*2118f387SNathan Whitehorn exec 3>&1 129*2118f387SNathan Whitehorn REVISIT=$(dialog --backtitle "FreeBSD Installer" \ 130*2118f387SNathan Whitehorn --title "Final Configuration" --no-cancel --menu \ 131*2118f387SNathan Whitehorn "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 \ 132*2118f387SNathan Whitehorn "Add User" "Add a user to the system" \ 133*2118f387SNathan Whitehorn "Root Password" "Change root password" \ 134*2118f387SNathan Whitehorn "Hostname" "Set system hostname" \ 135*2118f387SNathan Whitehorn "Network" "Networking configuration" \ 136*2118f387SNathan Whitehorn "Services" "Set daemons to run on startup" \ 137*2118f387SNathan Whitehorn "Time Zone" "Set system timezone" \ 138*2118f387SNathan Whitehorn "Shell" "Open a shell in the new system" \ 139*2118f387SNathan Whitehorn "Reboot" "Apply configuration and reboot" 2>&1 1>&3) 140*2118f387SNathan Whitehorn exec 3>&- 141*2118f387SNathan Whitehorn 142*2118f387SNathan Whitehorn case "$REVISIT" in 143*2118f387SNathan Whitehorn "Add User") 144*2118f387SNathan Whitehorn bsdinstall adduser 145*2118f387SNathan Whitehorn finalconfig 146*2118f387SNathan Whitehorn ;; 147*2118f387SNathan Whitehorn "Root Password") 148*2118f387SNathan Whitehorn bsdinstall rootpass 149*2118f387SNathan Whitehorn finalconfig 150*2118f387SNathan Whitehorn ;; 151*2118f387SNathan Whitehorn "Hostname") 152*2118f387SNathan Whitehorn bsdinstall hostname 153*2118f387SNathan Whitehorn finalconfig 154*2118f387SNathan Whitehorn ;; 155*2118f387SNathan Whitehorn "Network") 156*2118f387SNathan Whitehorn bsdinstall netconfig 157*2118f387SNathan Whitehorn finalconfig 158*2118f387SNathan Whitehorn ;; 159*2118f387SNathan Whitehorn "Services") 160*2118f387SNathan Whitehorn bsdinstall services 161*2118f387SNathan Whitehorn finalconfig 162*2118f387SNathan Whitehorn ;; 163*2118f387SNathan Whitehorn "Time Zone") 164*2118f387SNathan Whitehorn bsdinstall time 165*2118f387SNathan Whitehorn finalconfig 166*2118f387SNathan Whitehorn ;; 167*2118f387SNathan Whitehorn "Shell") 168*2118f387SNathan Whitehorn clear 169*2118f387SNathan Whitehorn echo This shell is operating in a chroot in the new system. \ 170*2118f387SNathan Whitehorn When finished making configuration changes, type \"exit\". 171*2118f387SNathan Whitehorn chroot "$BSDINSTALL_CHROOT" /bin/sh 172*2118f387SNathan Whitehorn # Don't hose local rc.conf changes 173*2118f387SNathan Whitehorn cp $BSDINSTALL_CHROOT/etc/rc.conf $BSDINSTALL_TMPETC/rc.conf.manual 174*2118f387SNathan Whitehorn finalconfig 175*2118f387SNathan Whitehorn ;; 176*2118f387SNathan Whitehorn esac 177*2118f387SNathan Whitehorn} 178*2118f387SNathan Whitehorn 179*2118f387SNathan Whitehorn# Allow user to change his mind 180*2118f387SNathan Whitehornfinalconfig 181*2118f387SNathan Whitehorn 182*2118f387SNathan Whitehorntrap error SIGINT # SIGINT is bad again 183*2118f387SNathan Whitehornbsdinstall config || error 184*2118f387SNathan Whitehorn 185*2118f387SNathan Whitehornif [ ! -z "$BSDINSTALL_FETCHDEST" ]; then 186*2118f387SNathan Whitehorn [ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \ 187*2118f387SNathan Whitehorn umount "$BSDINSTALL_DISTDIR" 188*2118f387SNathan Whitehorn rm -rf "$BSDINSTALL_FETCHDEST" 189*2118f387SNathan Whitehornfi 190*2118f387SNathan Whitehorn 191*2118f387SNathan Whitehornecho "Installation Completed at $(date)" >> $BSDINSTALL_LOG 192*2118f387SNathan Whitehorn 193