xref: /freebsd/usr.sbin/bsdinstall/scripts/auto (revision dfc23ba54be5ca51d500fea6ed51341b580c45dd)
12118f387SNathan Whitehorn#!/bin/sh
22118f387SNathan Whitehorn#-
32118f387SNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn
42118f387SNathan Whitehorn# All rights reserved.
52118f387SNathan Whitehorn#
62118f387SNathan Whitehorn# Redistribution and use in source and binary forms, with or without
72118f387SNathan Whitehorn# modification, are permitted provided that the following conditions
82118f387SNathan Whitehorn# are met:
92118f387SNathan Whitehorn# 1. Redistributions of source code must retain the above copyright
102118f387SNathan Whitehorn#    notice, this list of conditions and the following disclaimer.
112118f387SNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright
122118f387SNathan Whitehorn#    notice, this list of conditions and the following disclaimer in the
132118f387SNathan Whitehorn#    documentation and/or other materials provided with the distribution.
142118f387SNathan Whitehorn#
152118f387SNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
162118f387SNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
172118f387SNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
182118f387SNathan Whitehorn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
192118f387SNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
202118f387SNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
212118f387SNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
222118f387SNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
232118f387SNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
242118f387SNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
252118f387SNathan Whitehorn# SUCH DAMAGE.
262118f387SNathan Whitehorn#
272118f387SNathan Whitehorn# $FreeBSD$
282118f387SNathan Whitehorn
292118f387SNathan Whitehornecho "Begun Installation at $(date)" > $BSDINSTALL_LOG
302118f387SNathan Whitehorn
312118f387SNathan Whitehornerror() {
325a038452SNathan Whitehorn	test -n "$DISTDIR_IS_UNIONFS" && umount -f $BSDINSTALL_DISTDIR
335a038452SNathan Whitehorn	test -f $PATH_FSTAB && bsdinstall umount
342118f387SNathan Whitehorn	dialog --backtitle "FreeBSD Installer" --title "Abort" \
352118f387SNathan Whitehorn	    --no-label "Exit" --yes-label "Restart" --yesno \
362118f387SNathan Whitehorn	    "An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
372118f387SNathan Whitehorn	if [ $? -ne 0 ]; then
386d02d4cbSNathan Whitehorn		exit 1
392118f387SNathan Whitehorn	else
402118f387SNathan Whitehorn		exec $0
412118f387SNathan Whitehorn	fi
422118f387SNathan Whitehorn}
432118f387SNathan Whitehorn
442118f387SNathan Whitehorn
452118f387SNathan Whitehornrm -rf $BSDINSTALL_TMPETC
462118f387SNathan Whitehornmkdir $BSDINSTALL_TMPETC
472118f387SNathan Whitehorn
482118f387SNathan Whitehorntrap true SIGINT	# This section is optional
492118f387SNathan Whitehornbsdinstall keymap
502118f387SNathan Whitehorn
512118f387SNathan Whitehorntrap error SIGINT	# Catch cntrl-C here
522118f387SNathan Whitehornbsdinstall hostname || error
532118f387SNathan Whitehorn
54b70047d4SNathan Whitehornexport DISTRIBUTIONS="base.txz kernel.txz"
55b70047d4SNathan Whitehornif [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
56c0d1bdc0SDevin Teske	DISTMENU=`awk -F'\t' '!/^(kernel|base)/{print $4,$5,$6}' $BSDINSTALL_DISTDIR/MANIFEST`
57addc19a4SNathan Whitehorn
58addc19a4SNathan Whitehorn	exec 3>&1
594ca6fb65SDevin Teske	EXTRA_DISTS=$( eval dialog \
604ca6fb65SDevin Teske	    --backtitle \"FreeBSD Installer\" \
614ca6fb65SDevin Teske	    --title \"Distribution Select\" --nocancel --separate-output \
624ca6fb65SDevin Teske	    --checklist \"Choose optional system components to install:\" \
634ca6fb65SDevin Teske	    0 0 0 $DISTMENU \
64addc19a4SNathan Whitehorn	2>&1 1>&3 )
65addc19a4SNathan Whitehorn	for dist in $EXTRA_DISTS; do
66addc19a4SNathan Whitehorn		export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
67addc19a4SNathan Whitehorn	done
68b70047d4SNathan Whitehornfi
69addc19a4SNathan Whitehorn
702118f387SNathan WhitehornFETCH_DISTRIBUTIONS=""
712118f387SNathan Whitehornfor dist in $DISTRIBUTIONS; do
722118f387SNathan Whitehorn	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
732118f387SNathan Whitehorn		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
742118f387SNathan Whitehorn	fi
752118f387SNathan Whitehorndone
766dcef0cfSNathan WhitehornFETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS`	# Trim white space
772118f387SNathan Whitehorn
786dcef0cfSNathan Whitehornif [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then
792118f387SNathan 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
802118f387SNathan Whitehorn	bsdinstall netconfig || error
812118f387SNathan Whitehorn	NETCONFIG_DONE=yes
822118f387SNathan Whitehornfi
832118f387SNathan Whitehorn
845a038452SNathan Whitehornif [ -n "$FETCH_DISTRIBUTIONS" ]; then
856dcef0cfSNathan Whitehorn	exec 3>&1
8626976226SNathan Whitehorn	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
876dcef0cfSNathan Whitehorn	MIRROR_BUTTON=$?
886dcef0cfSNathan Whitehorn	exec 3>&-
896dcef0cfSNathan Whitehorn	test $MIRROR_BUTTON -eq 0 || error
906dcef0cfSNathan Whitehorn	export BSDINSTALL_DISTSITE
916dcef0cfSNathan Whitehornfi
926dcef0cfSNathan Whitehorn
932118f387SNathan Whitehornrm $PATH_FSTAB
942118f387SNathan Whitehorntouch $PATH_FSTAB
952118f387SNathan Whitehorn
962118f387SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Partitioning" --extra-button \
972118f387SNathan Whitehorn    --extra-label "Manual" --ok-label "Guided" --cancel-label "Shell" \
982118f387SNathan Whitehorn    --yesno "Would you like to use the guided partitioning tool (recommended for beginners) or to set up partitions manually (experts)? You can also open a shell and set up partitions entirely by hand." 0 0
992118f387SNathan Whitehorn
1002118f387SNathan Whitehorncase $? in
1012118f387SNathan Whitehorn0)	# Guided
1022118f387SNathan Whitehorn	bsdinstall autopart || error
1032118f387SNathan Whitehorn	bsdinstall mount || error
1042118f387SNathan Whitehorn	;;
1052118f387SNathan Whitehorn1)	# Shell
1062118f387SNathan Whitehorn	clear
1072118f387SNathan 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'."
108809685bcSNathan Whitehorn	sh 2>&1
1092118f387SNathan Whitehorn	;;
1102118f387SNathan Whitehorn3)	# Manual
1112118f387SNathan Whitehorn	bsdinstall partedit || error
1122118f387SNathan Whitehorn	bsdinstall mount || error
1132118f387SNathan Whitehorn	;;
1142118f387SNathan Whitehorn*)
1152118f387SNathan Whitehorn	error
1162118f387SNathan Whitehorn	;;
1172118f387SNathan Whitehornesac
1182118f387SNathan Whitehorn
1192118f387SNathan Whitehornif [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
1202118f387SNathan Whitehorn	ALL_DISTRIBUTIONS="$DISTRIBUTIONS"
1212118f387SNathan Whitehorn
1222118f387SNathan Whitehorn	# Download to a directory in the new system as scratch space
12384b58c13SNathan Whitehorn	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
1242118f387SNathan Whitehorn	mkdir -p "$BSDINSTALL_FETCHDEST" || error
1252118f387SNathan Whitehorn
1262118f387SNathan Whitehorn	export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
1272118f387SNathan Whitehorn	# Try to use any existing distfiles
1285a038452SNathan Whitehorn	if [ -d $BSDINSTALL_DISTDIR ]; then
1296dcef0cfSNathan Whitehorn		DISTDIR_IS_UNIONFS=1
130bfc3bab8SNathan Whitehorn		mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
1316d02d4cbSNathan Whitehorn	else
1326d02d4cbSNathan Whitehorn		export DISTRIBUTIONS="MANIFEST $ALL_DISTRIBUTIONS"
1332118f387SNathan Whitehorn		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
1342118f387SNathan Whitehorn	fi
1352118f387SNathan Whitehorn
1366d02d4cbSNathan Whitehorn	export FTP_PASSIVE_MODE=YES
1372118f387SNathan Whitehorn	bsdinstall distfetch || error
1382118f387SNathan Whitehorn	export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
1392118f387SNathan Whitehornfi
1402118f387SNathan Whitehorn
141b70047d4SNathan Whitehornbsdinstall checksum || error
1422118f387SNathan Whitehornbsdinstall distextract || error
1432118f387SNathan Whitehornbsdinstall rootpass || error
1442118f387SNathan Whitehorn
1452118f387SNathan Whitehorntrap true SIGINT	# This section is optional
1462118f387SNathan Whitehornif [ "$NETCONFIG_DONE" != yes ]; then
1472118f387SNathan Whitehorn	bsdinstall netconfig	# Don't check for errors -- the user may cancel
1482118f387SNathan Whitehornfi
1492118f387SNathan Whitehornbsdinstall time
1502118f387SNathan Whitehornbsdinstall services
1512118f387SNathan Whitehorn
1522118f387SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
1532118f387SNathan Whitehorn    "Would you like to add users to the installed system now?" 0 0 && \
1542118f387SNathan Whitehorn    bsdinstall adduser
1552118f387SNathan Whitehorn
1562118f387SNathan Whitehornfinalconfig() {
1572118f387SNathan Whitehorn	exec 3>&1
1582118f387SNathan Whitehorn	REVISIT=$(dialog --backtitle "FreeBSD Installer" \
1592118f387SNathan Whitehorn	    --title "Final Configuration" --no-cancel --menu \
1606081c922SNathan 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 \
16122a84ec9SKen Smith		"Exit" "Apply configuration and exit installer" \
1622118f387SNathan Whitehorn		"Add User" "Add a user to the system" \
1632118f387SNathan Whitehorn		"Root Password" "Change root password" \
1642118f387SNathan Whitehorn		"Hostname" "Set system hostname" \
1652118f387SNathan Whitehorn		"Network" "Networking configuration" \
1662118f387SNathan Whitehorn		"Services" "Set daemons to run on startup" \
1672118f387SNathan Whitehorn		"Time Zone" "Set system timezone" \
1686081c922SNathan Whitehorn		"Handbook" "Install FreeBSD Handbook (requires network)" 2>&1 1>&3)
1692118f387SNathan Whitehorn	exec 3>&-
1702118f387SNathan Whitehorn
1712118f387SNathan Whitehorn	case "$REVISIT" in
1722118f387SNathan Whitehorn	"Add User")
1732118f387SNathan Whitehorn		bsdinstall adduser
1742118f387SNathan Whitehorn		finalconfig
1752118f387SNathan Whitehorn		;;
1762118f387SNathan Whitehorn	"Root Password")
1772118f387SNathan Whitehorn		bsdinstall rootpass
1782118f387SNathan Whitehorn		finalconfig
1792118f387SNathan Whitehorn		;;
1802118f387SNathan Whitehorn	"Hostname")
1812118f387SNathan Whitehorn		bsdinstall hostname
1822118f387SNathan Whitehorn		finalconfig
1832118f387SNathan Whitehorn		;;
1842118f387SNathan Whitehorn	"Network")
1852118f387SNathan Whitehorn		bsdinstall netconfig
1862118f387SNathan Whitehorn		finalconfig
1872118f387SNathan Whitehorn		;;
1882118f387SNathan Whitehorn	"Services")
1892118f387SNathan Whitehorn		bsdinstall services
1902118f387SNathan Whitehorn		finalconfig
1912118f387SNathan Whitehorn		;;
1922118f387SNathan Whitehorn	"Time Zone")
1932118f387SNathan Whitehorn		bsdinstall time
1942118f387SNathan Whitehorn		finalconfig
1952118f387SNathan Whitehorn		;;
196bfc3bab8SNathan Whitehorn	"Handbook")
197bfc3bab8SNathan Whitehorn		bsdinstall docsinstall
198bfc3bab8SNathan Whitehorn		finalconfig
199bfc3bab8SNathan Whitehorn		;;
2002118f387SNathan Whitehorn	esac
2012118f387SNathan Whitehorn}
2022118f387SNathan Whitehorn
2032118f387SNathan Whitehorn# Allow user to change his mind
2042118f387SNathan Whitehornfinalconfig
2052118f387SNathan Whitehorn
2062118f387SNathan Whitehorntrap error SIGINT	# SIGINT is bad again
2072118f387SNathan Whitehornbsdinstall config  || error
2082118f387SNathan Whitehorn
2092118f387SNathan Whitehornif [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
2102118f387SNathan Whitehorn	[ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \
2112118f387SNathan Whitehorn	    umount "$BSDINSTALL_DISTDIR"
2122118f387SNathan Whitehorn	rm -rf "$BSDINSTALL_FETCHDEST"
2132118f387SNathan Whitehornfi
2142118f387SNathan Whitehorn
2156081c922SNathan Whitehorndialog --backtitle "FreeBSD Installer" --title "Manual Configuration" \
2166081c922SNathan 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
2176081c922SNathan Whitehornif [ $? -eq 0 ]; then
2186081c922SNathan Whitehorn	clear
2190c3cc3c3SNathan Whitehorn	mount -t devfs devfs "$BSDINSTALL_CHROOT/dev"
2206081c922SNathan Whitehorn	echo This shell is operating in a chroot in the new system. \
2216081c922SNathan Whitehorn	    When finished making configuration changes, type \"exit\".
2226081c922SNathan Whitehorn	chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1
2236081c922SNathan Whitehornfi
2246081c922SNathan Whitehorn
225*dfc23ba5SDag-Erling Smørgravbsdinstall entropy
226*dfc23ba5SDag-Erling Smørgravbsdinstall umount
227*dfc23ba5SDag-Erling Smørgrav
2282118f387SNathan Whitehornecho "Installation Completed at $(date)" >> $BSDINSTALL_LOG
2292118f387SNathan Whitehorn
230