xref: /freebsd/usr.sbin/bsdinstall/scripts/auto (revision 595373dd646b9c6fb22b03e238f6f179d9d263c9)
12118f387SNathan Whitehorn#!/bin/sh
22118f387SNathan Whitehorn#-
32118f387SNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn
4f0c98fdeSDevin Teske# Copyright (c) 2013-2018 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
36f0c98fdeSDevin Teske############################################################ GLOBALS
372118f387SNathan Whitehorn
38f0c98fdeSDevin Teske#
39f0c98fdeSDevin Teske# Strings that should be moved to an i18n file and loaded with f_include_lang()
40f0c98fdeSDevin Teske#
417059fa6fSAllan Judehline_arrows_tab_enter="Press arrows, TAB or ENTER"
42f0c98fdeSDevin Teskehline_arrows_tab_space_enter="Press arrows, TAB, SPACE or ENTER"
43f0c98fdeSDevin Teskemsg_abort="Abort"
44*595373ddSBen Woodsmsg_an_installation_step_has_been_aborted="An installation step has been aborted. Would you like\nto restart the installation or exit the installer?"
45*595373ddSBen Woodsmsg_auto_ufs="Auto (UFS)"
46*595373ddSBen Woodsmsg_auto_ufs_desc="Guided UFS Disk Setup"
47*595373ddSBen Woodsmsg_auto_ufs_help="Menu options help choose which disk to setup using UFS and standard partitions"
48*595373ddSBen Woodsmsg_auto_zfs="Auto (ZFS)"
49*595373ddSBen Woodsmsg_auto_zfs_desc="Guided Root-on-ZFS"
50*595373ddSBen Woodsmsg_auto_zfs_help="To use ZFS with less than 8GB RAM, see https://wiki.freebsd.org/ZFSTuningGuide"
51f0c98fdeSDevin Teskemsg_exit="Exit"
52f0c98fdeSDevin Teskemsg_freebsd_installer="FreeBSD Installer"
53a7d5d8d9SAllan 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?"
547059fa6fSAllan 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?"
55*595373ddSBen Woodsmsg_manual="Manual"
56*595373ddSBen Woodsmsg_manual_desc="Manual Disk Setup (experts)"
57*595373ddSBen Woodsmsg_manual_help="Create customized partitions from menu options"
587059fa6fSAllan Judemsg_no="NO"
59f0c98fdeSDevin Teskemsg_restart="Restart"
60*595373ddSBen Woodsmsg_shell="Shell"
61*595373ddSBen Woodsmsg_shell_desc="Open a shell and partition by hand"
62*595373ddSBen Woodsmsg_shell_help="Create customized partitions using command-line utilities"
637059fa6fSAllan Judemsg_yes="YES"
647059fa6fSAllan Jude
65f0c98fdeSDevin Teske############################################################ FUNCTIONS
66f0c98fdeSDevin Teske
67f0c98fdeSDevin Teske# error [$msg]
68f0c98fdeSDevin Teske#
69f0c98fdeSDevin Teske# Display generic error message when a script fails. An optional message
70f0c98fdeSDevin Teske# argument can preceed the generic message. User is given the choice of
71f0c98fdeSDevin Teske# restarting the installer or exiting.
72f0c98fdeSDevin Teske#
73f0c98fdeSDevin Teskeerror()
74f0c98fdeSDevin Teske{
75f0c98fdeSDevin Teske	local title="$msg_abort"
76f0c98fdeSDevin Teske	local btitle="$msg_freebsd_installer"
77f0c98fdeSDevin Teske	local prompt="${1:+$1\n\n}$msg_an_installation_step_has_been_aborted"
78f0c98fdeSDevin Teske	local hline="$hline_arrows_tab_space_enter"
79f0c98fdeSDevin Teske
80f0c98fdeSDevin Teske	[ "$DISTDIR_IS_UNIONFS" ] && umount -f "$BSDINSTALL_DISTDIR"
81f0c98fdeSDevin Teske	[ -f "$PATH_FSTAB" ] && bsdinstall umount
82f0c98fdeSDevin Teske
83f0c98fdeSDevin Teske	local height width
84f0c98fdeSDevin Teske	f_dialog_buttonbox_size height width \
85f0c98fdeSDevin Teske		"$title" "$btitle" "$prompt" "$hline"
86f0c98fdeSDevin Teske
87f0c98fdeSDevin Teske	if $DIALOG \
88f0c98fdeSDevin Teske		--title "$title"           \
89f0c98fdeSDevin Teske		--backtitle "$btitle"      \
90f0c98fdeSDevin Teske		--hline "$hline"           \
91f0c98fdeSDevin Teske		--no-label "$msg_exit"     \
92f0c98fdeSDevin Teske		--yes-label "$msg_restart" \
93f0c98fdeSDevin Teske		--yesno "$prompt" $height $width
94f0c98fdeSDevin Teske	then
95f0c98fdeSDevin Teske		exec $0
96f0c98fdeSDevin Teske		# NOTREACHED
97f0c98fdeSDevin Teske	fi
98f0c98fdeSDevin Teske	exit 1
99f0c98fdeSDevin Teske}
100f0c98fdeSDevin Teske
1017059fa6fSAllan Jude# dialog_workaround
1027059fa6fSAllan Jude#
1037059fa6fSAllan Jude# Ask the user if they wish to apply a workaround
1047059fa6fSAllan Jude#
1057059fa6fSAllan Judedialog_workaround()
1067059fa6fSAllan Jude{
1077059fa6fSAllan Jude	local passed_msg="$1"
1087059fa6fSAllan Jude	local title="$DIALOG_TITLE"
1097059fa6fSAllan Jude	local btitle="$DIALOG_BACKTITLE"
1107059fa6fSAllan Jude	local prompt # Calculated below
1117059fa6fSAllan Jude	local hline="$hline_arrows_tab_enter"
1127059fa6fSAllan Jude
1137059fa6fSAllan Jude	local height=8 width=50 prefix="   "
1147059fa6fSAllan Jude	local plen=${#prefix} list= line=
1157059fa6fSAllan Jude	local max_width=$(( $width - 3 - $plen ))
1167059fa6fSAllan Jude
1177059fa6fSAllan Jude	local yes no defaultno extra_args format
1187059fa6fSAllan Jude	if [ "$USE_XDIALOG" ]; then
1197059fa6fSAllan Jude		yes=ok no=cancel defaultno=default-no
1207059fa6fSAllan Jude		extra_args="--wrap --left"
1217059fa6fSAllan Jude		format="$passed_msg"
1227059fa6fSAllan Jude	else
1237059fa6fSAllan Jude		yes=yes no=no defaultno=defaultno
1247059fa6fSAllan Jude		extra_args="--cr-wrap"
1257059fa6fSAllan Jude		format="$passed_msg"
1267059fa6fSAllan Jude	fi
1277059fa6fSAllan Jude
1287059fa6fSAllan Jude	# Add height for Xdialog(1)
1297059fa6fSAllan Jude	[ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 ))
1307059fa6fSAllan Jude
1317059fa6fSAllan Jude	prompt=$( printf "$format" )
1327059fa6fSAllan Jude	f_dprintf "%s: Workaround prompt" "$0"
1337059fa6fSAllan Jude	$DIALOG \
1347059fa6fSAllan Jude		--title "$title"        \
1357059fa6fSAllan Jude		--backtitle "$btitle"   \
1367059fa6fSAllan Jude		--hline "$hline"        \
1377059fa6fSAllan Jude		--$yes-label "$msg_yes" \
1387059fa6fSAllan Jude		--$no-label "$msg_no"   \
1397059fa6fSAllan Jude		$extra_args             \
1407059fa6fSAllan Jude		--yesno "$prompt" $height $width
1417059fa6fSAllan Jude}
1427059fa6fSAllan Jude
143bc4a673fSDevin Teske############################################################ MAIN
144bc4a673fSDevin Teske
145bc4a673fSDevin Teskef_dprintf "Began Installation at %s" "$( date )"
1462118f387SNathan Whitehorn
1472118f387SNathan Whitehornrm -rf $BSDINSTALL_TMPETC
1482118f387SNathan Whitehornmkdir $BSDINSTALL_TMPETC
1492118f387SNathan Whitehorn
1502118f387SNathan Whitehorntrap true SIGINT	# This section is optional
1512118f387SNathan Whitehornbsdinstall keymap
1522118f387SNathan Whitehorn
1532118f387SNathan Whitehorntrap error SIGINT	# Catch cntrl-C here
1547041a67eSAndrew Thompsonbsdinstall hostname || error "Set hostname failed"
1552118f387SNathan Whitehorn
156b70047d4SNathan Whitehornexport DISTRIBUTIONS="base.txz kernel.txz"
157b70047d4SNathan Whitehornif [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
15888343186SGlen Barber	DISTMENU=`awk -F'\t' '!/^(kernel\.txz|base\.txz)/{print $1,$5,$6}' $BSDINSTALL_DISTDIR/MANIFEST`
15988343186SGlen Barber	DISTMENU="$(echo ${DISTMENU} | sed -E 's/\.txz//g')"
160addc19a4SNathan Whitehorn
161addc19a4SNathan Whitehorn	exec 3>&1
1624ca6fb65SDevin Teske	EXTRA_DISTS=$( eval dialog \
1634ca6fb65SDevin Teske	    --backtitle \"FreeBSD Installer\" \
1644ca6fb65SDevin Teske	    --title \"Distribution Select\" --nocancel --separate-output \
1654ca6fb65SDevin Teske	    --checklist \"Choose optional system components to install:\" \
1664ca6fb65SDevin Teske	    0 0 0 $DISTMENU \
167addc19a4SNathan Whitehorn	2>&1 1>&3 )
168addc19a4SNathan Whitehorn	for dist in $EXTRA_DISTS; do
169addc19a4SNathan Whitehorn		export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
170addc19a4SNathan Whitehorn	done
171b70047d4SNathan Whitehornfi
172addc19a4SNathan Whitehorn
17388343186SGlen BarberLOCAL_DISTRIBUTIONS="MANIFEST"
1742118f387SNathan WhitehornFETCH_DISTRIBUTIONS=""
1752118f387SNathan Whitehornfor dist in $DISTRIBUTIONS; do
1762118f387SNathan Whitehorn	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
1772118f387SNathan Whitehorn		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
17888343186SGlen Barber	else
17988343186SGlen Barber		LOCAL_DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS $dist"
1802118f387SNathan Whitehorn	fi
1812118f387SNathan Whitehorndone
18288343186SGlen BarberLOCAL_DISTRIBUTIONS=`echo $LOCAL_DISTRIBUTIONS`	# Trim white space
1836dcef0cfSNathan WhitehornFETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS`	# Trim white space
1842118f387SNathan Whitehorn
1856dcef0cfSNathan Whitehornif [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then
18688343186SGlen 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
1872118f387SNathan Whitehorn	bsdinstall netconfig || error
1882118f387SNathan Whitehorn	NETCONFIG_DONE=yes
1892118f387SNathan Whitehornfi
1902118f387SNathan Whitehorn
1915a038452SNathan Whitehornif [ -n "$FETCH_DISTRIBUTIONS" ]; then
1926dcef0cfSNathan Whitehorn	exec 3>&1
19326976226SNathan Whitehorn	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
1946dcef0cfSNathan Whitehorn	MIRROR_BUTTON=$?
1956dcef0cfSNathan Whitehorn	exec 3>&-
1967041a67eSAndrew Thompson	test $MIRROR_BUTTON -eq 0 || error "No mirror selected"
1976dcef0cfSNathan Whitehorn	export BSDINSTALL_DISTSITE
1986dcef0cfSNathan Whitehornfi
1996dcef0cfSNathan Whitehorn
2002d5cf580SDevin Teskerm -f $PATH_FSTAB
2012118f387SNathan Whitehorntouch $PATH_FSTAB
2022118f387SNathan Whitehorn
2037059fa6fSAllan Jude#
2047059fa6fSAllan Jude# Try to detect known broken platforms and apply their workarounds
2057059fa6fSAllan Jude#
2067059fa6fSAllan Jude
2077059fa6fSAllan Judeif f_interactive; then
2087059fa6fSAllan Jude	sys_maker=$( kenv -q smbios.system.maker )
2097059fa6fSAllan Jude	f_dprintf "smbios.system.maker=[%s]" "$sys_maker"
2107059fa6fSAllan Jude	sys_model=$( kenv -q smbios.system.product )
2117059fa6fSAllan Jude	f_dprintf "smbios.system.product=[%s]" "$sys_model"
2127059fa6fSAllan Jude	sys_version=$( kenv -q smbios.system.version )
2137059fa6fSAllan Jude	f_dprintf "smbios.system.version=[%s]" "$sys_version"
214a7d5d8d9SAllan Jude	sys_mb_maker=$( kenv -q smbios.planar.maker )
215a7d5d8d9SAllan Jude	f_dprintf "smbios.planar.maker=[%s]" "$sys_mb_maker"
216a7d5d8d9SAllan Jude	sys_mb_product=$( kenv -q smbios.planar.product )
217a7d5d8d9SAllan Jude	f_dprintf "smbios.planar.product=[%s]" "$sys_mb_product"
218a7d5d8d9SAllan Jude
219a7d5d8d9SAllan Jude	#
220a7d5d8d9SAllan Jude	# Laptop Models
221a7d5d8d9SAllan Jude	#
2227059fa6fSAllan Jude	case "$sys_maker" in
2237059fa6fSAllan Jude	"LENOVO")
2247059fa6fSAllan Jude		case "$sys_version" in
225229c92e7SAllan Jude		"ThinkPad X220"|"ThinkPad T420"|"ThinkPad T520"|"ThinkPad W520"|"ThinkPad X1")
2267059fa6fSAllan Jude			dialog_workaround "$msg_lenovo_fix"
2277059fa6fSAllan Jude			retval=$?
2287059fa6fSAllan Jude			f_dprintf "lenovofix_prompt=[%s]" "$retval"
2297059fa6fSAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
2307059fa6fSAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix"
2317059fa6fSAllan Jude				export WORKAROUND_LENOVO=1
2327059fa6fSAllan Jude			fi
2337059fa6fSAllan Jude			;;
2347059fa6fSAllan Jude		esac
2357059fa6fSAllan Jude		;;
2367059fa6fSAllan Jude	"Dell Inc.")
2377059fa6fSAllan Jude		case "$sys_model" in
238e3026446SAllan Jude		"Latitude E6330"|"Latitude E7440"|"Latitude E7240"|"Precision Tower 5810")
239a7d5d8d9SAllan Jude			dialog_workaround "$msg_gpt_active_fix"
240a7d5d8d9SAllan Jude			retval=$?
241a7d5d8d9SAllan Jude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
242a7d5d8d9SAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
243a7d5d8d9SAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
244a7d5d8d9SAllan Jude				export WORKAROUND_GPTACTIVE=1
245a7d5d8d9SAllan Jude			fi
246a7d5d8d9SAllan Jude			;;
247a7d5d8d9SAllan Jude		esac
248a7d5d8d9SAllan Jude		;;
2494c95e76aSAllan Jude	"Hewlett-Packard")
2504c95e76aSAllan Jude		case "$sys_model" in
2514c95e76aSAllan Jude		"HP ProBook 4330s")
2524c95e76aSAllan Jude			dialog_workaround "$msg_gpt_active_fix"
2534c95e76aSAllan Jude			retval=$?
2544c95e76aSAllan Jude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
2554c95e76aSAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
2564c95e76aSAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
2574c95e76aSAllan Jude				export WORKAROUND_GPTACTIVE=1
2584c95e76aSAllan Jude			fi
2594c95e76aSAllan Jude			;;
2604c95e76aSAllan Jude		esac
2614c95e76aSAllan Jude		;;
262a7d5d8d9SAllan Jude	esac
263a7d5d8d9SAllan Jude	#
264a7d5d8d9SAllan Jude	# Motherboard Models
265a7d5d8d9SAllan Jude	#
266a7d5d8d9SAllan Jude	case "$sys_mb_maker" in
267a7d5d8d9SAllan Jude	"Intel Corporation")
268a7d5d8d9SAllan Jude		case "$sys_mb_product" in
2694c95e76aSAllan Jude		"DP965LT"|"D510MO")
2704c95e76aSAllan Jude			dialog_workaround "$msg_gpt_active_fix"
2714c95e76aSAllan Jude			retval=$?
2724c95e76aSAllan Jude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
2734c95e76aSAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
2744c95e76aSAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
2754c95e76aSAllan Jude				export WORKAROUND_GPTACTIVE=1
2764c95e76aSAllan Jude			fi
2774c95e76aSAllan Jude			;;
2784c95e76aSAllan Jude		esac
2794c95e76aSAllan Jude		;;
2804c95e76aSAllan Jude	"Acer")
2814c95e76aSAllan Jude		case "$sys_mb_product" in
2824c95e76aSAllan Jude		"Veriton M6630G")
2837059fa6fSAllan Jude			dialog_workaround "$msg_gpt_active_fix"
2847059fa6fSAllan Jude			retval=$?
2857059fa6fSAllan Jude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
2867059fa6fSAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
2877059fa6fSAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
2887059fa6fSAllan Jude				export WORKAROUND_GPTACTIVE=1
2897059fa6fSAllan Jude			fi
2907059fa6fSAllan Jude			;;
2917059fa6fSAllan Jude		esac
2927059fa6fSAllan Jude		;;
2937059fa6fSAllan Jude	esac
2947059fa6fSAllan Judefi
2957059fa6fSAllan Jude
296*595373ddSBen WoodsPMODES="
297*595373ddSBen Woods	'$msg_auto_ufs' '$msg_auto_ufs_desc' '$msg_auto_ufs_help'
298*595373ddSBen Woods	'$msg_manual' '$msg_manual_desc' '$msg_manual_help'
299*595373ddSBen Woods	'$msg_shell' '$msg_shell_desc' '$msg_shell_help'
300*595373ddSBen Woods" # END-QUOTE
3012118f387SNathan Whitehorn
302cd88b886SDevin TeskeCURARCH=$( uname -m )
303cd88b886SDevin Teskecase $CURARCH in
3043735bba3SAllan Jude	amd64|arm64|i386)	# Booting ZFS Supported
305*595373ddSBen Woods		PMODES="
306*595373ddSBen Woods			'$msg_auto_zfs' '$msg_auto_zfs_desc' '$msg_auto_zfs_help'
307*595373ddSBen Woods			$PMODES
308*595373ddSBen Woods		" # END-QUOTE
309cd88b886SDevin Teske		;;
310*595373ddSBen Woods	*)			# Booting ZFS Unsupported
311cd88b886SDevin Teske		;;
312cd88b886SDevin Teskeesac
313cd88b886SDevin Teske
314cd88b886SDevin Teskeexec 3>&1
315cd88b886SDevin TeskePARTMODE=`echo $PMODES | xargs dialog --backtitle "FreeBSD Installer" \
316cd88b886SDevin Teske	--title "Partitioning" \
317*595373ddSBen Woods	--item-help \
318cd88b886SDevin Teske	--menu "How would you like to partition your disk?" \
31931a0cf13SDevin Teske	0 0 0 2>&1 1>&3` || exit 1
320cd88b886SDevin Teskeexec 3>&-
321cd88b886SDevin Teske
322cd88b886SDevin Teskecase "$PARTMODE" in
323*595373ddSBen Woods"$msg_auto_zfs")	# ZFS
324d512033eSBen Woods	bsdinstall zfsboot || error "ZFS setup failed"
325d512033eSBen Woods	bsdinstall mount || error "Failed to mount filesystem"
326d512033eSBen Woods	;;
327*595373ddSBen Woods"$msg_auto_ufs")	# Guided UFS
3287041a67eSAndrew Thompson	bsdinstall autopart || error "Partitioning error"
3297041a67eSAndrew Thompson	bsdinstall mount || error "Failed to mount filesystem"
3302118f387SNathan Whitehorn	;;
331*595373ddSBen Woods"$msg_shell")		# Shell
3322118f387SNathan Whitehorn	clear
3332118f387SNathan 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'."
334809685bcSNathan Whitehorn	sh 2>&1
3352118f387SNathan Whitehorn	;;
336*595373ddSBen Woods"$msg_manual")		# Manual
337bc4a673fSDevin Teske	if f_isset debugFile; then
338bc4a673fSDevin Teske		# Give partedit the path to our logfile so it can append
3397041a67eSAndrew Thompson		BSDINSTALL_LOG="${debugFile#+}" bsdinstall partedit || error "Partitioning error"
340bc4a673fSDevin Teske	else
3417041a67eSAndrew Thompson		bsdinstall partedit || error "Partitioning error"
342bc4a673fSDevin Teske	fi
3437041a67eSAndrew Thompson	bsdinstall mount || error "Failed to mount filesystem"
3442118f387SNathan Whitehorn	;;
3452118f387SNathan Whitehorn*)
3467041a67eSAndrew Thompson	error "Unknown partitioning mode"
3472118f387SNathan Whitehorn	;;
3482118f387SNathan Whitehornesac
3492118f387SNathan Whitehorn
3502118f387SNathan Whitehornif [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
3512118f387SNathan Whitehorn	ALL_DISTRIBUTIONS="$DISTRIBUTIONS"
35288343186SGlen Barber	WANT_DEBUG=
3532118f387SNathan Whitehorn
3542118f387SNathan Whitehorn	# Download to a directory in the new system as scratch space
35584b58c13SNathan Whitehorn	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
3567041a67eSAndrew Thompson	mkdir -p "$BSDINSTALL_FETCHDEST" || error "Could not create directory $BSDINSTALL_FETCHDEST"
3572118f387SNathan Whitehorn
3582118f387SNathan Whitehorn	export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
3592118f387SNathan Whitehorn	# Try to use any existing distfiles
3605a038452SNathan Whitehorn	if [ -d $BSDINSTALL_DISTDIR ]; then
3616dcef0cfSNathan Whitehorn		DISTDIR_IS_UNIONFS=1
362bfc3bab8SNathan Whitehorn		mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
3636d02d4cbSNathan Whitehorn	else
36488343186SGlen Barber		export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
3652118f387SNathan Whitehorn		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
3662118f387SNathan Whitehorn	fi
3672118f387SNathan Whitehorn
3686d02d4cbSNathan Whitehorn	export FTP_PASSIVE_MODE=YES
36988343186SGlen Barber	# Iterate through the distribution list and set a flag if debugging
37088343186SGlen Barber	# distributions have been selected.
37188343186SGlen Barber	for _DISTRIBUTION in $DISTRIBUTIONS; do
37288343186SGlen Barber		case $_DISTRIBUTION in
37388343186SGlen Barber			*-dbg.*)
37488343186SGlen Barber				[ -e $BSDINSTALL_DISTDIR/$_DISTRIBUTION ] \
37588343186SGlen Barber					&& continue
37688343186SGlen Barber				WANT_DEBUG=1
37788343186SGlen Barber				DEBUG_LIST="\n$DEBUG_LIST\n$_DISTRIBUTION"
37888343186SGlen Barber				;;
37988343186SGlen Barber			*)
38088343186SGlen Barber				;;
38188343186SGlen Barber		esac
38288343186SGlen Barber	done
38388343186SGlen Barber
38488343186SGlen Barber	# Fetch the distributions.
38588343186SGlen Barber	bsdinstall distfetch
38688343186SGlen Barber	rc=$?
38788343186SGlen Barber
38888343186SGlen Barber	if [ $rc -ne 0 ]; then
38988343186SGlen Barber		# If unable to fetch the remote distributions, recommend
39088343186SGlen Barber		# deselecting the debugging distributions, and retrying the
39188343186SGlen Barber		# installation, since failure to fetch *-dbg.txz should not
39288343186SGlen Barber		# be considered a fatal installation error.
39388343186SGlen Barber		msg="Failed to fetch remote distribution"
39488343186SGlen Barber		if [ ! -z "$WANT_DEBUG" ]; then
39588343186SGlen Barber			# Trim leading and trailing newlines.
39688343186SGlen Barber			DEBUG_LIST="${DEBUG_LIST%%\n}"
39788343186SGlen Barber			DEBUG_LIST="${DEBUG_LIST##\n}"
39888343186SGlen Barber			msg="$msg\n\nPlease deselect the following distributions"
39988343186SGlen Barber			msg="$msg and retry the installation:"
40088343186SGlen Barber			msg="$msg\n$DEBUG_LIST"
40188343186SGlen Barber		fi
40288343186SGlen Barber		error "$msg"
40388343186SGlen Barber	fi
4042118f387SNathan Whitehorn	export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
4052118f387SNathan Whitehornfi
4062118f387SNathan Whitehorn
40788343186SGlen Barberif [ ! -z "$LOCAL_DISTRIBUTIONS" ]; then
40888343186SGlen Barber	# Download to a directory in the new system as scratch space
40988343186SGlen Barber	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
41088343186SGlen Barber	mkdir -p "$BSDINSTALL_FETCHDEST" || error "Could not create directory $BSDINSTALL_FETCHDEST"
41188343186SGlen Barber	# Try to use any existing distfiles
41288343186SGlen Barber	if [ -d $BSDINSTALL_DISTDIR ]; then
41388343186SGlen Barber		DISTDIR_IS_UNIONFS=1
41488343186SGlen Barber		mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
41588343186SGlen Barber		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
41688343186SGlen Barber	fi
41788343186SGlen Barber	env DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS" \
41888343186SGlen Barber		BSDINSTALL_DISTSITE="file:///usr/freebsd-dist" \
41988343186SGlen Barber		bsdinstall distfetch || \
42088343186SGlen Barber		error "Failed to fetch distribution from local media"
42188343186SGlen Barberfi
42288343186SGlen Barber
4237041a67eSAndrew Thompsonbsdinstall checksum || error "Distribution checksum failed"
4247041a67eSAndrew Thompsonbsdinstall distextract || error "Distribution extract failed"
4258befcf7bSNathan Whitehorn
4268befcf7bSNathan Whitehorn# Set up boot loader
4278befcf7bSNathan Whitehornbsdinstall bootconfig || error "Failed to configure bootloader"
4288befcf7bSNathan Whitehorn
4297041a67eSAndrew Thompsonbsdinstall rootpass || error "Could not set root password"
4302118f387SNathan Whitehorn
4312118f387SNathan Whitehorntrap true SIGINT	# This section is optional
4322118f387SNathan Whitehornif [ "$NETCONFIG_DONE" != yes ]; then
4332118f387SNathan Whitehorn	bsdinstall netconfig	# Don't check for errors -- the user may cancel
4342118f387SNathan Whitehornfi
4352118f387SNathan Whitehornbsdinstall time
4362118f387SNathan Whitehornbsdinstall services
4370e3f233fSBartek Rutkowskibsdinstall hardening
4382118f387SNathan Whitehorn
4392118f387SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
4402118f387SNathan Whitehorn    "Would you like to add users to the installed system now?" 0 0 && \
4412118f387SNathan Whitehorn    bsdinstall adduser
4422118f387SNathan Whitehorn
4432118f387SNathan Whitehornfinalconfig() {
4442118f387SNathan Whitehorn	exec 3>&1
4452118f387SNathan Whitehorn	REVISIT=$(dialog --backtitle "FreeBSD Installer" \
4462118f387SNathan Whitehorn	    --title "Final Configuration" --no-cancel --menu \
4476081c922SNathan 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 \
44822a84ec9SKen Smith		"Exit" "Apply configuration and exit installer" \
4492118f387SNathan Whitehorn		"Add User" "Add a user to the system" \
4502118f387SNathan Whitehorn		"Root Password" "Change root password" \
4512118f387SNathan Whitehorn		"Hostname" "Set system hostname" \
4522118f387SNathan Whitehorn		"Network" "Networking configuration" \
4532118f387SNathan Whitehorn		"Services" "Set daemons to run on startup" \
4540e3f233fSBartek Rutkowski		"System Hardening" "Set security options" \
4552118f387SNathan Whitehorn		"Time Zone" "Set system timezone" \
4566081c922SNathan Whitehorn		"Handbook" "Install FreeBSD Handbook (requires network)" 2>&1 1>&3)
4572118f387SNathan Whitehorn	exec 3>&-
4582118f387SNathan Whitehorn
4592118f387SNathan Whitehorn	case "$REVISIT" in
4602118f387SNathan Whitehorn	"Add User")
4612118f387SNathan Whitehorn		bsdinstall adduser
4622118f387SNathan Whitehorn		finalconfig
4632118f387SNathan Whitehorn		;;
4642118f387SNathan Whitehorn	"Root Password")
4652118f387SNathan Whitehorn		bsdinstall rootpass
4662118f387SNathan Whitehorn		finalconfig
4672118f387SNathan Whitehorn		;;
4682118f387SNathan Whitehorn	"Hostname")
4692118f387SNathan Whitehorn		bsdinstall hostname
4702118f387SNathan Whitehorn		finalconfig
4712118f387SNathan Whitehorn		;;
4722118f387SNathan Whitehorn	"Network")
4732118f387SNathan Whitehorn		bsdinstall netconfig
4742118f387SNathan Whitehorn		finalconfig
4752118f387SNathan Whitehorn		;;
4762118f387SNathan Whitehorn	"Services")
4772118f387SNathan Whitehorn		bsdinstall services
4782118f387SNathan Whitehorn		finalconfig
4792118f387SNathan Whitehorn		;;
4800e3f233fSBartek Rutkowski	"System Hardening")
4810e3f233fSBartek Rutkowski		bsdinstall hardening
4820e3f233fSBartek Rutkowski		finalconfig
4830e3f233fSBartek Rutkowski		;;
4842118f387SNathan Whitehorn	"Time Zone")
4852118f387SNathan Whitehorn		bsdinstall time
4862118f387SNathan Whitehorn		finalconfig
4872118f387SNathan Whitehorn		;;
488bfc3bab8SNathan Whitehorn	"Handbook")
489bfc3bab8SNathan Whitehorn		bsdinstall docsinstall
490bfc3bab8SNathan Whitehorn		finalconfig
491bfc3bab8SNathan Whitehorn		;;
4922118f387SNathan Whitehorn	esac
4932118f387SNathan Whitehorn}
4942118f387SNathan Whitehorn
4952118f387SNathan Whitehorn# Allow user to change his mind
4962118f387SNathan Whitehornfinalconfig
4972118f387SNathan Whitehorn
4982118f387SNathan Whitehorntrap error SIGINT	# SIGINT is bad again
4997041a67eSAndrew Thompsonbsdinstall config  || error "Failed to save config"
5002118f387SNathan Whitehorn
501371ce0ebSRenato Botelhoif [ -n "$DISTDIR_IS_UNIONFS" ]; then
502371ce0ebSRenato Botelho	umount -f $BSDINSTALL_DISTDIR
503371ce0ebSRenato Botelhofi
504371ce0ebSRenato Botelho
5052118f387SNathan Whitehornif [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
5062118f387SNathan Whitehorn	rm -rf "$BSDINSTALL_FETCHDEST"
5072118f387SNathan Whitehornfi
5082118f387SNathan Whitehorn
5096081c922SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Manual Configuration" \
51044a25dd6SNathan Whitehorn    --default-button no --yesno \
51144a25dd6SNathan 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
5126081c922SNathan Whitehornif [ $? -eq 0 ]; then
5136081c922SNathan Whitehorn	clear
5146081c922SNathan Whitehorn	echo This shell is operating in a chroot in the new system. \
5156081c922SNathan Whitehorn	    When finished making configuration changes, type \"exit\".
5166081c922SNathan Whitehorn	chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1
5176081c922SNathan Whitehornfi
5186081c922SNathan Whitehorn
519dfc23ba5SDag-Erling Smørgravbsdinstall entropy
520dfc23ba5SDag-Erling Smørgravbsdinstall umount
521dfc23ba5SDag-Erling Smørgrav
522bc4a673fSDevin Teskef_dprintf "Installation Completed at %s" "$( date )"
5232118f387SNathan Whitehorn
524bc4a673fSDevin Teske################################################################################
525bc4a673fSDevin Teske# END
526bc4a673fSDevin Teske################################################################################
527