xref: /freebsd/usr.sbin/bsdinstall/scripts/auto (revision 44a25dd6c678dcdce46ddd61af2e9ee3879a7031)
12118f387SNathan Whitehorn#!/bin/sh
22118f387SNathan Whitehorn#-
32118f387SNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn
4bc4a673fSDevin Teske# Copyright (c) 2013 Devin Teske
52118f387SNathan Whitehorn# All rights reserved.
62118f387SNathan Whitehorn#
72118f387SNathan Whitehorn# Redistribution and use in source and binary forms, with or without
82118f387SNathan Whitehorn# modification, are permitted provided that the following conditions
92118f387SNathan Whitehorn# are met:
102118f387SNathan Whitehorn# 1. Redistributions of source code must retain the above copyright
112118f387SNathan Whitehorn#    notice, this list of conditions and the following disclaimer.
122118f387SNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright
132118f387SNathan Whitehorn#    notice, this list of conditions and the following disclaimer in the
142118f387SNathan Whitehorn#    documentation and/or other materials provided with the distribution.
152118f387SNathan Whitehorn#
162118f387SNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
172118f387SNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182118f387SNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
192118f387SNathan Whitehorn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
202118f387SNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
212118f387SNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
222118f387SNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
232118f387SNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
242118f387SNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
252118f387SNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
262118f387SNathan Whitehorn# SUCH DAMAGE.
272118f387SNathan Whitehorn#
282118f387SNathan Whitehorn# $FreeBSD$
29bc4a673fSDevin Teske#
30bc4a673fSDevin Teske############################################################ INCLUDES
312118f387SNathan Whitehorn
32bc4a673fSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig"
33bc4a673fSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1
34bc4a673fSDevin Teske
35bc4a673fSDevin Teske############################################################ FUNCTIONS
362118f387SNathan Whitehorn
372118f387SNathan Whitehornerror() {
387041a67eSAndrew Thompson	local msg
397041a67eSAndrew Thompson	if [ -n "$1" ]; then
407041a67eSAndrew Thompson		msg="$1\n\n"
417041a67eSAndrew Thompson	fi
425a038452SNathan Whitehorn	test -n "$DISTDIR_IS_UNIONFS" && umount -f $BSDINSTALL_DISTDIR
435a038452SNathan Whitehorn	test -f $PATH_FSTAB && bsdinstall umount
442118f387SNathan Whitehorn	dialog --backtitle "FreeBSD Installer" --title "Abort" \
452118f387SNathan Whitehorn	    --no-label "Exit" --yes-label "Restart" --yesno \
467041a67eSAndrew Thompson	    "${msg}An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
472118f387SNathan Whitehorn	if [ $? -ne 0 ]; then
486d02d4cbSNathan Whitehorn		exit 1
492118f387SNathan Whitehorn	else
502118f387SNathan Whitehorn		exec $0
512118f387SNathan Whitehorn	fi
522118f387SNathan Whitehorn}
532118f387SNathan Whitehorn
54bc4a673fSDevin Teske############################################################ MAIN
55bc4a673fSDevin Teske
56bc4a673fSDevin Teskef_dprintf "Began Installation at %s" "$( date )"
572118f387SNathan Whitehorn
582118f387SNathan Whitehornrm -rf $BSDINSTALL_TMPETC
592118f387SNathan Whitehornmkdir $BSDINSTALL_TMPETC
602118f387SNathan Whitehorn
612118f387SNathan Whitehorntrap true SIGINT	# This section is optional
622118f387SNathan Whitehornbsdinstall keymap
632118f387SNathan Whitehorn
642118f387SNathan Whitehorntrap error SIGINT	# Catch cntrl-C here
657041a67eSAndrew Thompsonbsdinstall hostname || error "Set hostname failed"
662118f387SNathan Whitehorn
67b70047d4SNathan Whitehornexport DISTRIBUTIONS="base.txz kernel.txz"
68b70047d4SNathan Whitehornif [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
69c0d1bdc0SDevin Teske	DISTMENU=`awk -F'\t' '!/^(kernel|base)/{print $4,$5,$6}' $BSDINSTALL_DISTDIR/MANIFEST`
70addc19a4SNathan Whitehorn
71addc19a4SNathan Whitehorn	exec 3>&1
724ca6fb65SDevin Teske	EXTRA_DISTS=$( eval dialog \
734ca6fb65SDevin Teske	    --backtitle \"FreeBSD Installer\" \
744ca6fb65SDevin Teske	    --title \"Distribution Select\" --nocancel --separate-output \
754ca6fb65SDevin Teske	    --checklist \"Choose optional system components to install:\" \
764ca6fb65SDevin Teske	    0 0 0 $DISTMENU \
77addc19a4SNathan Whitehorn	2>&1 1>&3 )
78addc19a4SNathan Whitehorn	for dist in $EXTRA_DISTS; do
79addc19a4SNathan Whitehorn		export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
80addc19a4SNathan Whitehorn	done
81b70047d4SNathan Whitehornfi
82addc19a4SNathan Whitehorn
832118f387SNathan WhitehornFETCH_DISTRIBUTIONS=""
842118f387SNathan Whitehornfor dist in $DISTRIBUTIONS; do
852118f387SNathan Whitehorn	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
862118f387SNathan Whitehorn		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
872118f387SNathan Whitehorn	fi
882118f387SNathan Whitehorndone
896dcef0cfSNathan WhitehornFETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS`	# Trim white space
902118f387SNathan Whitehorn
916dcef0cfSNathan Whitehornif [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then
922118f387SNathan 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
932118f387SNathan Whitehorn	bsdinstall netconfig || error
942118f387SNathan Whitehorn	NETCONFIG_DONE=yes
952118f387SNathan Whitehornfi
962118f387SNathan Whitehorn
975a038452SNathan Whitehornif [ -n "$FETCH_DISTRIBUTIONS" ]; then
986dcef0cfSNathan Whitehorn	exec 3>&1
9926976226SNathan Whitehorn	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
1006dcef0cfSNathan Whitehorn	MIRROR_BUTTON=$?
1016dcef0cfSNathan Whitehorn	exec 3>&-
1027041a67eSAndrew Thompson	test $MIRROR_BUTTON -eq 0 || error "No mirror selected"
1036dcef0cfSNathan Whitehorn	export BSDINSTALL_DISTSITE
1046dcef0cfSNathan Whitehornfi
1056dcef0cfSNathan Whitehorn
1062d5cf580SDevin Teskerm -f $PATH_FSTAB
1072118f387SNathan Whitehorntouch $PATH_FSTAB
1082118f387SNathan Whitehorn
109cd88b886SDevin TeskePMODES="\
110cd88b886SDevin TeskeGuided \"Partitioning Tool (Recommended for Beginners)\" \
111cd88b886SDevin TeskeManual \"Manually Configure Partitions (Expert)\" \
112cd88b886SDevin TeskeShell \"Open a shell and partition by hand\""
1132118f387SNathan Whitehorn
114cd88b886SDevin TeskeCURARCH=$( uname -m )
115cd88b886SDevin Teskecase $CURARCH in
116cd88b886SDevin Teske	amd64|i386)	# Booting ZFS Supported
117cd88b886SDevin Teske		PMODES="$PMODES ZFS \"Automatic Root-on-ZFS (Experimental)\""
118cd88b886SDevin Teske		;;
119cd88b886SDevin Teske	*)		# Booting ZFS Unspported
120cd88b886SDevin Teske		;;
121cd88b886SDevin Teskeesac
122cd88b886SDevin Teske
123cd88b886SDevin Teskeexec 3>&1
124cd88b886SDevin TeskePARTMODE=`echo $PMODES | xargs dialog --backtitle "FreeBSD Installer" \
125cd88b886SDevin Teske	--title "Partitioning" \
126cd88b886SDevin Teske	--menu "How would you like to partition your disk?" \
12731a0cf13SDevin Teske	0 0 0 2>&1 1>&3` || exit 1
128cd88b886SDevin Teskeexec 3>&-
129cd88b886SDevin Teske
130cd88b886SDevin Teskecase "$PARTMODE" in
131cd88b886SDevin Teske"Guided")	# Guided
1327041a67eSAndrew Thompson	bsdinstall autopart || error "Partitioning error"
1337041a67eSAndrew Thompson	bsdinstall mount || error "Failed to mount filesystem"
1342118f387SNathan Whitehorn	;;
135cd88b886SDevin Teske"Shell")	# Shell
1362118f387SNathan Whitehorn	clear
1372118f387SNathan 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'."
138809685bcSNathan Whitehorn	sh 2>&1
1392118f387SNathan Whitehorn	;;
140cd88b886SDevin Teske"Manual")	# Manual
141bc4a673fSDevin Teske	if f_isset debugFile; then
142bc4a673fSDevin Teske		# Give partedit the path to our logfile so it can append
1437041a67eSAndrew Thompson		BSDINSTALL_LOG="${debugFile#+}" bsdinstall partedit || error "Partitioning error"
144bc4a673fSDevin Teske	else
1457041a67eSAndrew Thompson		bsdinstall partedit || error "Partitioning error"
146bc4a673fSDevin Teske	fi
1477041a67eSAndrew Thompson	bsdinstall mount || error "Failed to mount filesystem"
1482118f387SNathan Whitehorn	;;
149cd88b886SDevin Teske"ZFS")	# ZFS
1507041a67eSAndrew Thompson	bsdinstall zfsboot || error "ZFS setup failed"
1517041a67eSAndrew Thompson	bsdinstall mount || error "Failed to mount filesystem"
152cd88b886SDevin Teske	;;
1532118f387SNathan Whitehorn*)
1547041a67eSAndrew Thompson	error "Unknown partitioning mode"
1552118f387SNathan Whitehorn	;;
1562118f387SNathan Whitehornesac
1572118f387SNathan Whitehorn
1582118f387SNathan Whitehornif [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
1592118f387SNathan Whitehorn	ALL_DISTRIBUTIONS="$DISTRIBUTIONS"
1602118f387SNathan Whitehorn
1612118f387SNathan Whitehorn	# Download to a directory in the new system as scratch space
16284b58c13SNathan Whitehorn	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
1637041a67eSAndrew Thompson	mkdir -p "$BSDINSTALL_FETCHDEST" || error "Could not create directory $BSDINSTALL_FETCHDEST"
1642118f387SNathan Whitehorn
1652118f387SNathan Whitehorn	export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
1662118f387SNathan Whitehorn	# Try to use any existing distfiles
1675a038452SNathan Whitehorn	if [ -d $BSDINSTALL_DISTDIR ]; then
1686dcef0cfSNathan Whitehorn		DISTDIR_IS_UNIONFS=1
169bfc3bab8SNathan Whitehorn		mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
1706d02d4cbSNathan Whitehorn	else
1716d02d4cbSNathan Whitehorn		export DISTRIBUTIONS="MANIFEST $ALL_DISTRIBUTIONS"
1722118f387SNathan Whitehorn		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
1732118f387SNathan Whitehorn	fi
1742118f387SNathan Whitehorn
1756d02d4cbSNathan Whitehorn	export FTP_PASSIVE_MODE=YES
1767041a67eSAndrew Thompson	bsdinstall distfetch || error "Failed to fetch distribution"
1772118f387SNathan Whitehorn	export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
1782118f387SNathan Whitehornfi
1792118f387SNathan Whitehorn
1807041a67eSAndrew Thompsonbsdinstall checksum || error "Distribution checksum failed"
1817041a67eSAndrew Thompsonbsdinstall distextract || error "Distribution extract failed"
1827041a67eSAndrew Thompsonbsdinstall rootpass || error "Could not set root password"
1832118f387SNathan Whitehorn
1842118f387SNathan Whitehorntrap true SIGINT	# This section is optional
1852118f387SNathan Whitehornif [ "$NETCONFIG_DONE" != yes ]; then
1862118f387SNathan Whitehorn	bsdinstall netconfig	# Don't check for errors -- the user may cancel
1872118f387SNathan Whitehornfi
1882118f387SNathan Whitehornbsdinstall time
1892118f387SNathan Whitehornbsdinstall services
1902118f387SNathan Whitehorn
1912118f387SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
1922118f387SNathan Whitehorn    "Would you like to add users to the installed system now?" 0 0 && \
1932118f387SNathan Whitehorn    bsdinstall adduser
1942118f387SNathan Whitehorn
1952118f387SNathan Whitehornfinalconfig() {
1962118f387SNathan Whitehorn	exec 3>&1
1972118f387SNathan Whitehorn	REVISIT=$(dialog --backtitle "FreeBSD Installer" \
1982118f387SNathan Whitehorn	    --title "Final Configuration" --no-cancel --menu \
1996081c922SNathan 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 \
20022a84ec9SKen Smith		"Exit" "Apply configuration and exit installer" \
2012118f387SNathan Whitehorn		"Add User" "Add a user to the system" \
2022118f387SNathan Whitehorn		"Root Password" "Change root password" \
2032118f387SNathan Whitehorn		"Hostname" "Set system hostname" \
2042118f387SNathan Whitehorn		"Network" "Networking configuration" \
2052118f387SNathan Whitehorn		"Services" "Set daemons to run on startup" \
2062118f387SNathan Whitehorn		"Time Zone" "Set system timezone" \
2076081c922SNathan Whitehorn		"Handbook" "Install FreeBSD Handbook (requires network)" 2>&1 1>&3)
2082118f387SNathan Whitehorn	exec 3>&-
2092118f387SNathan Whitehorn
2102118f387SNathan Whitehorn	case "$REVISIT" in
2112118f387SNathan Whitehorn	"Add User")
2122118f387SNathan Whitehorn		bsdinstall adduser
2132118f387SNathan Whitehorn		finalconfig
2142118f387SNathan Whitehorn		;;
2152118f387SNathan Whitehorn	"Root Password")
2162118f387SNathan Whitehorn		bsdinstall rootpass
2172118f387SNathan Whitehorn		finalconfig
2182118f387SNathan Whitehorn		;;
2192118f387SNathan Whitehorn	"Hostname")
2202118f387SNathan Whitehorn		bsdinstall hostname
2212118f387SNathan Whitehorn		finalconfig
2222118f387SNathan Whitehorn		;;
2232118f387SNathan Whitehorn	"Network")
2242118f387SNathan Whitehorn		bsdinstall netconfig
2252118f387SNathan Whitehorn		finalconfig
2262118f387SNathan Whitehorn		;;
2272118f387SNathan Whitehorn	"Services")
2282118f387SNathan Whitehorn		bsdinstall services
2292118f387SNathan Whitehorn		finalconfig
2302118f387SNathan Whitehorn		;;
2312118f387SNathan Whitehorn	"Time Zone")
2322118f387SNathan Whitehorn		bsdinstall time
2332118f387SNathan Whitehorn		finalconfig
2342118f387SNathan Whitehorn		;;
235bfc3bab8SNathan Whitehorn	"Handbook")
236bfc3bab8SNathan Whitehorn		bsdinstall docsinstall
237bfc3bab8SNathan Whitehorn		finalconfig
238bfc3bab8SNathan Whitehorn		;;
2392118f387SNathan Whitehorn	esac
2402118f387SNathan Whitehorn}
2412118f387SNathan Whitehorn
2422118f387SNathan Whitehorn# Allow user to change his mind
2432118f387SNathan Whitehornfinalconfig
2442118f387SNathan Whitehorn
2452118f387SNathan Whitehorntrap error SIGINT	# SIGINT is bad again
2467041a67eSAndrew Thompsonbsdinstall config  || error "Failed to save config"
2472118f387SNathan Whitehorn
2482118f387SNathan Whitehornif [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
2492118f387SNathan Whitehorn	[ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \
2502118f387SNathan Whitehorn	    umount "$BSDINSTALL_DISTDIR"
2512118f387SNathan Whitehorn	rm -rf "$BSDINSTALL_FETCHDEST"
2522118f387SNathan Whitehornfi
2532118f387SNathan Whitehorn
2546081c922SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Manual Configuration" \
255*44a25dd6SNathan Whitehorn    --default-button no --yesno \
256*44a25dd6SNathan 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
2576081c922SNathan Whitehornif [ $? -eq 0 ]; then
2586081c922SNathan Whitehorn	clear
2590c3cc3c3SNathan Whitehorn	mount -t devfs devfs "$BSDINSTALL_CHROOT/dev"
2606081c922SNathan Whitehorn	echo This shell is operating in a chroot in the new system. \
2616081c922SNathan Whitehorn	    When finished making configuration changes, type \"exit\".
2626081c922SNathan Whitehorn	chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1
2636081c922SNathan Whitehornfi
2646081c922SNathan Whitehorn
265dfc23ba5SDag-Erling Smørgravbsdinstall entropy
266dfc23ba5SDag-Erling Smørgravbsdinstall umount
267dfc23ba5SDag-Erling Smørgrav
268bc4a673fSDevin Teskef_dprintf "Installation Completed at %s" "$( date )"
2692118f387SNathan Whitehorn
270bc4a673fSDevin Teske################################################################################
271bc4a673fSDevin Teske# END
272bc4a673fSDevin Teske################################################################################
273