12118f387SNathan Whitehorn#!/bin/sh 22118f387SNathan Whitehorn#- 32118f387SNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn 42118f387SNathan Whitehorn# All rights reserved. 52118f387SNathan Whitehorn# 62118f387SNathan Whitehorn# Redistribution and use in source and binary forms, with or without 72118f387SNathan Whitehorn# modification, are permitted provided that the following conditions 82118f387SNathan Whitehorn# are met: 92118f387SNathan Whitehorn# 1. Redistributions of source code must retain the above copyright 102118f387SNathan Whitehorn# notice, this list of conditions and the following disclaimer. 112118f387SNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright 122118f387SNathan Whitehorn# notice, this list of conditions and the following disclaimer in the 132118f387SNathan Whitehorn# documentation and/or other materials provided with the distribution. 142118f387SNathan Whitehorn# 152118f387SNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 162118f387SNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 172118f387SNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 182118f387SNathan Whitehorn# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 192118f387SNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 202118f387SNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 212118f387SNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 222118f387SNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 232118f387SNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 242118f387SNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 252118f387SNathan Whitehorn# SUCH DAMAGE. 262118f387SNathan Whitehorn# 272118f387SNathan Whitehorn# $FreeBSD$ 282118f387SNathan Whitehorn 292118f387SNathan Whitehornecho "Begun Installation at $(date)" > $BSDINSTALL_LOG 302118f387SNathan Whitehorn 312118f387SNathan Whitehornerror() { 322118f387SNathan Whitehorn dialog --backtitle "FreeBSD Installer" --title "Abort" \ 332118f387SNathan Whitehorn --no-label "Exit" --yes-label "Restart" --yesno \ 342118f387SNathan Whitehorn "An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0 352118f387SNathan Whitehorn if [ $? -ne 0 ]; then 362118f387SNathan Whitehorn exit 372118f387SNathan Whitehorn else 382118f387SNathan Whitehorn test -f $PATH_FSTAB && bsdinstall umount 392118f387SNathan Whitehorn exec $0 402118f387SNathan Whitehorn fi 412118f387SNathan Whitehorn} 422118f387SNathan Whitehorn 432118f387SNathan Whitehorn 442118f387SNathan Whitehornrm -rf $BSDINSTALL_TMPETC 452118f387SNathan Whitehornmkdir $BSDINSTALL_TMPETC 462118f387SNathan Whitehorn 472118f387SNathan Whitehorntrap true SIGINT # This section is optional 482118f387SNathan Whitehornbsdinstall keymap 492118f387SNathan Whitehorn 502118f387SNathan Whitehorntrap error SIGINT # Catch cntrl-C here 512118f387SNathan Whitehornbsdinstall hostname || error 522118f387SNathan Whitehorn 53*addc19a4SNathan WhitehornLIB32="" 54*addc19a4SNathan Whitehorn[ `uname -p` = amd64 -o `uname -p` = powerpc64 ] && \ 55*addc19a4SNathan Whitehorn LIB32="lib32 \"32-bit compatibility\" on" 56*addc19a4SNathan Whitehorn 57*addc19a4SNathan WhitehornDISTMENU="doc \"Additional documentation\" on \ 58*addc19a4SNathan Whitehorn games \"Games (fortune, etc.)\" on \ 59*addc19a4SNathan Whitehorn $LIB32 \ 60*addc19a4SNathan Whitehorn ports \"Ports tree\" on \ 61*addc19a4SNathan Whitehorn src \"System source code\" off" 62*addc19a4SNathan Whitehorn 63*addc19a4SNathan Whitehornexec 3>&1 64*addc19a4SNathan WhitehornEXTRA_DISTS=$(echo $DISTMENU | xargs dialog --backtitle "FreeBSD Installer" \ 65*addc19a4SNathan Whitehorn --title "Distribution Select" --nocancel --separate-output \ 66*addc19a4SNathan Whitehorn --checklist "Choose optional system components to install:" \ 67*addc19a4SNathan Whitehorn 0 0 0 \ 68*addc19a4SNathan Whitehorn2>&1 1>&3) 69*addc19a4SNathan WhitehornDISTRIBUTIONS="base.txz kernel.txz" 70*addc19a4SNathan Whitehornfor dist in $EXTRA_DISTS; do 71*addc19a4SNathan Whitehorn export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz" 72*addc19a4SNathan Whitehorndone 73*addc19a4SNathan Whitehorn 742118f387SNathan WhitehornFETCH_DISTRIBUTIONS="" 752118f387SNathan Whitehornfor dist in $DISTRIBUTIONS; do 762118f387SNathan Whitehorn if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then 772118f387SNathan Whitehorn FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist" 782118f387SNathan Whitehorn fi 792118f387SNathan Whitehorndone 802118f387SNathan Whitehorn 812118f387SNathan Whitehornif [ ! -z "$FETCH_DISTRIBUTIONS" -a ! -z $BSDINSTALL_CONFIGCURRENT ]; then 822118f387SNathan 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 832118f387SNathan Whitehorn bsdinstall netconfig || error 842118f387SNathan Whitehorn NETCONFIG_DONE=yes 852118f387SNathan Whitehornfi 862118f387SNathan Whitehorn 872118f387SNathan Whitehornrm $PATH_FSTAB 882118f387SNathan Whitehorntouch $PATH_FSTAB 892118f387SNathan Whitehorn 902118f387SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Partitioning" --extra-button \ 912118f387SNathan Whitehorn --extra-label "Manual" --ok-label "Guided" --cancel-label "Shell" \ 922118f387SNathan 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 932118f387SNathan Whitehorn 942118f387SNathan Whitehorncase $? in 952118f387SNathan Whitehorn0) # Guided 962118f387SNathan Whitehorn bsdinstall autopart || error 972118f387SNathan Whitehorn bsdinstall mount || error 982118f387SNathan Whitehorn ;; 992118f387SNathan Whitehorn1) # Shell 1002118f387SNathan Whitehorn clear 1012118f387SNathan 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'." 1022118f387SNathan Whitehorn sh 1032118f387SNathan Whitehorn ;; 1042118f387SNathan Whitehorn3) # Manual 1052118f387SNathan Whitehorn bsdinstall partedit || error 1062118f387SNathan Whitehorn bsdinstall mount || error 1072118f387SNathan Whitehorn ;; 1082118f387SNathan Whitehorn*) 1092118f387SNathan Whitehorn error 1102118f387SNathan Whitehorn ;; 1112118f387SNathan Whitehornesac 1122118f387SNathan Whitehorn 1132118f387SNathan Whitehornif [ ! -z "$FETCH_DISTRIBUTIONS" ]; then 1142118f387SNathan Whitehorn ALL_DISTRIBUTIONS="$DISTRIBUTIONS" 1152118f387SNathan Whitehorn 1162118f387SNathan Whitehorn # Download to a directory in the new system as scratch space 1172118f387SNathan Whitehorn BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/bsdinstall-dist" 1182118f387SNathan Whitehorn mkdir -p "$BSDINSTALL_FETCHDEST" || error 1192118f387SNathan Whitehorn 1202118f387SNathan Whitehorn export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS" 1212118f387SNathan Whitehorn # Try to use any existing distfiles 1222118f387SNathan Whitehorn [ -d $BSDINSTALL_DISTDIR -a "$FETCH_DISTRIBUTIONS" != "$ALL_DISTRIBUTIONS" ] && mount_unionfs "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR" 1232118f387SNathan Whitehorn 1242118f387SNathan Whitehorn # Otherwise, fetch everything 1252118f387SNathan Whitehorn if [ $? -ne 0 ]; then 1262118f387SNathan Whitehorn export DISTRIBUTIONS="$ALL_DISTRIBUTIONS" 1272118f387SNathan Whitehorn export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST" 1282118f387SNathan Whitehorn fi 1292118f387SNathan Whitehorn 1302118f387SNathan Whitehorn bsdinstall distfetch || error 1312118f387SNathan Whitehorn export DISTRIBUTIONS="$ALL_DISTRIBUTIONS" 1322118f387SNathan Whitehornfi 1332118f387SNathan Whitehorn 1342118f387SNathan Whitehornbsdinstall distextract || error 1352118f387SNathan Whitehornbsdinstall rootpass || error 1362118f387SNathan Whitehorn 1372118f387SNathan Whitehorntrap true SIGINT # This section is optional 1382118f387SNathan Whitehornif [ "$NETCONFIG_DONE" != yes ]; then 1392118f387SNathan Whitehorn bsdinstall netconfig # Don't check for errors -- the user may cancel 1402118f387SNathan Whitehornfi 1412118f387SNathan Whitehornbsdinstall time 1422118f387SNathan Whitehornbsdinstall services 1432118f387SNathan Whitehorn 1442118f387SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \ 1452118f387SNathan Whitehorn "Would you like to add users to the installed system now?" 0 0 && \ 1462118f387SNathan Whitehorn bsdinstall adduser 1472118f387SNathan Whitehorn 1482118f387SNathan Whitehornfinalconfig() { 1492118f387SNathan Whitehorn exec 3>&1 1502118f387SNathan Whitehorn REVISIT=$(dialog --backtitle "FreeBSD Installer" \ 1512118f387SNathan Whitehorn --title "Final Configuration" --no-cancel --menu \ 1522118f387SNathan 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 \ 1532118f387SNathan Whitehorn "Add User" "Add a user to the system" \ 1542118f387SNathan Whitehorn "Root Password" "Change root password" \ 1552118f387SNathan Whitehorn "Hostname" "Set system hostname" \ 1562118f387SNathan Whitehorn "Network" "Networking configuration" \ 1572118f387SNathan Whitehorn "Services" "Set daemons to run on startup" \ 1582118f387SNathan Whitehorn "Time Zone" "Set system timezone" \ 1592118f387SNathan Whitehorn "Shell" "Open a shell in the new system" \ 1602118f387SNathan Whitehorn "Reboot" "Apply configuration and reboot" 2>&1 1>&3) 1612118f387SNathan Whitehorn exec 3>&- 1622118f387SNathan Whitehorn 1632118f387SNathan Whitehorn case "$REVISIT" in 1642118f387SNathan Whitehorn "Add User") 1652118f387SNathan Whitehorn bsdinstall adduser 1662118f387SNathan Whitehorn finalconfig 1672118f387SNathan Whitehorn ;; 1682118f387SNathan Whitehorn "Root Password") 1692118f387SNathan Whitehorn bsdinstall rootpass 1702118f387SNathan Whitehorn finalconfig 1712118f387SNathan Whitehorn ;; 1722118f387SNathan Whitehorn "Hostname") 1732118f387SNathan Whitehorn bsdinstall hostname 1742118f387SNathan Whitehorn finalconfig 1752118f387SNathan Whitehorn ;; 1762118f387SNathan Whitehorn "Network") 1772118f387SNathan Whitehorn bsdinstall netconfig 1782118f387SNathan Whitehorn finalconfig 1792118f387SNathan Whitehorn ;; 1802118f387SNathan Whitehorn "Services") 1812118f387SNathan Whitehorn bsdinstall services 1822118f387SNathan Whitehorn finalconfig 1832118f387SNathan Whitehorn ;; 1842118f387SNathan Whitehorn "Time Zone") 1852118f387SNathan Whitehorn bsdinstall time 1862118f387SNathan Whitehorn finalconfig 1872118f387SNathan Whitehorn ;; 1882118f387SNathan Whitehorn "Shell") 1892118f387SNathan Whitehorn clear 1902118f387SNathan Whitehorn echo This shell is operating in a chroot in the new system. \ 1912118f387SNathan Whitehorn When finished making configuration changes, type \"exit\". 1922118f387SNathan Whitehorn chroot "$BSDINSTALL_CHROOT" /bin/sh 1932118f387SNathan Whitehorn # Don't hose local rc.conf changes 1942118f387SNathan Whitehorn cp $BSDINSTALL_CHROOT/etc/rc.conf $BSDINSTALL_TMPETC/rc.conf.manual 1952118f387SNathan Whitehorn finalconfig 1962118f387SNathan Whitehorn ;; 1972118f387SNathan Whitehorn esac 1982118f387SNathan Whitehorn} 1992118f387SNathan Whitehorn 2002118f387SNathan Whitehorn# Allow user to change his mind 2012118f387SNathan Whitehornfinalconfig 2022118f387SNathan Whitehorn 2032118f387SNathan Whitehorntrap error SIGINT # SIGINT is bad again 2042118f387SNathan Whitehornbsdinstall config || error 2052118f387SNathan Whitehorn 2062118f387SNathan Whitehornif [ ! -z "$BSDINSTALL_FETCHDEST" ]; then 2072118f387SNathan Whitehorn [ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \ 2082118f387SNathan Whitehorn umount "$BSDINSTALL_DISTDIR" 2092118f387SNathan Whitehorn rm -rf "$BSDINSTALL_FETCHDEST" 2102118f387SNathan Whitehornfi 2112118f387SNathan Whitehorn 2122118f387SNathan Whitehornecho "Installation Completed at $(date)" >> $BSDINSTALL_LOG 2132118f387SNathan Whitehorn 214