xref: /freebsd/usr.sbin/bsdinstall/scripts/auto (revision 34b43f4b26e41a70fcb67ec5d8cf394f23b3fbf9)
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#
28bc4a673fSDevin Teske#
29bc4a673fSDevin Teske############################################################ INCLUDES
302118f387SNathan Whitehorn
31bc4a673fSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig"
32bc4a673fSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1
337059fa6fSAllan Judef_include $BSDCFG_SHARE/dialog.subr
34bc4a673fSDevin Teske
35f0c98fdeSDevin Teske############################################################ GLOBALS
362118f387SNathan Whitehorn
37f0c98fdeSDevin Teske#
38f0c98fdeSDevin Teske# Strings that should be moved to an i18n file and loaded with f_include_lang()
39f0c98fdeSDevin Teske#
407059fa6fSAllan Judehline_arrows_tab_enter="Press arrows, TAB or ENTER"
41f0c98fdeSDevin Teskehline_arrows_tab_space_enter="Press arrows, TAB, SPACE or ENTER"
42f0c98fdeSDevin Teskemsg_abort="Abort"
43595373ddSBen Woodsmsg_an_installation_step_has_been_aborted="An installation step has been aborted. Would you like\nto restart the installation or exit the installer?"
44595373ddSBen Woodsmsg_auto_ufs="Auto (UFS)"
45595373ddSBen Woodsmsg_auto_ufs_desc="Guided UFS Disk Setup"
46595373ddSBen Woodsmsg_auto_ufs_help="Menu options help choose which disk to setup using UFS and standard partitions"
47595373ddSBen Woodsmsg_auto_zfs="Auto (ZFS)"
48595373ddSBen Woodsmsg_auto_zfs_desc="Guided Root-on-ZFS"
49595373ddSBen Woodsmsg_auto_zfs_help="To use ZFS with less than 8GB RAM, see https://wiki.freebsd.org/ZFSTuningGuide"
50f0c98fdeSDevin Teskemsg_exit="Exit"
51cc42ef53SBrad Davismsg_freebsd_installer="$OSNAME Installer"
52a7d5d8d9SAllan 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?"
537059fa6fSAllan 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?"
54595373ddSBen Woodsmsg_manual="Manual"
55595373ddSBen Woodsmsg_manual_desc="Manual Disk Setup (experts)"
56595373ddSBen Woodsmsg_manual_help="Create customized partitions from menu options"
577059fa6fSAllan Judemsg_no="NO"
58f0c98fdeSDevin Teskemsg_restart="Restart"
59595373ddSBen Woodsmsg_shell="Shell"
60595373ddSBen Woodsmsg_shell_desc="Open a shell and partition by hand"
61595373ddSBen Woodsmsg_shell_help="Create customized partitions using command-line utilities"
627059fa6fSAllan Judemsg_yes="YES"
637059fa6fSAllan Jude
64f0c98fdeSDevin Teske############################################################ FUNCTIONS
65f0c98fdeSDevin Teske
66f0c98fdeSDevin Teske# error [$msg]
67f0c98fdeSDevin Teske#
68f0c98fdeSDevin Teske# Display generic error message when a script fails. An optional message
69f0c98fdeSDevin Teske# argument can preceed the generic message. User is given the choice of
70f0c98fdeSDevin Teske# restarting the installer or exiting.
71f0c98fdeSDevin Teske#
72f0c98fdeSDevin Teskeerror()
73f0c98fdeSDevin Teske{
74f0c98fdeSDevin Teske	local title="$msg_abort"
75f0c98fdeSDevin Teske	local btitle="$msg_freebsd_installer"
76f0c98fdeSDevin Teske	local prompt="${1:+$1\n\n}$msg_an_installation_step_has_been_aborted"
77f0c98fdeSDevin Teske	local hline="$hline_arrows_tab_space_enter"
78f0c98fdeSDevin Teske
79f0c98fdeSDevin Teske	[ -f "$PATH_FSTAB" ] && bsdinstall umount
80f0c98fdeSDevin Teske
81f0c98fdeSDevin Teske	local height width
82f0c98fdeSDevin Teske	f_dialog_buttonbox_size height width \
83f0c98fdeSDevin Teske		"$title" "$btitle" "$prompt" "$hline"
84f0c98fdeSDevin Teske
85f0c98fdeSDevin Teske	if $DIALOG \
86f0c98fdeSDevin Teske		--title "$title"           \
87f0c98fdeSDevin Teske		--backtitle "$btitle"      \
88f0c98fdeSDevin Teske		--hline "$hline"           \
89f0c98fdeSDevin Teske		--no-label "$msg_exit"     \
90f0c98fdeSDevin Teske		--yes-label "$msg_restart" \
91f0c98fdeSDevin Teske		--yesno "$prompt" $height $width
92f0c98fdeSDevin Teske	then
93f0c98fdeSDevin Teske		exec $0
94f0c98fdeSDevin Teske		# NOTREACHED
95f0c98fdeSDevin Teske	fi
96f0c98fdeSDevin Teske	exit 1
97f0c98fdeSDevin Teske}
98f0c98fdeSDevin Teske
997059fa6fSAllan Jude# dialog_workaround
1007059fa6fSAllan Jude#
1017059fa6fSAllan Jude# Ask the user if they wish to apply a workaround
1027059fa6fSAllan Jude#
1037059fa6fSAllan Judedialog_workaround()
1047059fa6fSAllan Jude{
1057059fa6fSAllan Jude	local passed_msg="$1"
1067059fa6fSAllan Jude	local title="$DIALOG_TITLE"
1077059fa6fSAllan Jude	local btitle="$DIALOG_BACKTITLE"
1087059fa6fSAllan Jude	local prompt # Calculated below
1097059fa6fSAllan Jude	local hline="$hline_arrows_tab_enter"
1107059fa6fSAllan Jude
1117059fa6fSAllan Jude	local height=8 width=50 prefix="   "
1127059fa6fSAllan Jude	local plen=${#prefix} list= line=
1137059fa6fSAllan Jude	local max_width=$(( $width - 3 - $plen ))
1147059fa6fSAllan Jude
1157059fa6fSAllan Jude	local yes no defaultno extra_args format
1167059fa6fSAllan Jude	if [ "$USE_XDIALOG" ]; then
1177059fa6fSAllan Jude		yes=ok no=cancel defaultno=default-no
1187059fa6fSAllan Jude		extra_args="--wrap --left"
1197059fa6fSAllan Jude		format="$passed_msg"
1207059fa6fSAllan Jude	else
1217059fa6fSAllan Jude		yes=yes no=no defaultno=defaultno
1227059fa6fSAllan Jude		extra_args="--cr-wrap"
1237059fa6fSAllan Jude		format="$passed_msg"
1247059fa6fSAllan Jude	fi
1257059fa6fSAllan Jude
1267059fa6fSAllan Jude	# Add height for Xdialog(1)
1277059fa6fSAllan Jude	[ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 ))
1287059fa6fSAllan Jude
1297059fa6fSAllan Jude	prompt=$( printf "$format" )
1307059fa6fSAllan Jude	f_dprintf "%s: Workaround prompt" "$0"
1317059fa6fSAllan Jude	$DIALOG \
1327059fa6fSAllan Jude		--title "$title"        \
1337059fa6fSAllan Jude		--backtitle "$btitle"   \
1347059fa6fSAllan Jude		--hline "$hline"        \
1357059fa6fSAllan Jude		--$yes-label "$msg_yes" \
1367059fa6fSAllan Jude		--$no-label "$msg_no"   \
1377059fa6fSAllan Jude		$extra_args             \
1387059fa6fSAllan Jude		--yesno "$prompt" $height $width
1397059fa6fSAllan Jude}
1407059fa6fSAllan Jude
141bc4a673fSDevin Teske############################################################ MAIN
142bc4a673fSDevin Teske
143bc4a673fSDevin Teskef_dprintf "Began Installation at %s" "$( date )"
1442118f387SNathan Whitehorn
1452118f387SNathan Whitehornrm -rf $BSDINSTALL_TMPETC
1462118f387SNathan Whitehornmkdir $BSDINSTALL_TMPETC
1472118f387SNathan Whitehorn
14803d66186SBrad Davis[ -f /usr/libexec/bsdinstall/local.pre-everything ] && f_dprintf "Running local.pre-everything" && sh /usr/libexec/bsdinstall/local.pre-everything "$BSDINSTALL_CHROOT"
14903d66186SBrad Davis
1502118f387SNathan Whitehorntrap true SIGINT	# This section is optional
15117f4ded5SBrad Davis[ -z "$BSDINSTALL_SKIP_KEYMAP" ] && bsdinstall keymap
1522118f387SNathan Whitehorn
1532118f387SNathan Whitehorntrap error SIGINT	# Catch cntrl-C here
15417f4ded5SBrad Davisif [ -z "$BSDINSTALL_SKIP_HOSTNAME" ]; then bsdinstall hostname || error "Set hostname failed"; fi
1552118f387SNathan Whitehorn
156*34b43f4bSIsaac Freundbsddialog --backtitle "$OSNAME Installer" --title "Select Installation Type" \
157*34b43f4bSIsaac Freund	--yes-label "Traditional" --no-label "Packages (Experimental)" --yesno \
158*34b43f4bSIsaac Freund	"Would you like to install the base system using traditional distribution sets or packages (experimental)?" 0 0
159*34b43f4bSIsaac Freundif [ $? -eq 1 ]; then
160*34b43f4bSIsaac Freund	PKGBASE=yes
161*34b43f4bSIsaac Freundfi
162*34b43f4bSIsaac Freund
163*34b43f4bSIsaac Freundif [ "$PKGBASE" == yes ]; then
164*34b43f4bSIsaac Freund	bsddialog --backtitle "$OSNAME Installer" --title "Network Installation" \
165*34b43f4bSIsaac Freund	    --msgbox "Installation of base system packages currently requires internet access. The next few screens will allow you to configure networking." 0 0
166*34b43f4bSIsaac Freund	bsdinstall netconfig || error
167*34b43f4bSIsaac Freund	NETCONFIG_DONE=yes
168*34b43f4bSIsaac Freundelse
1697143521fSJessica Clarke	export DISTRIBUTIONS="${DISTRIBUTIONS:-base.txz kernel.txz}"
1707143521fSJessica Clarke	if [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
1717143521fSJessica Clarke		DISTMENU=`awk -F'\t' '!/^(kernel\.txz|base\.txz)/{print $1,$5,$6}' $BSDINSTALL_DISTDIR/MANIFEST`
1727143521fSJessica Clarke		DISTMENU="$(echo ${DISTMENU} | sed -E 's/\.txz//g')"
1737143521fSJessica Clarke
1747143521fSJessica Clarke		if [ -n "$DISTMENU" ]; then
175c0e249d3SLars Kellogg-Stedman			exec 5>&1
1767143521fSJessica Clarke			EXTRA_DISTS=$( eval bsddialog \
1777143521fSJessica Clarke			    --backtitle \"$OSNAME Installer\" \
1787143521fSJessica Clarke			    --title \"Distribution Select\" --nocancel --separate-output \
1797143521fSJessica Clarke			    --checklist \"Choose optional system components to install:\" \
1807143521fSJessica Clarke			    0 0 0 $DISTMENU \
1817143521fSJessica Clarke			2>&1 1>&5 )
1827143521fSJessica Clarke			for dist in $EXTRA_DISTS; do
1837143521fSJessica Clarke				export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
1847143521fSJessica Clarke			done
1857143521fSJessica Clarke		fi
1867143521fSJessica Clarke	fi
1877143521fSJessica Clarke
1887143521fSJessica Clarke	FETCH_DISTRIBUTIONS=""
1897143521fSJessica Clarke	for dist in $DISTRIBUTIONS; do
1907143521fSJessica Clarke		if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
1917143521fSJessica Clarke			FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
1927143521fSJessica Clarke		fi
1937143521fSJessica Clarke	done
1947143521fSJessica Clarke
1957143521fSJessica Clarke	if [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then
1967143521fSJessica Clarke		bsddialog --backtitle "$OSNAME 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
1977143521fSJessica Clarke		bsdinstall netconfig || error
1987143521fSJessica Clarke		NETCONFIG_DONE=yes
1992118f387SNathan Whitehorn	fi
200*34b43f4bSIsaac Freundfi
2012118f387SNathan Whitehorn
2022d5cf580SDevin Teskerm -f $PATH_FSTAB
2032118f387SNathan Whitehorntouch $PATH_FSTAB
2042118f387SNathan Whitehorn
20503d66186SBrad Davis[ -f /usr/libexec/bsdinstall/local.pre-partition ] && f_dprintf "Running local.pre-partition" && sh /usr/libexec/bsdinstall/local.pre-partition "$BSDINSTALL_CHROOT"
20603d66186SBrad Davis
2077059fa6fSAllan Jude#
2087059fa6fSAllan Jude# Try to detect known broken platforms and apply their workarounds
2097059fa6fSAllan Jude#
2107059fa6fSAllan Jude
2117059fa6fSAllan Judeif f_interactive; then
2127059fa6fSAllan Jude	sys_maker=$( kenv -q smbios.system.maker )
2137059fa6fSAllan Jude	f_dprintf "smbios.system.maker=[%s]" "$sys_maker"
2147059fa6fSAllan Jude	sys_model=$( kenv -q smbios.system.product )
2157059fa6fSAllan Jude	f_dprintf "smbios.system.product=[%s]" "$sys_model"
2167059fa6fSAllan Jude	sys_version=$( kenv -q smbios.system.version )
2177059fa6fSAllan Jude	f_dprintf "smbios.system.version=[%s]" "$sys_version"
218a7d5d8d9SAllan Jude	sys_mb_maker=$( kenv -q smbios.planar.maker )
219a7d5d8d9SAllan Jude	f_dprintf "smbios.planar.maker=[%s]" "$sys_mb_maker"
220a7d5d8d9SAllan Jude	sys_mb_product=$( kenv -q smbios.planar.product )
221a7d5d8d9SAllan Jude	f_dprintf "smbios.planar.product=[%s]" "$sys_mb_product"
222a7d5d8d9SAllan Jude
223a7d5d8d9SAllan Jude	#
224a7d5d8d9SAllan Jude	# Laptop Models
225a7d5d8d9SAllan Jude	#
2267059fa6fSAllan Jude	case "$sys_maker" in
2277059fa6fSAllan Jude	"LENOVO")
2287059fa6fSAllan Jude		case "$sys_version" in
229229c92e7SAllan Jude		"ThinkPad X220"|"ThinkPad T420"|"ThinkPad T520"|"ThinkPad W520"|"ThinkPad X1")
2307059fa6fSAllan Jude			dialog_workaround "$msg_lenovo_fix"
2317059fa6fSAllan Jude			retval=$?
2327059fa6fSAllan Jude			f_dprintf "lenovofix_prompt=[%s]" "$retval"
2337059fa6fSAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
2347059fa6fSAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix"
2357059fa6fSAllan Jude				export WORKAROUND_LENOVO=1
2367059fa6fSAllan Jude			fi
2377059fa6fSAllan Jude			;;
2387059fa6fSAllan Jude		esac
2397059fa6fSAllan Jude		;;
2407059fa6fSAllan Jude	"Dell Inc.")
2417059fa6fSAllan Jude		case "$sys_model" in
242e3026446SAllan Jude		"Latitude E6330"|"Latitude E7440"|"Latitude E7240"|"Precision Tower 5810")
243a7d5d8d9SAllan Jude			dialog_workaround "$msg_gpt_active_fix"
244a7d5d8d9SAllan Jude			retval=$?
245a7d5d8d9SAllan Jude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
246a7d5d8d9SAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
247a7d5d8d9SAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
248a7d5d8d9SAllan Jude				export WORKAROUND_GPTACTIVE=1
249a7d5d8d9SAllan Jude			fi
250a7d5d8d9SAllan Jude			;;
251a7d5d8d9SAllan Jude		esac
252a7d5d8d9SAllan Jude		;;
2534c95e76aSAllan Jude	"Hewlett-Packard")
2544c95e76aSAllan Jude		case "$sys_model" in
2554c95e76aSAllan Jude		"HP ProBook 4330s")
2564c95e76aSAllan Jude			dialog_workaround "$msg_gpt_active_fix"
2574c95e76aSAllan Jude			retval=$?
2584c95e76aSAllan Jude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
2594c95e76aSAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
2604c95e76aSAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
2614c95e76aSAllan Jude				export WORKAROUND_GPTACTIVE=1
2624c95e76aSAllan Jude			fi
2634c95e76aSAllan Jude			;;
2644c95e76aSAllan Jude		esac
2654c95e76aSAllan Jude		;;
266a7d5d8d9SAllan Jude	esac
267a7d5d8d9SAllan Jude	#
268a7d5d8d9SAllan Jude	# Motherboard Models
269a7d5d8d9SAllan Jude	#
270a7d5d8d9SAllan Jude	case "$sys_mb_maker" in
271a7d5d8d9SAllan Jude	"Intel Corporation")
272a7d5d8d9SAllan Jude		case "$sys_mb_product" in
2734c95e76aSAllan Jude		"DP965LT"|"D510MO")
2744c95e76aSAllan Jude			dialog_workaround "$msg_gpt_active_fix"
2754c95e76aSAllan Jude			retval=$?
2764c95e76aSAllan Jude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
2774c95e76aSAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
2784c95e76aSAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
2794c95e76aSAllan Jude				export WORKAROUND_GPTACTIVE=1
2804c95e76aSAllan Jude			fi
2814c95e76aSAllan Jude			;;
2824c95e76aSAllan Jude		esac
2834c95e76aSAllan Jude		;;
2844c95e76aSAllan Jude	"Acer")
2854c95e76aSAllan Jude		case "$sys_mb_product" in
2864c95e76aSAllan Jude		"Veriton M6630G")
2877059fa6fSAllan Jude			dialog_workaround "$msg_gpt_active_fix"
2887059fa6fSAllan Jude			retval=$?
2897059fa6fSAllan Jude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
2907059fa6fSAllan Jude			if [ $retval -eq $DIALOG_OK ]; then
2917059fa6fSAllan Jude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
2927059fa6fSAllan Jude				export WORKAROUND_GPTACTIVE=1
2937059fa6fSAllan Jude			fi
2947059fa6fSAllan Jude			;;
2957059fa6fSAllan Jude		esac
2967059fa6fSAllan Jude		;;
2977059fa6fSAllan Jude	esac
2987059fa6fSAllan Judefi
2997059fa6fSAllan Jude
300595373ddSBen WoodsPMODES="
301595373ddSBen Woods	'$msg_auto_ufs' '$msg_auto_ufs_desc' '$msg_auto_ufs_help'
302595373ddSBen Woods	'$msg_manual' '$msg_manual_desc' '$msg_manual_help'
303595373ddSBen Woods	'$msg_shell' '$msg_shell_desc' '$msg_shell_help'
304595373ddSBen Woods" # END-QUOTE
3052118f387SNathan Whitehorn
306cd88b886SDevin TeskeCURARCH=$( uname -m )
307cd88b886SDevin Teskecase $CURARCH in
3087b08a307SMitchell Horne	amd64|arm64|i386|riscv)	# Booting ZFS Supported
309595373ddSBen Woods		PMODES="
310595373ddSBen Woods			'$msg_auto_zfs' '$msg_auto_zfs_desc' '$msg_auto_zfs_help'
311595373ddSBen Woods			$PMODES
312595373ddSBen Woods		" # END-QUOTE
313cd88b886SDevin Teske		;;
314595373ddSBen Woods	*)			# Booting ZFS Unsupported
315cd88b886SDevin Teske		;;
316cd88b886SDevin Teskeesac
317cd88b886SDevin Teske
318c0e249d3SLars Kellogg-Stedmanexec 5>&1
31904b46577SAlfonso S. SicilianoPARTMODE=`echo $PMODES | xargs -o bsddialog --backtitle "$OSNAME Installer" \
320cd88b886SDevin Teske	--title "Partitioning" \
321595373ddSBen Woods	--item-help \
322cd88b886SDevin Teske	--menu "How would you like to partition your disk?" \
323c0e249d3SLars Kellogg-Stedman	0 0 0 2>&1 1>&5` || exit 1
324c0e249d3SLars Kellogg-Stedmanexec 5>&-
325cd88b886SDevin Teske
326cd88b886SDevin Teskecase "$PARTMODE" in
327595373ddSBen Woods"$msg_auto_zfs")	# ZFS
328d512033eSBen Woods	bsdinstall zfsboot || error "ZFS setup failed"
329d512033eSBen Woods	bsdinstall mount || error "Failed to mount filesystem"
330d512033eSBen Woods	;;
331595373ddSBen Woods"$msg_auto_ufs")	# Guided UFS
3327041a67eSAndrew Thompson	bsdinstall autopart || error "Partitioning error"
3337041a67eSAndrew Thompson	bsdinstall mount || error "Failed to mount filesystem"
3342118f387SNathan Whitehorn	;;
335595373ddSBen Woods"$msg_shell")		# Shell
3362118f387SNathan Whitehorn	clear
3372118f387SNathan 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'."
338809685bcSNathan Whitehorn	sh 2>&1
3392118f387SNathan Whitehorn	;;
340595373ddSBen Woods"$msg_manual")		# Manual
341bc4a673fSDevin Teske	if f_isset debugFile; then
342bc4a673fSDevin Teske		# Give partedit the path to our logfile so it can append
3437041a67eSAndrew Thompson		BSDINSTALL_LOG="${debugFile#+}" bsdinstall partedit || error "Partitioning error"
344bc4a673fSDevin Teske	else
3457041a67eSAndrew Thompson		bsdinstall partedit || error "Partitioning error"
346bc4a673fSDevin Teske	fi
3477041a67eSAndrew Thompson	bsdinstall mount || error "Failed to mount filesystem"
3482118f387SNathan Whitehorn	;;
3492118f387SNathan Whitehorn*)
3507041a67eSAndrew Thompson	error "Unknown partitioning mode"
3512118f387SNathan Whitehorn	;;
3522118f387SNathan Whitehornesac
3532118f387SNathan Whitehorn
35403d66186SBrad Davis[ -f /usr/libexec/bsdinstall/local.pre-fetch ] && f_dprintf "Running local.pre-fetch" && sh /usr/libexec/bsdinstall/local.pre-fetch "$BSDINSTALL_CHROOT"
35503d66186SBrad Davis
356*34b43f4bSIsaac Freundif [ "$PKGBASE" == yes ]; then
357*34b43f4bSIsaac Freund	bsdinstall pkgbase || error "Installation of base system packages failed"
358*34b43f4bSIsaac Freundelse
35940923b0cSNathan Whitehorn	if [ -n "$FETCH_DISTRIBUTIONS" ]; then
360c0e249d3SLars Kellogg-Stedman		exec 5>&1
361c0e249d3SLars Kellogg-Stedman		export BSDINSTALL_DISTDIR=$(`dirname $0`/fetchmissingdists 2>&1 1>&5)
36240923b0cSNathan Whitehorn		FETCH_RESULT=$?
363c0e249d3SLars Kellogg-Stedman		exec 5>&-
3642118f387SNathan Whitehorn
36540923b0cSNathan Whitehorn		[ $FETCH_RESULT -ne 0 ] && error "Could not fetch remote distributions"
3662118f387SNathan Whitehorn	fi
3677041a67eSAndrew Thompson	bsdinstall checksum || error "Distribution checksum failed"
3687041a67eSAndrew Thompson	bsdinstall distextract || error "Distribution extract failed"
369*34b43f4bSIsaac Freundfi
3708befcf7bSNathan Whitehorn
3718befcf7bSNathan Whitehorn# Set up boot loader
3728befcf7bSNathan Whitehornbsdinstall bootconfig || error "Failed to configure bootloader"
3738befcf7bSNathan Whitehorn
37403d66186SBrad Davis[ -f /usr/libexec/bsdinstall/local.pre-configure ] && f_dprintf "Running local.pre-configure" && sh /usr/libexec/bsdinstall/local.pre-configure "$BSDINSTALL_CHROOT"
37503d66186SBrad Davis
3767041a67eSAndrew Thompsonbsdinstall rootpass || error "Could not set root password"
3772118f387SNathan Whitehorn
3782118f387SNathan Whitehorntrap true SIGINT	# This section is optional
3792118f387SNathan Whitehornif [ "$NETCONFIG_DONE" != yes ]; then
3802118f387SNathan Whitehorn	bsdinstall netconfig	# Don't check for errors -- the user may cancel
3812118f387SNathan Whitehornfi
38217f4ded5SBrad Davis[ -z "$BSDINSTALL_SKIP_TIME" ] && bsdinstall time
38317f4ded5SBrad Davis[ -z "$BSDINSTALL_SKIP_SERVICES" ] && bsdinstall services
38417f4ded5SBrad Davis[ -z "$BSDINSTALL_SKIP_HARDENING" ] && bsdinstall hardening
385bbe2a1daSBjoern A. Zeeb[ -z "$BSDINSTALL_SKIP_FIRMWARE" ] && bsdinstall firmware
3862118f387SNathan Whitehorn
38704b46577SAlfonso S. Siciliano[ -z "$BSDINSTALL_SKIP_USERS" ] && bsddialog --backtitle "$OSNAME Installer" \
38817f4ded5SBrad Davis	--title "Add User Accounts" --yesno \
3892118f387SNathan Whitehorn    "Would you like to add users to the installed system now?" 0 0 && \
3902118f387SNathan Whitehorn    bsdinstall adduser
3912118f387SNathan Whitehorn
3922118f387SNathan Whitehorn# Allow user to change his mind
393a6d20207SPierre Pronchery[ -z "$BSDINSTALL_SKIP_FINALCONFIG" ] && bsdinstall finalconfig
3942118f387SNathan Whitehorn
3952118f387SNathan Whitehorntrap error SIGINT	# SIGINT is bad again
3967041a67eSAndrew Thompsonbsdinstall config  || error "Failed to save config"
3972118f387SNathan Whitehorn
3982118f387SNathan Whitehornif [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
3992118f387SNathan Whitehorn	rm -rf "$BSDINSTALL_FETCHDEST"
4002118f387SNathan Whitehornfi
4012118f387SNathan Whitehorn
40203d66186SBrad Davis[ -f /usr/libexec/bsdinstall/local.post-configure ] && f_dprintf "Running local.post-configure" && sh /usr/libexec/bsdinstall/local.post-configure "$BSDINSTALL_CHROOT"
40303d66186SBrad Davis
40417f4ded5SBrad Davisif [ -z "$BSDINSTALL_SKIP_MANUAL" ]; then
40504b46577SAlfonso S. Siciliano	bsddialog --backtitle "$OSNAME Installer" --title "Manual Configuration" \
40604b46577SAlfonso S. Siciliano		--default-no --yesno \
40744a25dd6SNathan 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
4086081c922SNathan Whitehorn	if [ $? -eq 0 ]; then
4096081c922SNathan Whitehorn		clear
4106081c922SNathan Whitehorn		echo This shell is operating in a chroot in the new system. \
4116081c922SNathan Whitehorn		    When finished making configuration changes, type \"exit\".
4126081c922SNathan Whitehorn		chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1
4136081c922SNathan Whitehorn	fi
41417f4ded5SBrad Davisfi
4156081c922SNathan Whitehorn
416dfc23ba5SDag-Erling Smørgravbsdinstall entropy
417dfc23ba5SDag-Erling Smørgravbsdinstall umount
418dfc23ba5SDag-Erling Smørgrav
419bc4a673fSDevin Teskef_dprintf "Installation Completed at %s" "$( date )"
4202118f387SNathan Whitehorn
421bc4a673fSDevin Teske################################################################################
422bc4a673fSDevin Teske# END
423bc4a673fSDevin Teske################################################################################
424