xref: /freebsd/usr.sbin/bsdinstall/scripts/auto (revision 8befcf7be199ab5e496593cb563a3a7b9e0170e9)
12118f387SNathan Whitehorn#!/bin/sh
22118f387SNathan Whitehorn#-
32118f387SNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn
4bc4a673fSDevin Teske# Copyright (c) 2013 Devin Teske
52118f387SNathan Whitehorn# All rights reserved.
62118f387SNathan Whitehorn#
72118f387SNathan Whitehorn# Redistribution and use in source and binary forms, with or without
82118f387SNathan Whitehorn# modification, are permitted provided that the following conditions
92118f387SNathan Whitehorn# are met:
102118f387SNathan Whitehorn# 1. Redistributions of source code must retain the above copyright
112118f387SNathan Whitehorn#    notice, this list of conditions and the following disclaimer.
122118f387SNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright
132118f387SNathan Whitehorn#    notice, this list of conditions and the following disclaimer in the
142118f387SNathan Whitehorn#    documentation and/or other materials provided with the distribution.
152118f387SNathan Whitehorn#
162118f387SNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
172118f387SNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182118f387SNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
192118f387SNathan Whitehorn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
202118f387SNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
212118f387SNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
222118f387SNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
232118f387SNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
242118f387SNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
252118f387SNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
262118f387SNathan Whitehorn# SUCH DAMAGE.
272118f387SNathan Whitehorn#
282118f387SNathan Whitehorn# $FreeBSD$
29bc4a673fSDevin Teske#
30bc4a673fSDevin Teske############################################################ INCLUDES
312118f387SNathan Whitehorn
32bc4a673fSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig"
33bc4a673fSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1
347059fa6fSAllan Judef_include $BSDCFG_SHARE/dialog.subr
35bc4a673fSDevin Teske
36bc4a673fSDevin Teske############################################################ FUNCTIONS
372118f387SNathan Whitehorn
382118f387SNathan Whitehornerror() {
397041a67eSAndrew Thompson	local msg
407041a67eSAndrew Thompson	if [ -n "$1" ]; then
417041a67eSAndrew Thompson		msg="$1\n\n"
427041a67eSAndrew Thompson	fi
435a038452SNathan Whitehorn	test -n "$DISTDIR_IS_UNIONFS" && umount -f $BSDINSTALL_DISTDIR
445a038452SNathan Whitehorn	test -f $PATH_FSTAB && bsdinstall umount
452118f387SNathan Whitehorn	dialog --backtitle "FreeBSD Installer" --title "Abort" \
462118f387SNathan Whitehorn	    --no-label "Exit" --yes-label "Restart" --yesno \
477041a67eSAndrew Thompson	    "${msg}An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
482118f387SNathan Whitehorn	if [ $? -ne 0 ]; then
496d02d4cbSNathan Whitehorn		exit 1
502118f387SNathan Whitehorn	else
512118f387SNathan Whitehorn		exec $0
522118f387SNathan Whitehorn	fi
532118f387SNathan Whitehorn}
542118f387SNathan Whitehorn
557059fa6fSAllan Judehline_arrows_tab_enter="Press arrows, TAB or ENTER"
56a7d5d8d9SAllan Judemsg_gpt_active_fix="Your hardware is known to have issues booting in CSM/Legacy/BIOS mode from GPT partitions that are not set active. Would you like the installer to apply this workaround for you?"
577059fa6fSAllan Judemsg_lenovo_fix="Your model of Lenovo is known to have a BIOS bug that prevents it booting from GPT partitions without UEFI. Would you like the installer to apply a workaround for you?"
587059fa6fSAllan Judemsg_no="NO"
597059fa6fSAllan Judemsg_yes="YES"
607059fa6fSAllan Jude
617059fa6fSAllan Jude# dialog_workaround
627059fa6fSAllan Jude#
637059fa6fSAllan Jude# Ask the user if they wish to apply a workaround
647059fa6fSAllan Jude#
657059fa6fSAllan Judedialog_workaround()
667059fa6fSAllan Jude{
677059fa6fSAllan Jude	local passed_msg="$1"
687059fa6fSAllan Jude	local title="$DIALOG_TITLE"
697059fa6fSAllan Jude	local btitle="$DIALOG_BACKTITLE"
707059fa6fSAllan Jude	local prompt # Calculated below
717059fa6fSAllan Jude	local hline="$hline_arrows_tab_enter"
727059fa6fSAllan Jude
737059fa6fSAllan Jude	local height=8 width=50 prefix="   "
747059fa6fSAllan Jude	local plen=${#prefix} list= line=
757059fa6fSAllan Jude	local max_width=$(( $width - 3 - $plen ))
767059fa6fSAllan Jude
777059fa6fSAllan Jude	local yes no defaultno extra_args format
787059fa6fSAllan Jude	if [ "$USE_XDIALOG" ]; then
797059fa6fSAllan Jude		yes=ok no=cancel defaultno=default-no
807059fa6fSAllan Jude		extra_args="--wrap --left"
817059fa6fSAllan Jude		format="$passed_msg"
827059fa6fSAllan Jude	else
837059fa6fSAllan Jude		yes=yes no=no defaultno=defaultno
847059fa6fSAllan Jude		extra_args="--cr-wrap"
857059fa6fSAllan Jude		format="$passed_msg"
867059fa6fSAllan Jude	fi
877059fa6fSAllan Jude
887059fa6fSAllan Jude	# Add height for Xdialog(1)
897059fa6fSAllan Jude	[ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 ))
907059fa6fSAllan Jude
917059fa6fSAllan Jude	prompt=$( printf "$format" )
927059fa6fSAllan Jude	f_dprintf "%s: Workaround prompt" "$0"
937059fa6fSAllan Jude	$DIALOG \
947059fa6fSAllan Jude		--title "$title"        \
957059fa6fSAllan Jude		--backtitle "$btitle"   \
967059fa6fSAllan Jude		--hline "$hline"        \
977059fa6fSAllan Jude		--$yes-label "$msg_yes" \
987059fa6fSAllan Jude		--$no-label "$msg_no"   \
997059fa6fSAllan Jude		$extra_args             \
1007059fa6fSAllan Jude		--yesno "$prompt" $height $width
1017059fa6fSAllan Jude}
1027059fa6fSAllan Jude
103bc4a673fSDevin Teske############################################################ MAIN
104bc4a673fSDevin Teske
105bc4a673fSDevin Teskef_dprintf "Began Installation at %s" "$( date )"
1062118f387SNathan Whitehorn
1072118f387SNathan Whitehornrm -rf $BSDINSTALL_TMPETC
1082118f387SNathan Whitehornmkdir $BSDINSTALL_TMPETC
1092118f387SNathan Whitehorn
1102118f387SNathan Whitehorntrap true SIGINT	# This section is optional
1112118f387SNathan Whitehornbsdinstall keymap
1122118f387SNathan Whitehorn
1132118f387SNathan Whitehorntrap error SIGINT	# Catch cntrl-C here
1147041a67eSAndrew Thompsonbsdinstall hostname || error "Set hostname failed"
1152118f387SNathan Whitehorn
116b70047d4SNathan Whitehornexport DISTRIBUTIONS="base.txz kernel.txz"
117b70047d4SNathan Whitehornif [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
11888343186SGlen Barber	DISTMENU=`awk -F'\t' '!/^(kernel\.txz|base\.txz)/{print $1,$5,$6}' $BSDINSTALL_DISTDIR/MANIFEST`
11988343186SGlen Barber	DISTMENU="$(echo ${DISTMENU} | sed -E 's/\.txz//g')"
120addc19a4SNathan Whitehorn
121addc19a4SNathan Whitehorn	exec 3>&1
1224ca6fb65SDevin Teske	EXTRA_DISTS=$( eval dialog \
1234ca6fb65SDevin Teske	    --backtitle \"FreeBSD Installer\" \
1244ca6fb65SDevin Teske	    --title \"Distribution Select\" --nocancel --separate-output \
1254ca6fb65SDevin Teske	    --checklist \"Choose optional system components to install:\" \
1264ca6fb65SDevin Teske	    0 0 0 $DISTMENU \
127addc19a4SNathan Whitehorn	2>&1 1>&3 )
128addc19a4SNathan Whitehorn	for dist in $EXTRA_DISTS; do
129addc19a4SNathan Whitehorn		export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
130addc19a4SNathan Whitehorn	done
131b70047d4SNathan Whitehornfi
132addc19a4SNathan Whitehorn
13388343186SGlen BarberLOCAL_DISTRIBUTIONS="MANIFEST"
1342118f387SNathan WhitehornFETCH_DISTRIBUTIONS=""
1352118f387SNathan Whitehornfor dist in $DISTRIBUTIONS; do
1362118f387SNathan Whitehorn	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
1372118f387SNathan Whitehorn		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
13888343186SGlen Barber	else
13988343186SGlen Barber		LOCAL_DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS $dist"
1402118f387SNathan Whitehorn	fi
1412118f387SNathan Whitehorndone
14288343186SGlen BarberLOCAL_DISTRIBUTIONS=`echo $LOCAL_DISTRIBUTIONS`	# Trim white space
1436dcef0cfSNathan WhitehornFETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS`	# Trim white space
1442118f387SNathan Whitehorn
1456dcef0cfSNathan Whitehornif [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then
14688343186SGlen Barber	dialog --backtitle "FreeBSD Installer" --title "Network Installation" --msgbox "Some installation files were not 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
1472118f387SNathan Whitehorn	bsdinstall netconfig || error
1482118f387SNathan Whitehorn	NETCONFIG_DONE=yes
1492118f387SNathan Whitehornfi
1502118f387SNathan Whitehorn
1515a038452SNathan Whitehornif [ -n "$FETCH_DISTRIBUTIONS" ]; then
1526dcef0cfSNathan Whitehorn	exec 3>&1
15326976226SNathan Whitehorn	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
1546dcef0cfSNathan Whitehorn	MIRROR_BUTTON=$?
1556dcef0cfSNathan Whitehorn	exec 3>&-
1567041a67eSAndrew Thompson	test $MIRROR_BUTTON -eq 0 || error "No mirror selected"
1576dcef0cfSNathan Whitehorn	export BSDINSTALL_DISTSITE
1586dcef0cfSNathan Whitehornfi
1596dcef0cfSNathan Whitehorn
1602d5cf580SDevin Teskerm -f $PATH_FSTAB
1612118f387SNathan Whitehorntouch $PATH_FSTAB
1622118f387SNathan Whitehorn
1637059fa6fSAllan Jude#
1647059fa6fSAllan Jude# Try to detect known broken platforms and apply their workarounds
1657059fa6fSAllan Jude#
1667059fa6fSAllan Jude
1677059fa6fSAllan Judeif f_interactive; then
1687059fa6fSAllan Jude	sys_maker=$( kenv -q smbios.system.maker )
1697059fa6fSAllan Jude	f_dprintf "smbios.system.maker=[%s]" "$sys_maker"
1707059fa6fSAllan Jude	sys_model=$( kenv -q smbios.system.product )
1717059fa6fSAllan Jude	f_dprintf "smbios.system.product=[%s]" "$sys_model"
1727059fa6fSAllan Jude	sys_version=$( kenv -q smbios.system.version )
1737059fa6fSAllan Jude	f_dprintf "smbios.system.version=[%s]" "$sys_version"
174a7d5d8d9SAllan Jude	sys_mb_maker=$( kenv -q smbios.planar.maker )
175a7d5d8d9SAllan Jude	f_dprintf "smbios.planar.maker=[%s]" "$sys_mb_maker"
176a7d5d8d9SAllan Jude	sys_mb_product=$( kenv -q smbios.planar.product )
177a7d5d8d9SAllan Jude	f_dprintf "smbios.planar.product=[%s]" "$sys_mb_product"
178a7d5d8d9SAllan Jude
179a7d5d8d9SAllan Jude	#
180a7d5d8d9SAllan Jude	# Laptop Models
181a7d5d8d9SAllan Jude	#
1827059fa6fSAllan Jude	case "$sys_maker" in
1837059fa6fSAllan Jude	"LENOVO")
1847059fa6fSAllan Jude		case "$sys_version" in
185e3026446SAllan Jude		"ThinkPad X220"|"ThinkPad T420"|"ThinkPad T520"|"ThinkPad W520")
1867059fa6fSAllan Jude			dialog_workaround "$msg_lenovo_fix"
1877059fa6fSAllan Jude			retval=$?
1887059fa6fSAllan Jude			f_dprintf "lenovofix_prompt=[%s]" "$retval"
1897059fa6fSAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
1907059fa6fSAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix"
1917059fa6fSAllan Jude				export WORKAROUND_LENOVO=1
1927059fa6fSAllan Jude			fi
1937059fa6fSAllan Jude			;;
1947059fa6fSAllan Jude		esac
1957059fa6fSAllan Jude		;;
1967059fa6fSAllan Jude	"Dell Inc.")
1977059fa6fSAllan Jude		case "$sys_model" in
198e3026446SAllan Jude		"Latitude E6330"|"Latitude E7440"|"Latitude E7240"|"Precision Tower 5810")
199a7d5d8d9SAllan Jude			dialog_workaround "$msg_gpt_active_fix"
200a7d5d8d9SAllan Jude			retval=$?
201a7d5d8d9SAllan Jude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
202a7d5d8d9SAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
203a7d5d8d9SAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
204a7d5d8d9SAllan Jude				export WORKAROUND_GPTACTIVE=1
205a7d5d8d9SAllan Jude			fi
206a7d5d8d9SAllan Jude			;;
207a7d5d8d9SAllan Jude		esac
208a7d5d8d9SAllan Jude		;;
2094c95e76aSAllan Jude	"Hewlett-Packard")
2104c95e76aSAllan Jude		case "$sys_model" in
2114c95e76aSAllan Jude		"HP ProBook 4330s")
2124c95e76aSAllan Jude			dialog_workaround "$msg_gpt_active_fix"
2134c95e76aSAllan Jude			retval=$?
2144c95e76aSAllan Jude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
2154c95e76aSAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
2164c95e76aSAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
2174c95e76aSAllan Jude				export WORKAROUND_GPTACTIVE=1
2184c95e76aSAllan Jude			fi
2194c95e76aSAllan Jude			;;
2204c95e76aSAllan Jude		esac
2214c95e76aSAllan Jude		;;
222a7d5d8d9SAllan Jude	esac
223a7d5d8d9SAllan Jude	#
224a7d5d8d9SAllan Jude	# Motherboard Models
225a7d5d8d9SAllan Jude	#
226a7d5d8d9SAllan Jude	case "$sys_mb_maker" in
227a7d5d8d9SAllan Jude	"Intel Corporation")
228a7d5d8d9SAllan Jude		case "$sys_mb_product" in
2294c95e76aSAllan Jude		"DP965LT"|"D510MO")
2304c95e76aSAllan Jude			dialog_workaround "$msg_gpt_active_fix"
2314c95e76aSAllan Jude			retval=$?
2324c95e76aSAllan Jude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
2334c95e76aSAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
2344c95e76aSAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
2354c95e76aSAllan Jude				export WORKAROUND_GPTACTIVE=1
2364c95e76aSAllan Jude			fi
2374c95e76aSAllan Jude			;;
2384c95e76aSAllan Jude		esac
2394c95e76aSAllan Jude		;;
2404c95e76aSAllan Jude	"Acer")
2414c95e76aSAllan Jude		case "$sys_mb_product" in
2424c95e76aSAllan Jude		"Veriton M6630G")
2437059fa6fSAllan Jude			dialog_workaround "$msg_gpt_active_fix"
2447059fa6fSAllan Jude			retval=$?
2457059fa6fSAllan Jude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
2467059fa6fSAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
2477059fa6fSAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
2487059fa6fSAllan Jude				export WORKAROUND_GPTACTIVE=1
2497059fa6fSAllan Jude			fi
2507059fa6fSAllan Jude			;;
2517059fa6fSAllan Jude		esac
2527059fa6fSAllan Jude		;;
2537059fa6fSAllan Jude	esac
2547059fa6fSAllan Judefi
2557059fa6fSAllan Jude
256cd88b886SDevin TeskePMODES="\
2577c1db228SNathan Whitehorn\"Auto (UFS)\" \"Guided Disk Setup\" \
2587c1db228SNathan WhitehornManual \"Manual Disk Setup (experts)\" \
259cd88b886SDevin TeskeShell \"Open a shell and partition by hand\""
2602118f387SNathan Whitehorn
261cd88b886SDevin TeskeCURARCH=$( uname -m )
262cd88b886SDevin Teskecase $CURARCH in
2633735bba3SAllan Jude	amd64|arm64|i386)	# Booting ZFS Supported
264d73bf007SNathan Whitehorn		PMODES="$PMODES \"Auto (ZFS)\" \"Guided Root-on-ZFS\""
265cd88b886SDevin Teske		;;
266cd88b886SDevin Teske	*)		# Booting ZFS Unspported
267cd88b886SDevin Teske		;;
268cd88b886SDevin Teskeesac
269cd88b886SDevin Teske
270cd88b886SDevin Teskeexec 3>&1
271cd88b886SDevin TeskePARTMODE=`echo $PMODES | xargs dialog --backtitle "FreeBSD Installer" \
272cd88b886SDevin Teske	--title "Partitioning" \
273cd88b886SDevin Teske	--menu "How would you like to partition your disk?" \
27431a0cf13SDevin Teske	0 0 0 2>&1 1>&3` || exit 1
275cd88b886SDevin Teskeexec 3>&-
276cd88b886SDevin Teske
277cd88b886SDevin Teskecase "$PARTMODE" in
2787c1db228SNathan Whitehorn"Auto (UFS)")	# Guided
2797041a67eSAndrew Thompson	bsdinstall autopart || error "Partitioning error"
2807041a67eSAndrew Thompson	bsdinstall mount || error "Failed to mount filesystem"
2812118f387SNathan Whitehorn	;;
282cd88b886SDevin Teske"Shell")	# Shell
2832118f387SNathan Whitehorn	clear
2842118f387SNathan 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'."
285809685bcSNathan Whitehorn	sh 2>&1
2862118f387SNathan Whitehorn	;;
287cd88b886SDevin Teske"Manual")	# Manual
288bc4a673fSDevin Teske	if f_isset debugFile; then
289bc4a673fSDevin Teske		# Give partedit the path to our logfile so it can append
2907041a67eSAndrew Thompson		BSDINSTALL_LOG="${debugFile#+}" bsdinstall partedit || error "Partitioning error"
291bc4a673fSDevin Teske	else
2927041a67eSAndrew Thompson		bsdinstall partedit || error "Partitioning error"
293bc4a673fSDevin Teske	fi
2947041a67eSAndrew Thompson	bsdinstall mount || error "Failed to mount filesystem"
2952118f387SNathan Whitehorn	;;
2967c1db228SNathan Whitehorn"Auto (ZFS)")	# ZFS
2977041a67eSAndrew Thompson	bsdinstall zfsboot || error "ZFS setup failed"
2987041a67eSAndrew Thompson	bsdinstall mount || error "Failed to mount filesystem"
299cd88b886SDevin Teske	;;
3002118f387SNathan Whitehorn*)
3017041a67eSAndrew Thompson	error "Unknown partitioning mode"
3022118f387SNathan Whitehorn	;;
3032118f387SNathan Whitehornesac
3042118f387SNathan Whitehorn
3052118f387SNathan Whitehornif [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
3062118f387SNathan Whitehorn	ALL_DISTRIBUTIONS="$DISTRIBUTIONS"
30788343186SGlen Barber	WANT_DEBUG=
3082118f387SNathan Whitehorn
3092118f387SNathan Whitehorn	# Download to a directory in the new system as scratch space
31084b58c13SNathan Whitehorn	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
3117041a67eSAndrew Thompson	mkdir -p "$BSDINSTALL_FETCHDEST" || error "Could not create directory $BSDINSTALL_FETCHDEST"
3122118f387SNathan Whitehorn
3132118f387SNathan Whitehorn	export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
3142118f387SNathan Whitehorn	# Try to use any existing distfiles
3155a038452SNathan Whitehorn	if [ -d $BSDINSTALL_DISTDIR ]; then
3166dcef0cfSNathan Whitehorn		DISTDIR_IS_UNIONFS=1
317bfc3bab8SNathan Whitehorn		mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
3186d02d4cbSNathan Whitehorn	else
31988343186SGlen Barber		export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
3202118f387SNathan Whitehorn		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
3212118f387SNathan Whitehorn	fi
3222118f387SNathan Whitehorn
3236d02d4cbSNathan Whitehorn	export FTP_PASSIVE_MODE=YES
32488343186SGlen Barber	# Iterate through the distribution list and set a flag if debugging
32588343186SGlen Barber	# distributions have been selected.
32688343186SGlen Barber	for _DISTRIBUTION in $DISTRIBUTIONS; do
32788343186SGlen Barber		case $_DISTRIBUTION in
32888343186SGlen Barber			*-dbg.*)
32988343186SGlen Barber				[ -e $BSDINSTALL_DISTDIR/$_DISTRIBUTION ] \
33088343186SGlen Barber					&& continue
33188343186SGlen Barber				WANT_DEBUG=1
33288343186SGlen Barber				DEBUG_LIST="\n$DEBUG_LIST\n$_DISTRIBUTION"
33388343186SGlen Barber				;;
33488343186SGlen Barber			*)
33588343186SGlen Barber				;;
33688343186SGlen Barber		esac
33788343186SGlen Barber	done
33888343186SGlen Barber
33988343186SGlen Barber	# Fetch the distributions.
34088343186SGlen Barber	bsdinstall distfetch
34188343186SGlen Barber	rc=$?
34288343186SGlen Barber
34388343186SGlen Barber	if [ $rc -ne 0 ]; then
34488343186SGlen Barber		# If unable to fetch the remote distributions, recommend
34588343186SGlen Barber		# deselecting the debugging distributions, and retrying the
34688343186SGlen Barber		# installation, since failure to fetch *-dbg.txz should not
34788343186SGlen Barber		# be considered a fatal installation error.
34888343186SGlen Barber		msg="Failed to fetch remote distribution"
34988343186SGlen Barber		if [ ! -z "$WANT_DEBUG" ]; then
35088343186SGlen Barber			# Trim leading and trailing newlines.
35188343186SGlen Barber			DEBUG_LIST="${DEBUG_LIST%%\n}"
35288343186SGlen Barber			DEBUG_LIST="${DEBUG_LIST##\n}"
35388343186SGlen Barber			msg="$msg\n\nPlease deselect the following distributions"
35488343186SGlen Barber			msg="$msg and retry the installation:"
35588343186SGlen Barber			msg="$msg\n$DEBUG_LIST"
35688343186SGlen Barber		fi
35788343186SGlen Barber		error "$msg"
35888343186SGlen Barber	fi
3592118f387SNathan Whitehorn	export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
3602118f387SNathan Whitehornfi
3612118f387SNathan Whitehorn
36288343186SGlen Barberif [ ! -z "$LOCAL_DISTRIBUTIONS" ]; then
36388343186SGlen Barber	# Download to a directory in the new system as scratch space
36488343186SGlen Barber	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
36588343186SGlen Barber	mkdir -p "$BSDINSTALL_FETCHDEST" || error "Could not create directory $BSDINSTALL_FETCHDEST"
36688343186SGlen Barber	# Try to use any existing distfiles
36788343186SGlen Barber	if [ -d $BSDINSTALL_DISTDIR ]; then
36888343186SGlen Barber		DISTDIR_IS_UNIONFS=1
36988343186SGlen Barber		mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
37088343186SGlen Barber		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
37188343186SGlen Barber	fi
37288343186SGlen Barber	env DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS" \
37388343186SGlen Barber		BSDINSTALL_DISTSITE="file:///usr/freebsd-dist" \
37488343186SGlen Barber		bsdinstall distfetch || \
37588343186SGlen Barber		error "Failed to fetch distribution from local media"
37688343186SGlen Barberfi
37788343186SGlen Barber
3787041a67eSAndrew Thompsonbsdinstall checksum || error "Distribution checksum failed"
3797041a67eSAndrew Thompsonbsdinstall distextract || error "Distribution extract failed"
380*8befcf7bSNathan Whitehorn
381*8befcf7bSNathan Whitehorn# Set up boot loader
382*8befcf7bSNathan Whitehornbsdinstall bootconfig || error "Failed to configure bootloader"
383*8befcf7bSNathan Whitehorn
3847041a67eSAndrew Thompsonbsdinstall rootpass || error "Could not set root password"
3852118f387SNathan Whitehorn
3862118f387SNathan Whitehorntrap true SIGINT	# This section is optional
3872118f387SNathan Whitehornif [ "$NETCONFIG_DONE" != yes ]; then
3882118f387SNathan Whitehorn	bsdinstall netconfig	# Don't check for errors -- the user may cancel
3892118f387SNathan Whitehornfi
3902118f387SNathan Whitehornbsdinstall time
3912118f387SNathan Whitehornbsdinstall services
3920e3f233fSBartek Rutkowskibsdinstall hardening
3932118f387SNathan Whitehorn
3942118f387SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
3952118f387SNathan Whitehorn    "Would you like to add users to the installed system now?" 0 0 && \
3962118f387SNathan Whitehorn    bsdinstall adduser
3972118f387SNathan Whitehorn
3982118f387SNathan Whitehornfinalconfig() {
3992118f387SNathan Whitehorn	exec 3>&1
4002118f387SNathan Whitehorn	REVISIT=$(dialog --backtitle "FreeBSD Installer" \
4012118f387SNathan Whitehorn	    --title "Final Configuration" --no-cancel --menu \
4026081c922SNathan Whitehorn	    "Setup of your FreeBSD system is nearly complete. You can now modify your configuration choices. After this screen, you will have an opportunity to make more complex changes using a shell." 0 0 0 \
40322a84ec9SKen Smith		"Exit" "Apply configuration and exit installer" \
4042118f387SNathan Whitehorn		"Add User" "Add a user to the system" \
4052118f387SNathan Whitehorn		"Root Password" "Change root password" \
4062118f387SNathan Whitehorn		"Hostname" "Set system hostname" \
4072118f387SNathan Whitehorn		"Network" "Networking configuration" \
4082118f387SNathan Whitehorn		"Services" "Set daemons to run on startup" \
4090e3f233fSBartek Rutkowski		"System Hardening" "Set security options" \
4102118f387SNathan Whitehorn		"Time Zone" "Set system timezone" \
4116081c922SNathan Whitehorn		"Handbook" "Install FreeBSD Handbook (requires network)" 2>&1 1>&3)
4122118f387SNathan Whitehorn	exec 3>&-
4132118f387SNathan Whitehorn
4142118f387SNathan Whitehorn	case "$REVISIT" in
4152118f387SNathan Whitehorn	"Add User")
4162118f387SNathan Whitehorn		bsdinstall adduser
4172118f387SNathan Whitehorn		finalconfig
4182118f387SNathan Whitehorn		;;
4192118f387SNathan Whitehorn	"Root Password")
4202118f387SNathan Whitehorn		bsdinstall rootpass
4212118f387SNathan Whitehorn		finalconfig
4222118f387SNathan Whitehorn		;;
4232118f387SNathan Whitehorn	"Hostname")
4242118f387SNathan Whitehorn		bsdinstall hostname
4252118f387SNathan Whitehorn		finalconfig
4262118f387SNathan Whitehorn		;;
4272118f387SNathan Whitehorn	"Network")
4282118f387SNathan Whitehorn		bsdinstall netconfig
4292118f387SNathan Whitehorn		finalconfig
4302118f387SNathan Whitehorn		;;
4312118f387SNathan Whitehorn	"Services")
4322118f387SNathan Whitehorn		bsdinstall services
4332118f387SNathan Whitehorn		finalconfig
4342118f387SNathan Whitehorn		;;
4350e3f233fSBartek Rutkowski	"System Hardening")
4360e3f233fSBartek Rutkowski		bsdinstall hardening
4370e3f233fSBartek Rutkowski		finalconfig
4380e3f233fSBartek Rutkowski		;;
4392118f387SNathan Whitehorn	"Time Zone")
4402118f387SNathan Whitehorn		bsdinstall time
4412118f387SNathan Whitehorn		finalconfig
4422118f387SNathan Whitehorn		;;
443bfc3bab8SNathan Whitehorn	"Handbook")
444bfc3bab8SNathan Whitehorn		bsdinstall docsinstall
445bfc3bab8SNathan Whitehorn		finalconfig
446bfc3bab8SNathan Whitehorn		;;
4472118f387SNathan Whitehorn	esac
4482118f387SNathan Whitehorn}
4492118f387SNathan Whitehorn
4502118f387SNathan Whitehorn# Allow user to change his mind
4512118f387SNathan Whitehornfinalconfig
4522118f387SNathan Whitehorn
4532118f387SNathan Whitehorntrap error SIGINT	# SIGINT is bad again
4547041a67eSAndrew Thompsonbsdinstall config  || error "Failed to save config"
4552118f387SNathan Whitehorn
456371ce0ebSRenato Botelhoif [ -n "$DISTDIR_IS_UNIONFS" ]; then
457371ce0ebSRenato Botelho	umount -f $BSDINSTALL_DISTDIR
458371ce0ebSRenato Botelhofi
459371ce0ebSRenato Botelho
4602118f387SNathan Whitehornif [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
4612118f387SNathan Whitehorn	rm -rf "$BSDINSTALL_FETCHDEST"
4622118f387SNathan Whitehornfi
4632118f387SNathan Whitehorn
4646081c922SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Manual Configuration" \
46544a25dd6SNathan Whitehorn    --default-button no --yesno \
46644a25dd6SNathan Whitehorn   "The installation is now finished. Before exiting the installer, would you like to open a shell in the new system to make any final manual modifications?" 0 0
4676081c922SNathan Whitehornif [ $? -eq 0 ]; then
4686081c922SNathan Whitehorn	clear
4696081c922SNathan Whitehorn	echo This shell is operating in a chroot in the new system. \
4706081c922SNathan Whitehorn	    When finished making configuration changes, type \"exit\".
4716081c922SNathan Whitehorn	chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1
4726081c922SNathan Whitehornfi
4736081c922SNathan Whitehorn
474dfc23ba5SDag-Erling Smørgravbsdinstall entropy
475dfc23ba5SDag-Erling Smørgravbsdinstall umount
476dfc23ba5SDag-Erling Smørgrav
477bc4a673fSDevin Teskef_dprintf "Installation Completed at %s" "$( date )"
4782118f387SNathan Whitehorn
479bc4a673fSDevin Teske################################################################################
480bc4a673fSDevin Teske# END
481bc4a673fSDevin Teske################################################################################
482