1218799Snwhitehorn#!/bin/sh
2218799Snwhitehorn#-
3218799Snwhitehorn# Copyright (c) 2011 Nathan Whitehorn
4257842Sdteske# Copyright (c) 2013 Devin Teske
5218799Snwhitehorn# All rights reserved.
6218799Snwhitehorn#
7218799Snwhitehorn# Redistribution and use in source and binary forms, with or without
8218799Snwhitehorn# modification, are permitted provided that the following conditions
9218799Snwhitehorn# are met:
10218799Snwhitehorn# 1. Redistributions of source code must retain the above copyright
11218799Snwhitehorn#    notice, this list of conditions and the following disclaimer.
12218799Snwhitehorn# 2. Redistributions in binary form must reproduce the above copyright
13218799Snwhitehorn#    notice, this list of conditions and the following disclaimer in the
14218799Snwhitehorn#    documentation and/or other materials provided with the distribution.
15218799Snwhitehorn#
16218799Snwhitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17218799Snwhitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18218799Snwhitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19218799Snwhitehorn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20218799Snwhitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21218799Snwhitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22218799Snwhitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23218799Snwhitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24218799Snwhitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25218799Snwhitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26218799Snwhitehorn# SUCH DAMAGE.
27218799Snwhitehorn#
28218799Snwhitehorn# $FreeBSD: stable/11/usr.sbin/bsdinstall/scripts/auto 370209 2021-07-27 20:15:40Z gjb $
29257842Sdteske#
30257842Sdteske############################################################ INCLUDES
31218799Snwhitehorn
32257842SdteskeBSDCFG_SHARE="/usr/share/bsdconfig"
33257842Sdteske. $BSDCFG_SHARE/common.subr || exit 1
34285679Sallanjudef_include $BSDCFG_SHARE/dialog.subr
35218799Snwhitehorn
36257842Sdteske############################################################ FUNCTIONS
37257842Sdteske
38218799Snwhitehornerror() {
39269653Sthompsa	local msg
40269653Sthompsa	if [ -n "$1" ]; then
41269653Sthompsa		msg="$1\n\n"
42269653Sthompsa	fi
43220088Snwhitehorn	test -n "$DISTDIR_IS_UNIONFS" && umount -f $BSDINSTALL_DISTDIR
44220088Snwhitehorn	test -f $PATH_FSTAB && bsdinstall umount
45218799Snwhitehorn	dialog --backtitle "FreeBSD Installer" --title "Abort" \
46218799Snwhitehorn	    --no-label "Exit" --yes-label "Restart" --yesno \
47269653Sthompsa	    "${msg}An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
48218799Snwhitehorn	if [ $? -ne 0 ]; then
49225637Snwhitehorn		exit 1
50218799Snwhitehorn	else
51218799Snwhitehorn		exec $0
52218799Snwhitehorn	fi
53218799Snwhitehorn}
54218799Snwhitehorn
55285679Sallanjudehline_arrows_tab_enter="Press arrows, TAB or ENTER"
56285732Sallanjudemsg_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?"
57285679Sallanjudemsg_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?"
58285679Sallanjudemsg_no="NO"
59285679Sallanjudemsg_yes="YES"
60285679Sallanjude
61285679Sallanjude# dialog_workaround
62285679Sallanjude#
63285679Sallanjude# Ask the user if they wish to apply a workaround
64285679Sallanjude#
65285679Sallanjudedialog_workaround()
66285679Sallanjude{
67285679Sallanjude	local passed_msg="$1"
68285679Sallanjude	local title="$DIALOG_TITLE"
69285679Sallanjude	local btitle="$DIALOG_BACKTITLE"
70285679Sallanjude	local prompt # Calculated below
71285679Sallanjude	local hline="$hline_arrows_tab_enter"
72285679Sallanjude
73285679Sallanjude	local height=8 width=50 prefix="   "
74285679Sallanjude	local plen=${#prefix} list= line=
75285679Sallanjude	local max_width=$(( $width - 3 - $plen ))
76285679Sallanjude
77285679Sallanjude	local yes no defaultno extra_args format
78285679Sallanjude	if [ "$USE_XDIALOG" ]; then
79285679Sallanjude		yes=ok no=cancel defaultno=default-no
80285679Sallanjude		extra_args="--wrap --left"
81285679Sallanjude		format="$passed_msg"
82285679Sallanjude	else
83285679Sallanjude		yes=yes no=no defaultno=defaultno
84285679Sallanjude		extra_args="--cr-wrap"
85285679Sallanjude		format="$passed_msg"
86285679Sallanjude	fi
87285679Sallanjude
88285679Sallanjude	# Add height for Xdialog(1)
89285679Sallanjude	[ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 ))
90285679Sallanjude
91285679Sallanjude	prompt=$( printf "$format" )
92285679Sallanjude	f_dprintf "%s: Workaround prompt" "$0"
93285679Sallanjude	$DIALOG \
94285679Sallanjude		--title "$title"        \
95285679Sallanjude		--backtitle "$btitle"   \
96285679Sallanjude		--hline "$hline"        \
97285679Sallanjude		--$yes-label "$msg_yes" \
98285679Sallanjude		--$no-label "$msg_no"   \
99285679Sallanjude		$extra_args             \
100285679Sallanjude		--yesno "$prompt" $height $width
101285679Sallanjude}
102285679Sallanjude
103257842Sdteske############################################################ MAIN
104218799Snwhitehorn
105257842Sdteskef_dprintf "Began Installation at %s" "$( date )"
106257842Sdteske
107218799Snwhitehornrm -rf $BSDINSTALL_TMPETC
108218799Snwhitehornmkdir $BSDINSTALL_TMPETC
109218799Snwhitehorn
110218799Snwhitehorntrap true SIGINT	# This section is optional
111218799Snwhitehornbsdinstall keymap
112218799Snwhitehorn
113218799Snwhitehorntrap error SIGINT	# Catch cntrl-C here
114269653Sthompsabsdinstall hostname || error "Set hostname failed"
115218799Snwhitehorn
116219615Snwhitehornexport DISTRIBUTIONS="base.txz kernel.txz"
117219615Snwhitehornif [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
118293223Sgjb	DISTMENU=`awk -F'\t' '!/^(kernel\.txz|base\.txz)/{print $1,$5,$6}' $BSDINSTALL_DISTDIR/MANIFEST`
119293223Sgjb	DISTMENU="$(echo ${DISTMENU} | sed -E 's/\.txz//g')"
120218947Snwhitehorn
121370209Sgjb	if [ -n "$DISTMENU" ]; then
122370209Sgjb		exec 3>&1
123370209Sgjb		EXTRA_DISTS=$( eval dialog \
124370209Sgjb		    --backtitle \"FreeBSD Installer\" \
125370209Sgjb		    --title \"Distribution Select\" --nocancel --separate-output \
126370209Sgjb		    --checklist \"Choose optional system components to install:\" \
127370209Sgjb		    0 0 0 $DISTMENU \
128370209Sgjb		2>&1 1>&3 )
129370209Sgjb		for dist in $EXTRA_DISTS; do
130370209Sgjb			export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
131370209Sgjb		done
132370209Sgjb	fi
133219615Snwhitehornfi
134218947Snwhitehorn
135293223SgjbLOCAL_DISTRIBUTIONS="MANIFEST"
136218799SnwhitehornFETCH_DISTRIBUTIONS=""
137218799Snwhitehornfor dist in $DISTRIBUTIONS; do
138218799Snwhitehorn	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
139218799Snwhitehorn		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
140293223Sgjb	else
141293223Sgjb		LOCAL_DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS $dist"
142218799Snwhitehorn	fi
143218799Snwhitehorndone
144293223SgjbLOCAL_DISTRIBUTIONS=`echo $LOCAL_DISTRIBUTIONS`	# Trim white space
145220080SnwhitehornFETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS`	# Trim white space
146218799Snwhitehorn
147220080Snwhitehornif [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then
148293223Sgjb	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
149218799Snwhitehorn	bsdinstall netconfig || error
150218799Snwhitehorn	NETCONFIG_DONE=yes
151218799Snwhitehornfi
152218799Snwhitehorn
153220088Snwhitehornif [ -n "$FETCH_DISTRIBUTIONS" ]; then
154220080Snwhitehorn	exec 3>&1
155220834Snwhitehorn	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
156220080Snwhitehorn	MIRROR_BUTTON=$?
157220080Snwhitehorn	exec 3>&-
158269653Sthompsa	test $MIRROR_BUTTON -eq 0 || error "No mirror selected"
159220080Snwhitehorn	export BSDINSTALL_DISTSITE
160220080Snwhitehornfi
161220080Snwhitehorn
162259572Sdteskerm -f $PATH_FSTAB
163218799Snwhitehorntouch $PATH_FSTAB
164218799Snwhitehorn
165285679Sallanjude#
166285679Sallanjude# Try to detect known broken platforms and apply their workarounds
167285679Sallanjude#
168285679Sallanjude
169285679Sallanjudeif f_interactive; then
170285679Sallanjude	sys_maker=$( kenv -q smbios.system.maker )
171285679Sallanjude	f_dprintf "smbios.system.maker=[%s]" "$sys_maker"
172285679Sallanjude	sys_model=$( kenv -q smbios.system.product )
173285679Sallanjude	f_dprintf "smbios.system.product=[%s]" "$sys_model"
174285679Sallanjude	sys_version=$( kenv -q smbios.system.version )
175285679Sallanjude	f_dprintf "smbios.system.version=[%s]" "$sys_version"
176285732Sallanjude	sys_mb_maker=$( kenv -q smbios.planar.maker )
177285732Sallanjude	f_dprintf "smbios.planar.maker=[%s]" "$sys_mb_maker"
178285732Sallanjude	sys_mb_product=$( kenv -q smbios.planar.product )
179285732Sallanjude	f_dprintf "smbios.planar.product=[%s]" "$sys_mb_product"
180285732Sallanjude
181285732Sallanjude	#
182285732Sallanjude	# Laptop Models
183285732Sallanjude	#
184285679Sallanjude	case "$sys_maker" in
185285679Sallanjude	"LENOVO")
186285679Sallanjude		case "$sys_version" in
187331088Seadler		"ThinkPad X220"|"ThinkPad T420"|"ThinkPad T520"|"ThinkPad W520"|"ThinkPad X1")
188285679Sallanjude			dialog_workaround "$msg_lenovo_fix"
189285679Sallanjude			retval=$?
190285679Sallanjude			f_dprintf "lenovofix_prompt=[%s]" "$retval"
191285679Sallanjude			if [ $retval -eq $DIALOG_OK ]; then
192285679Sallanjude				export ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix"
193285679Sallanjude				export WORKAROUND_LENOVO=1
194285679Sallanjude			fi
195285679Sallanjude			;;
196285679Sallanjude		esac
197285679Sallanjude		;;
198285679Sallanjude	"Dell Inc.")
199285679Sallanjude		case "$sys_model" in
200302320Sallanjude		"Latitude E6330"|"Latitude E7440"|"Latitude E7240"|"Precision Tower 5810")
201285679Sallanjude			dialog_workaround "$msg_gpt_active_fix"
202285679Sallanjude			retval=$?
203285679Sallanjude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
204285679Sallanjude			if [ $retval -eq $DIALOG_OK ]; then
205285679Sallanjude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
206285679Sallanjude				export WORKAROUND_GPTACTIVE=1
207285679Sallanjude			fi
208285679Sallanjude			;;
209285679Sallanjude		esac
210285679Sallanjude		;;
211287843Sallanjude	"Hewlett-Packard")
212287843Sallanjude		case "$sys_model" in
213287843Sallanjude		"HP ProBook 4330s")
214287843Sallanjude			dialog_workaround "$msg_gpt_active_fix"
215287843Sallanjude			retval=$?
216287843Sallanjude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
217287843Sallanjude			if [ $retval -eq $DIALOG_OK ]; then
218287843Sallanjude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
219287843Sallanjude				export WORKAROUND_GPTACTIVE=1
220287843Sallanjude			fi
221287843Sallanjude			;;
222287843Sallanjude		esac
223287843Sallanjude		;;
224285679Sallanjude	esac
225285732Sallanjude	#
226285732Sallanjude	# Motherboard Models
227285732Sallanjude	#
228285732Sallanjude	case "$sys_mb_maker" in
229285732Sallanjude	"Intel Corporation")
230285732Sallanjude		case "$sys_mb_product" in
231287843Sallanjude		"DP965LT"|"D510MO")
232285732Sallanjude			dialog_workaround "$msg_gpt_active_fix"
233285732Sallanjude			retval=$?
234285732Sallanjude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
235285732Sallanjude			if [ $retval -eq $DIALOG_OK ]; then
236285732Sallanjude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
237285732Sallanjude				export WORKAROUND_GPTACTIVE=1
238285732Sallanjude			fi
239285732Sallanjude			;;
240285732Sallanjude		esac
241285732Sallanjude		;;
242287843Sallanjude	"Acer")
243287843Sallanjude		case "$sys_mb_product" in
244287843Sallanjude		"Veriton M6630G")
245287843Sallanjude			dialog_workaround "$msg_gpt_active_fix"
246287843Sallanjude			retval=$?
247287843Sallanjude			f_dprintf "gpt_active_fix_prompt=[%s]" "$retval"
248287843Sallanjude			if [ $retval -eq $DIALOG_OK ]; then
249287843Sallanjude				export ZFSBOOT_PARTITION_SCHEME="GPT + Active"
250287843Sallanjude				export WORKAROUND_GPTACTIVE=1
251287843Sallanjude			fi
252287843Sallanjude			;;
253287843Sallanjude		esac
254287843Sallanjude		;;
255285732Sallanjude	esac
256285679Sallanjudefi
257285679Sallanjude
258256343SdteskePMODES="\
259271553Snwhitehorn\"Auto (UFS)\" \"Guided Disk Setup\" \
260271553SnwhitehornManual \"Manual Disk Setup (experts)\" \
261256343SdteskeShell \"Open a shell and partition by hand\""
262218799Snwhitehorn
263256343SdteskeCURARCH=$( uname -m )
264256343Sdteskecase $CURARCH in
265319983Sallanjude	amd64|arm64|i386)	# Booting ZFS Supported
266271567Snwhitehorn		PMODES="$PMODES \"Auto (ZFS)\" \"Guided Root-on-ZFS\""
267256343Sdteske		;;
268256343Sdteske	*)		# Booting ZFS Unspported
269256343Sdteske		;;
270256343Sdteskeesac
271256343Sdteske
272256343Sdteskeexec 3>&1
273256343SdteskePARTMODE=`echo $PMODES | xargs dialog --backtitle "FreeBSD Installer" \
274256343Sdteske	--title "Partitioning" \
275256343Sdteske	--menu "How would you like to partition your disk?" \
276259570Sdteske	0 0 0 2>&1 1>&3` || exit 1
277256343Sdteskeexec 3>&-
278256343Sdteske
279256343Sdteskecase "$PARTMODE" in
280271553Snwhitehorn"Auto (UFS)")	# Guided
281269653Sthompsa	bsdinstall autopart || error "Partitioning error"
282269653Sthompsa	bsdinstall mount || error "Failed to mount filesystem"
283218799Snwhitehorn	;;
284256343Sdteske"Shell")	# Shell
285218799Snwhitehorn	clear
286218799Snwhitehorn	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'."
287222425Snwhitehorn	sh 2>&1
288218799Snwhitehorn	;;
289256343Sdteske"Manual")	# Manual
290257842Sdteske	if f_isset debugFile; then
291257842Sdteske		# Give partedit the path to our logfile so it can append
292269653Sthompsa		BSDINSTALL_LOG="${debugFile#+}" bsdinstall partedit || error "Partitioning error"
293257842Sdteske	else
294269653Sthompsa		bsdinstall partedit || error "Partitioning error"
295257842Sdteske	fi
296269653Sthompsa	bsdinstall mount || error "Failed to mount filesystem"
297218799Snwhitehorn	;;
298271553Snwhitehorn"Auto (ZFS)")	# ZFS
299269653Sthompsa	bsdinstall zfsboot || error "ZFS setup failed"
300269653Sthompsa	bsdinstall mount || error "Failed to mount filesystem"
301256343Sdteske	;;
302218799Snwhitehorn*)
303269653Sthompsa	error "Unknown partitioning mode"
304218799Snwhitehorn	;;
305218799Snwhitehornesac
306218799Snwhitehorn
307218799Snwhitehornif [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
308218799Snwhitehorn	ALL_DISTRIBUTIONS="$DISTRIBUTIONS"
309293223Sgjb	WANT_DEBUG=
310218799Snwhitehorn
311218799Snwhitehorn	# Download to a directory in the new system as scratch space
312219528Snwhitehorn	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
313269653Sthompsa	mkdir -p "$BSDINSTALL_FETCHDEST" || error "Could not create directory $BSDINSTALL_FETCHDEST"
314218799Snwhitehorn
315218799Snwhitehorn	export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
316218799Snwhitehorn	# Try to use any existing distfiles
317220088Snwhitehorn	if [ -d $BSDINSTALL_DISTDIR ]; then
318220080Snwhitehorn		DISTDIR_IS_UNIONFS=1
319223897Snwhitehorn		mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
320225637Snwhitehorn	else
321293223Sgjb		export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
322218799Snwhitehorn		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
323218799Snwhitehorn	fi
324218799Snwhitehorn		
325225637Snwhitehorn	export FTP_PASSIVE_MODE=YES
326293223Sgjb	# Iterate through the distribution list and set a flag if debugging
327293223Sgjb	# distributions have been selected.
328293223Sgjb	for _DISTRIBUTION in $DISTRIBUTIONS; do
329293223Sgjb		case $_DISTRIBUTION in
330293223Sgjb			*-dbg.*)
331293223Sgjb				[ -e $BSDINSTALL_DISTDIR/$_DISTRIBUTION ] \
332293223Sgjb					&& continue
333293223Sgjb				WANT_DEBUG=1
334293223Sgjb				DEBUG_LIST="\n$DEBUG_LIST\n$_DISTRIBUTION"
335293223Sgjb				;;
336293223Sgjb			*)
337293223Sgjb				;;
338293223Sgjb		esac
339293223Sgjb	done
340293223Sgjb
341293223Sgjb	# Fetch the distributions.
342293223Sgjb	bsdinstall distfetch
343293223Sgjb	rc=$?
344293223Sgjb
345293223Sgjb	if [ $rc -ne 0 ]; then
346293223Sgjb		# If unable to fetch the remote distributions, recommend
347293223Sgjb		# deselecting the debugging distributions, and retrying the
348293223Sgjb		# installation, since failure to fetch *-dbg.txz should not
349293223Sgjb		# be considered a fatal installation error.
350293223Sgjb		msg="Failed to fetch remote distribution"
351293223Sgjb		if [ ! -z "$WANT_DEBUG" ]; then
352293223Sgjb			# Trim leading and trailing newlines.
353293223Sgjb			DEBUG_LIST="${DEBUG_LIST%%\n}"
354293223Sgjb			DEBUG_LIST="${DEBUG_LIST##\n}"
355293223Sgjb			msg="$msg\n\nPlease deselect the following distributions"
356293223Sgjb			msg="$msg and retry the installation:"
357293223Sgjb			msg="$msg\n$DEBUG_LIST"
358293223Sgjb		fi
359293223Sgjb		error "$msg"
360293223Sgjb	fi
361218799Snwhitehorn	export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
362218799Snwhitehornfi
363218799Snwhitehorn
364293223Sgjbif [ ! -z "$LOCAL_DISTRIBUTIONS" ]; then
365293223Sgjb	# Download to a directory in the new system as scratch space
366293223Sgjb	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
367293223Sgjb	mkdir -p "$BSDINSTALL_FETCHDEST" || error "Could not create directory $BSDINSTALL_FETCHDEST"
368293223Sgjb	# Try to use any existing distfiles
369293223Sgjb	if [ -d $BSDINSTALL_DISTDIR ]; then
370293223Sgjb		DISTDIR_IS_UNIONFS=1
371293223Sgjb		mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
372293223Sgjb		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
373293223Sgjb	fi
374293223Sgjb	env DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS" \
375293223Sgjb		BSDINSTALL_DISTSITE="file:///usr/freebsd-dist" \
376293223Sgjb		bsdinstall distfetch || \
377293223Sgjb		error "Failed to fetch distribution from local media"
378293223Sgjbfi
379293223Sgjb
380269653Sthompsabsdinstall checksum || error "Distribution checksum failed"
381269653Sthompsabsdinstall distextract || error "Distribution extract failed"
382269653Sthompsabsdinstall rootpass || error "Could not set root password"
383218799Snwhitehorn
384218799Snwhitehorntrap true SIGINT	# This section is optional
385218799Snwhitehornif [ "$NETCONFIG_DONE" != yes ]; then
386218799Snwhitehorn	bsdinstall netconfig	# Don't check for errors -- the user may cancel
387218799Snwhitehornfi
388218799Snwhitehornbsdinstall time
389218799Snwhitehornbsdinstall services
390303447Srobakbsdinstall hardening
391218799Snwhitehorn
392218799Snwhitehorndialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
393218799Snwhitehorn    "Would you like to add users to the installed system now?" 0 0 && \
394218799Snwhitehorn    bsdinstall adduser
395218799Snwhitehorn
396218799Snwhitehornfinalconfig() {
397218799Snwhitehorn	exec 3>&1
398218799Snwhitehorn	REVISIT=$(dialog --backtitle "FreeBSD Installer" \
399218799Snwhitehorn	    --title "Final Configuration" --no-cancel --menu \
400228194Snwhitehorn	    "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 \
401226507Skensmith		"Exit" "Apply configuration and exit installer" \
402218799Snwhitehorn		"Add User" "Add a user to the system" \
403218799Snwhitehorn		"Root Password" "Change root password" \
404218799Snwhitehorn		"Hostname" "Set system hostname" \
405218799Snwhitehorn		"Network" "Networking configuration" \
406218799Snwhitehorn		"Services" "Set daemons to run on startup" \
407303447Srobak		"System Hardening" "Set security options" \
408218799Snwhitehorn		"Time Zone" "Set system timezone" \
409228194Snwhitehorn		"Handbook" "Install FreeBSD Handbook (requires network)" 2>&1 1>&3)
410218799Snwhitehorn	exec 3>&-
411218799Snwhitehorn
412218799Snwhitehorn	case "$REVISIT" in
413218799Snwhitehorn	"Add User")
414218799Snwhitehorn		bsdinstall adduser
415218799Snwhitehorn		finalconfig
416218799Snwhitehorn		;;
417218799Snwhitehorn	"Root Password")
418218799Snwhitehorn		bsdinstall rootpass 
419218799Snwhitehorn		finalconfig
420218799Snwhitehorn		;;
421218799Snwhitehorn	"Hostname")
422218799Snwhitehorn		bsdinstall hostname
423218799Snwhitehorn		finalconfig
424218799Snwhitehorn		;;
425218799Snwhitehorn	"Network")
426218799Snwhitehorn		bsdinstall netconfig
427218799Snwhitehorn		finalconfig
428218799Snwhitehorn		;;
429218799Snwhitehorn	"Services")
430218799Snwhitehorn		bsdinstall services
431218799Snwhitehorn		finalconfig
432218799Snwhitehorn		;;
433303447Srobak	"System Hardening")
434303447Srobak		bsdinstall hardening
435303447Srobak		finalconfig
436303447Srobak		;;
437218799Snwhitehorn	"Time Zone")
438218799Snwhitehorn		bsdinstall time
439218799Snwhitehorn		finalconfig
440218799Snwhitehorn		;;
441223897Snwhitehorn	"Handbook")
442223897Snwhitehorn		bsdinstall docsinstall
443223897Snwhitehorn		finalconfig
444223897Snwhitehorn		;;
445218799Snwhitehorn	esac
446218799Snwhitehorn}
447218799Snwhitehorn
448218799Snwhitehorn# Allow user to change his mind
449218799Snwhitehornfinalconfig
450218799Snwhitehorn
451218799Snwhitehorntrap error SIGINT	# SIGINT is bad again
452269653Sthompsabsdinstall config  || error "Failed to save config"
453218799Snwhitehorn
454313762Sgargaif [ -n "$DISTDIR_IS_UNIONFS" ]; then
455313762Sgarga	umount -f $BSDINSTALL_DISTDIR
456313762Sgargafi
457313762Sgarga
458218799Snwhitehornif [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
459218799Snwhitehorn	rm -rf "$BSDINSTALL_FETCHDEST"
460218799Snwhitehornfi
461218799Snwhitehorn
462228194Snwhitehorndialog --backtitle "FreeBSD Installer" --title "Manual Configuration" \
463271552Snwhitehorn    --default-button no --yesno \
464271552Snwhitehorn   "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
465228194Snwhitehornif [ $? -eq 0 ]; then
466228194Snwhitehorn	clear
467228194Snwhitehorn	echo This shell is operating in a chroot in the new system. \
468228194Snwhitehorn	    When finished making configuration changes, type \"exit\".
469228194Snwhitehorn	chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1
470228194Snwhitehornfi
471228194Snwhitehorn
472256338Sdesbsdinstall entropy
473256338Sdesbsdinstall umount
474256338Sdes
475257842Sdteskef_dprintf "Installation Completed at %s" "$( date )"
476218799Snwhitehorn
477257842Sdteske################################################################################
478257842Sdteske# END
479257842Sdteske################################################################################
480