xref: /freebsd/usr.sbin/bsdinstall/scripts/auto (revision bc4a673f89b9c5d4eb0be86cf4206a6b09fd2ca3)
12118f387SNathan Whitehorn#!/bin/sh
22118f387SNathan Whitehorn#-
32118f387SNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn
4*bc4a673fSDevin 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$
29*bc4a673fSDevin Teske#
30*bc4a673fSDevin Teske############################################################ INCLUDES
312118f387SNathan Whitehorn
32*bc4a673fSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig"
33*bc4a673fSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1
34*bc4a673fSDevin Teske
35*bc4a673fSDevin Teske############################################################ FUNCTIONS
362118f387SNathan Whitehorn
372118f387SNathan Whitehornerror() {
385a038452SNathan Whitehorn	test -n "$DISTDIR_IS_UNIONFS" && umount -f $BSDINSTALL_DISTDIR
395a038452SNathan Whitehorn	test -f $PATH_FSTAB && bsdinstall umount
402118f387SNathan Whitehorn	dialog --backtitle "FreeBSD Installer" --title "Abort" \
412118f387SNathan Whitehorn	    --no-label "Exit" --yes-label "Restart" --yesno \
422118f387SNathan Whitehorn	    "An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
432118f387SNathan Whitehorn	if [ $? -ne 0 ]; then
446d02d4cbSNathan Whitehorn		exit 1
452118f387SNathan Whitehorn	else
462118f387SNathan Whitehorn		exec $0
472118f387SNathan Whitehorn	fi
482118f387SNathan Whitehorn}
492118f387SNathan Whitehorn
50*bc4a673fSDevin Teske############################################################ MAIN
51*bc4a673fSDevin Teske
52*bc4a673fSDevin Teskef_dprintf "Began Installation at %s" "$( date )"
532118f387SNathan Whitehorn
542118f387SNathan Whitehornrm -rf $BSDINSTALL_TMPETC
552118f387SNathan Whitehornmkdir $BSDINSTALL_TMPETC
562118f387SNathan Whitehorn
572118f387SNathan Whitehorntrap true SIGINT	# This section is optional
582118f387SNathan Whitehornbsdinstall keymap
592118f387SNathan Whitehorn
602118f387SNathan Whitehorntrap error SIGINT	# Catch cntrl-C here
612118f387SNathan Whitehornbsdinstall hostname || error
622118f387SNathan Whitehorn
63b70047d4SNathan Whitehornexport DISTRIBUTIONS="base.txz kernel.txz"
64b70047d4SNathan Whitehornif [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
65c0d1bdc0SDevin Teske	DISTMENU=`awk -F'\t' '!/^(kernel|base)/{print $4,$5,$6}' $BSDINSTALL_DISTDIR/MANIFEST`
66addc19a4SNathan Whitehorn
67addc19a4SNathan Whitehorn	exec 3>&1
684ca6fb65SDevin Teske	EXTRA_DISTS=$( eval dialog \
694ca6fb65SDevin Teske	    --backtitle \"FreeBSD Installer\" \
704ca6fb65SDevin Teske	    --title \"Distribution Select\" --nocancel --separate-output \
714ca6fb65SDevin Teske	    --checklist \"Choose optional system components to install:\" \
724ca6fb65SDevin Teske	    0 0 0 $DISTMENU \
73addc19a4SNathan Whitehorn	2>&1 1>&3 )
74addc19a4SNathan Whitehorn	for dist in $EXTRA_DISTS; do
75addc19a4SNathan Whitehorn		export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
76addc19a4SNathan Whitehorn	done
77b70047d4SNathan Whitehornfi
78addc19a4SNathan Whitehorn
792118f387SNathan WhitehornFETCH_DISTRIBUTIONS=""
802118f387SNathan Whitehornfor dist in $DISTRIBUTIONS; do
812118f387SNathan Whitehorn	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
822118f387SNathan Whitehorn		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
832118f387SNathan Whitehorn	fi
842118f387SNathan Whitehorndone
856dcef0cfSNathan WhitehornFETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS`	# Trim white space
862118f387SNathan Whitehorn
876dcef0cfSNathan Whitehornif [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then
882118f387SNathan Whitehorn	dialog --backtitle "FreeBSD Installer" --title "Network Installation" --msgbox "No installation files were found on the boot volume. The next few screens will allow you to configure networking so that they can be downloaded from the Internet." 0 0
892118f387SNathan Whitehorn	bsdinstall netconfig || error
902118f387SNathan Whitehorn	NETCONFIG_DONE=yes
912118f387SNathan Whitehornfi
922118f387SNathan Whitehorn
935a038452SNathan Whitehornif [ -n "$FETCH_DISTRIBUTIONS" ]; then
946dcef0cfSNathan Whitehorn	exec 3>&1
9526976226SNathan Whitehorn	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
966dcef0cfSNathan Whitehorn	MIRROR_BUTTON=$?
976dcef0cfSNathan Whitehorn	exec 3>&-
986dcef0cfSNathan Whitehorn	test $MIRROR_BUTTON -eq 0 || error
996dcef0cfSNathan Whitehorn	export BSDINSTALL_DISTSITE
1006dcef0cfSNathan Whitehornfi
1016dcef0cfSNathan Whitehorn
1022118f387SNathan Whitehornrm $PATH_FSTAB
1032118f387SNathan Whitehorntouch $PATH_FSTAB
1042118f387SNathan Whitehorn
105cd88b886SDevin TeskePMODES="\
106cd88b886SDevin TeskeGuided \"Partitioning Tool (Recommended for Beginners)\" \
107cd88b886SDevin TeskeManual \"Manually Configure Partitions (Expert)\" \
108cd88b886SDevin TeskeShell \"Open a shell and partition by hand\""
1092118f387SNathan Whitehorn
110cd88b886SDevin TeskeCURARCH=$( uname -m )
111cd88b886SDevin Teskecase $CURARCH in
112cd88b886SDevin Teske	amd64|i386)	# Booting ZFS Supported
113cd88b886SDevin Teske		PMODES="$PMODES ZFS \"Automatic Root-on-ZFS (Experimental)\""
114cd88b886SDevin Teske		;;
115cd88b886SDevin Teske	*)		# Booting ZFS Unspported
116cd88b886SDevin Teske		;;
117cd88b886SDevin Teskeesac
118cd88b886SDevin Teske
119cd88b886SDevin Teskeexec 3>&1
120cd88b886SDevin TeskePARTMODE=`echo $PMODES | xargs dialog --backtitle "FreeBSD Installer" \
121cd88b886SDevin Teske	--title "Partitioning" \
122cd88b886SDevin Teske	--menu "How would you like to partition your disk?" \
123cd88b886SDevin Teske	0 0 0 2>&1 1>&3`
124cd88b886SDevin Teskeif [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi
125cd88b886SDevin Teskeexec 3>&-
126cd88b886SDevin Teske
127cd88b886SDevin Teskecase "$PARTMODE" in
128cd88b886SDevin Teske"Guided")	# Guided
1292118f387SNathan Whitehorn	bsdinstall autopart || error
1302118f387SNathan Whitehorn	bsdinstall mount || error
1312118f387SNathan Whitehorn	;;
132cd88b886SDevin Teske"Shell")	# Shell
1332118f387SNathan Whitehorn	clear
1342118f387SNathan 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'."
135809685bcSNathan Whitehorn	sh 2>&1
1362118f387SNathan Whitehorn	;;
137cd88b886SDevin Teske"Manual")	# Manual
138*bc4a673fSDevin Teske	if f_isset debugFile; then
139*bc4a673fSDevin Teske		# Give partedit the path to our logfile so it can append
140*bc4a673fSDevin Teske		BSDINSTALL_LOG="${debugFile#+}" bsdinstall partedit || error
141*bc4a673fSDevin Teske	else
1422118f387SNathan Whitehorn		bsdinstall partedit || error
143*bc4a673fSDevin Teske	fi
1442118f387SNathan Whitehorn	bsdinstall mount || error
1452118f387SNathan Whitehorn	;;
146cd88b886SDevin Teske"ZFS")	# ZFS
147cd88b886SDevin Teske	bsdinstall zfsboot || error
148cd88b886SDevin Teske	bsdinstall mount || error
149cd88b886SDevin Teske	;;
1502118f387SNathan Whitehorn*)
1512118f387SNathan Whitehorn	error
1522118f387SNathan Whitehorn	;;
1532118f387SNathan Whitehornesac
1542118f387SNathan Whitehorn
1552118f387SNathan Whitehornif [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
1562118f387SNathan Whitehorn	ALL_DISTRIBUTIONS="$DISTRIBUTIONS"
1572118f387SNathan Whitehorn
1582118f387SNathan Whitehorn	# Download to a directory in the new system as scratch space
15984b58c13SNathan Whitehorn	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
1602118f387SNathan Whitehorn	mkdir -p "$BSDINSTALL_FETCHDEST" || error
1612118f387SNathan Whitehorn
1622118f387SNathan Whitehorn	export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
1632118f387SNathan Whitehorn	# Try to use any existing distfiles
1645a038452SNathan Whitehorn	if [ -d $BSDINSTALL_DISTDIR ]; then
1656dcef0cfSNathan Whitehorn		DISTDIR_IS_UNIONFS=1
166bfc3bab8SNathan Whitehorn		mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
1676d02d4cbSNathan Whitehorn	else
1686d02d4cbSNathan Whitehorn		export DISTRIBUTIONS="MANIFEST $ALL_DISTRIBUTIONS"
1692118f387SNathan Whitehorn		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
1702118f387SNathan Whitehorn	fi
1712118f387SNathan Whitehorn
1726d02d4cbSNathan Whitehorn	export FTP_PASSIVE_MODE=YES
1732118f387SNathan Whitehorn	bsdinstall distfetch || error
1742118f387SNathan Whitehorn	export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
1752118f387SNathan Whitehornfi
1762118f387SNathan Whitehorn
177b70047d4SNathan Whitehornbsdinstall checksum || error
1782118f387SNathan Whitehornbsdinstall distextract || error
1792118f387SNathan Whitehornbsdinstall rootpass || error
1802118f387SNathan Whitehorn
1812118f387SNathan Whitehorntrap true SIGINT	# This section is optional
1822118f387SNathan Whitehornif [ "$NETCONFIG_DONE" != yes ]; then
1832118f387SNathan Whitehorn	bsdinstall netconfig	# Don't check for errors -- the user may cancel
1842118f387SNathan Whitehornfi
1852118f387SNathan Whitehornbsdinstall time
1862118f387SNathan Whitehornbsdinstall services
1872118f387SNathan Whitehorn
1882118f387SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
1892118f387SNathan Whitehorn    "Would you like to add users to the installed system now?" 0 0 && \
1902118f387SNathan Whitehorn    bsdinstall adduser
1912118f387SNathan Whitehorn
1922118f387SNathan Whitehornfinalconfig() {
1932118f387SNathan Whitehorn	exec 3>&1
1942118f387SNathan Whitehorn	REVISIT=$(dialog --backtitle "FreeBSD Installer" \
1952118f387SNathan Whitehorn	    --title "Final Configuration" --no-cancel --menu \
1966081c922SNathan 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 \
19722a84ec9SKen Smith		"Exit" "Apply configuration and exit installer" \
1982118f387SNathan Whitehorn		"Add User" "Add a user to the system" \
1992118f387SNathan Whitehorn		"Root Password" "Change root password" \
2002118f387SNathan Whitehorn		"Hostname" "Set system hostname" \
2012118f387SNathan Whitehorn		"Network" "Networking configuration" \
2022118f387SNathan Whitehorn		"Services" "Set daemons to run on startup" \
2032118f387SNathan Whitehorn		"Time Zone" "Set system timezone" \
2046081c922SNathan Whitehorn		"Handbook" "Install FreeBSD Handbook (requires network)" 2>&1 1>&3)
2052118f387SNathan Whitehorn	exec 3>&-
2062118f387SNathan Whitehorn
2072118f387SNathan Whitehorn	case "$REVISIT" in
2082118f387SNathan Whitehorn	"Add User")
2092118f387SNathan Whitehorn		bsdinstall adduser
2102118f387SNathan Whitehorn		finalconfig
2112118f387SNathan Whitehorn		;;
2122118f387SNathan Whitehorn	"Root Password")
2132118f387SNathan Whitehorn		bsdinstall rootpass
2142118f387SNathan Whitehorn		finalconfig
2152118f387SNathan Whitehorn		;;
2162118f387SNathan Whitehorn	"Hostname")
2172118f387SNathan Whitehorn		bsdinstall hostname
2182118f387SNathan Whitehorn		finalconfig
2192118f387SNathan Whitehorn		;;
2202118f387SNathan Whitehorn	"Network")
2212118f387SNathan Whitehorn		bsdinstall netconfig
2222118f387SNathan Whitehorn		finalconfig
2232118f387SNathan Whitehorn		;;
2242118f387SNathan Whitehorn	"Services")
2252118f387SNathan Whitehorn		bsdinstall services
2262118f387SNathan Whitehorn		finalconfig
2272118f387SNathan Whitehorn		;;
2282118f387SNathan Whitehorn	"Time Zone")
2292118f387SNathan Whitehorn		bsdinstall time
2302118f387SNathan Whitehorn		finalconfig
2312118f387SNathan Whitehorn		;;
232bfc3bab8SNathan Whitehorn	"Handbook")
233bfc3bab8SNathan Whitehorn		bsdinstall docsinstall
234bfc3bab8SNathan Whitehorn		finalconfig
235bfc3bab8SNathan Whitehorn		;;
2362118f387SNathan Whitehorn	esac
2372118f387SNathan Whitehorn}
2382118f387SNathan Whitehorn
2392118f387SNathan Whitehorn# Allow user to change his mind
2402118f387SNathan Whitehornfinalconfig
2412118f387SNathan Whitehorn
2422118f387SNathan Whitehorntrap error SIGINT	# SIGINT is bad again
2432118f387SNathan Whitehornbsdinstall config  || error
2442118f387SNathan Whitehorn
2452118f387SNathan Whitehornif [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
2462118f387SNathan Whitehorn	[ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \
2472118f387SNathan Whitehorn	    umount "$BSDINSTALL_DISTDIR"
2482118f387SNathan Whitehorn	rm -rf "$BSDINSTALL_FETCHDEST"
2492118f387SNathan Whitehornfi
2502118f387SNathan Whitehorn
2516081c922SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Manual Configuration" \
2526081c922SNathan Whitehorn    --yesno "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
2536081c922SNathan Whitehornif [ $? -eq 0 ]; then
2546081c922SNathan Whitehorn	clear
2550c3cc3c3SNathan Whitehorn	mount -t devfs devfs "$BSDINSTALL_CHROOT/dev"
2566081c922SNathan Whitehorn	echo This shell is operating in a chroot in the new system. \
2576081c922SNathan Whitehorn	    When finished making configuration changes, type \"exit\".
2586081c922SNathan Whitehorn	chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1
2596081c922SNathan Whitehornfi
2606081c922SNathan Whitehorn
261dfc23ba5SDag-Erling Smørgravbsdinstall entropy
262dfc23ba5SDag-Erling Smørgravbsdinstall umount
263dfc23ba5SDag-Erling Smørgrav
264*bc4a673fSDevin Teskef_dprintf "Installation Completed at %s" "$( date )"
2652118f387SNathan Whitehorn
266*bc4a673fSDevin Teske################################################################################
267*bc4a673fSDevin Teske# END
268*bc4a673fSDevin Teske################################################################################
269