auto revision 225637
1218799Snwhitehorn#!/bin/sh
2218799Snwhitehorn#-
3218799Snwhitehorn# Copyright (c) 2011 Nathan Whitehorn
4218799Snwhitehorn# All rights reserved.
5218799Snwhitehorn#
6218799Snwhitehorn# Redistribution and use in source and binary forms, with or without
7218799Snwhitehorn# modification, are permitted provided that the following conditions
8218799Snwhitehorn# are met:
9218799Snwhitehorn# 1. Redistributions of source code must retain the above copyright
10218799Snwhitehorn#    notice, this list of conditions and the following disclaimer.
11218799Snwhitehorn# 2. Redistributions in binary form must reproduce the above copyright
12218799Snwhitehorn#    notice, this list of conditions and the following disclaimer in the
13218799Snwhitehorn#    documentation and/or other materials provided with the distribution.
14218799Snwhitehorn#
15218799Snwhitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16218799Snwhitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17218799Snwhitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18218799Snwhitehorn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19218799Snwhitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20218799Snwhitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21218799Snwhitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22218799Snwhitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23218799Snwhitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24218799Snwhitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25218799Snwhitehorn# SUCH DAMAGE.
26218799Snwhitehorn#
27218799Snwhitehorn# $FreeBSD: head/usr.sbin/bsdinstall/scripts/auto 225637 2011-09-17 09:25:45Z nwhitehorn $
28218799Snwhitehorn
29218799Snwhitehornecho "Begun Installation at $(date)" > $BSDINSTALL_LOG
30218799Snwhitehorn
31218799Snwhitehornerror() {
32220088Snwhitehorn	test -n "$DISTDIR_IS_UNIONFS" && umount -f $BSDINSTALL_DISTDIR
33220088Snwhitehorn	test -f $PATH_FSTAB && bsdinstall umount
34218799Snwhitehorn	dialog --backtitle "FreeBSD Installer" --title "Abort" \
35218799Snwhitehorn	    --no-label "Exit" --yes-label "Restart" --yesno \
36218799Snwhitehorn	    "An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
37218799Snwhitehorn	if [ $? -ne 0 ]; then
38225637Snwhitehorn		exit 1
39218799Snwhitehorn	else
40218799Snwhitehorn		exec $0
41218799Snwhitehorn	fi
42218799Snwhitehorn}
43218799Snwhitehorn
44218799Snwhitehorn
45218799Snwhitehornrm -rf $BSDINSTALL_TMPETC
46218799Snwhitehornmkdir $BSDINSTALL_TMPETC
47218799Snwhitehorn
48218799Snwhitehorntrap true SIGINT	# This section is optional
49218799Snwhitehornbsdinstall keymap
50218799Snwhitehorn
51218799Snwhitehorntrap error SIGINT	# Catch cntrl-C here
52218799Snwhitehornbsdinstall hostname || error
53218799Snwhitehorn
54219615Snwhitehornexport DISTRIBUTIONS="base.txz kernel.txz"
55219615Snwhitehornif [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
56219615Snwhitehorn	DISTMENU=`cut -f 4,5,6 $BSDINSTALL_DISTDIR/MANIFEST | grep -v -e ^kernel -e ^base`
57218947Snwhitehorn
58219615Snwhitehorn	exec 3>&1
59219615Snwhitehorn	EXTRA_DISTS=$(echo $DISTMENU | xargs dialog \
60219615Snwhitehorn	    --backtitle "FreeBSD Installer" \
61219615Snwhitehorn	    --title "Distribution Select" --nocancel --separate-output \
62219615Snwhitehorn	    --checklist "Choose optional system components to install:" \
63219615Snwhitehorn	    0 0 0 \
64219615Snwhitehorn	2>&1 1>&3)
65219615Snwhitehorn	for dist in $EXTRA_DISTS; do
66219615Snwhitehorn		export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
67219615Snwhitehorn	done
68219615Snwhitehornfi
69218947Snwhitehorn
70218799SnwhitehornFETCH_DISTRIBUTIONS=""
71218799Snwhitehornfor dist in $DISTRIBUTIONS; do
72218799Snwhitehorn	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
73218799Snwhitehorn		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
74218799Snwhitehorn	fi
75218799Snwhitehorndone
76220080SnwhitehornFETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS`	# Trim white space
77218799Snwhitehorn
78220080Snwhitehornif [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then
79218799Snwhitehorn	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
80218799Snwhitehorn	bsdinstall netconfig || error
81218799Snwhitehorn	NETCONFIG_DONE=yes
82218799Snwhitehornfi
83218799Snwhitehorn
84220088Snwhitehornif [ -n "$FETCH_DISTRIBUTIONS" ]; then
85220080Snwhitehorn	exec 3>&1
86220834Snwhitehorn	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
87220080Snwhitehorn	MIRROR_BUTTON=$?
88220080Snwhitehorn	exec 3>&-
89220080Snwhitehorn	test $MIRROR_BUTTON -eq 0 || error
90220080Snwhitehorn	export BSDINSTALL_DISTSITE
91220080Snwhitehornfi
92220080Snwhitehorn
93218799Snwhitehornrm $PATH_FSTAB
94218799Snwhitehorntouch $PATH_FSTAB
95218799Snwhitehorn
96218799Snwhitehorndialog --backtitle "FreeBSD Installer" --title "Partitioning" --extra-button \
97218799Snwhitehorn    --extra-label "Manual" --ok-label "Guided" --cancel-label "Shell" \
98218799Snwhitehorn    --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
99218799Snwhitehorn
100218799Snwhitehorncase $? in
101218799Snwhitehorn0)	# Guided
102218799Snwhitehorn	bsdinstall autopart || error
103218799Snwhitehorn	bsdinstall mount || error
104218799Snwhitehorn	;;
105218799Snwhitehorn1)	# Shell
106218799Snwhitehorn	clear
107218799Snwhitehorn	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'."
108222425Snwhitehorn	sh 2>&1
109218799Snwhitehorn	;;
110218799Snwhitehorn3)	# Manual
111218799Snwhitehorn	bsdinstall partedit || error
112218799Snwhitehorn	bsdinstall mount || error
113218799Snwhitehorn	;;
114218799Snwhitehorn*)
115218799Snwhitehorn	error
116218799Snwhitehorn	;;
117218799Snwhitehornesac
118218799Snwhitehorn
119218799Snwhitehornif [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
120218799Snwhitehorn	ALL_DISTRIBUTIONS="$DISTRIBUTIONS"
121218799Snwhitehorn
122218799Snwhitehorn	# Download to a directory in the new system as scratch space
123219528Snwhitehorn	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
124218799Snwhitehorn	mkdir -p "$BSDINSTALL_FETCHDEST" || error
125218799Snwhitehorn
126218799Snwhitehorn	export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
127218799Snwhitehorn	# Try to use any existing distfiles
128220088Snwhitehorn	if [ -d $BSDINSTALL_DISTDIR ]; then
129220080Snwhitehorn		DISTDIR_IS_UNIONFS=1
130223897Snwhitehorn		mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
131225637Snwhitehorn	else
132225637Snwhitehorn		export DISTRIBUTIONS="MANIFEST $ALL_DISTRIBUTIONS"
133218799Snwhitehorn		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
134218799Snwhitehorn	fi
135218799Snwhitehorn		
136225637Snwhitehorn	export FTP_PASSIVE_MODE=YES
137218799Snwhitehorn	bsdinstall distfetch || error
138218799Snwhitehorn	export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
139218799Snwhitehornfi
140218799Snwhitehorn
141219615Snwhitehornbsdinstall checksum || error
142218799Snwhitehornbsdinstall distextract || error
143218799Snwhitehornbsdinstall rootpass || error
144218799Snwhitehorn
145218799Snwhitehorntrap true SIGINT	# This section is optional
146218799Snwhitehornif [ "$NETCONFIG_DONE" != yes ]; then
147218799Snwhitehorn	bsdinstall netconfig	# Don't check for errors -- the user may cancel
148218799Snwhitehornfi
149218799Snwhitehornbsdinstall time
150218799Snwhitehornbsdinstall services
151218799Snwhitehorn
152218799Snwhitehorndialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
153218799Snwhitehorn    "Would you like to add users to the installed system now?" 0 0 && \
154218799Snwhitehorn    bsdinstall adduser
155218799Snwhitehorn
156218799Snwhitehornfinalconfig() {
157218799Snwhitehorn	exec 3>&1
158218799Snwhitehorn	REVISIT=$(dialog --backtitle "FreeBSD Installer" \
159218799Snwhitehorn	    --title "Final Configuration" --no-cancel --menu \
160218799Snwhitehorn	    "Setup of your FreeBSD system is nearly complete. You can now modify your configuration choices or apply more complex changes using a shell." 0 0 0 \
161218799Snwhitehorn		"Add User" "Add a user to the system" \
162218799Snwhitehorn		"Root Password" "Change root password" \
163218799Snwhitehorn		"Hostname" "Set system hostname" \
164218799Snwhitehorn		"Network" "Networking configuration" \
165218799Snwhitehorn		"Services" "Set daemons to run on startup" \
166218799Snwhitehorn		"Time Zone" "Set system timezone" \
167223897Snwhitehorn		"Handbook" "Install FreeBSD Handbook (requires network)" \
168218799Snwhitehorn		"Shell" "Open a shell in the new system" \
169220499Snwhitehorn		"Exit" "Apply configuration and exit installer" 2>&1 1>&3)
170218799Snwhitehorn	exec 3>&-
171218799Snwhitehorn
172218799Snwhitehorn	case "$REVISIT" in
173218799Snwhitehorn	"Add User")
174218799Snwhitehorn		bsdinstall adduser
175218799Snwhitehorn		finalconfig
176218799Snwhitehorn		;;
177218799Snwhitehorn	"Root Password")
178218799Snwhitehorn		bsdinstall rootpass 
179218799Snwhitehorn		finalconfig
180218799Snwhitehorn		;;
181218799Snwhitehorn	"Hostname")
182218799Snwhitehorn		bsdinstall hostname
183218799Snwhitehorn		finalconfig
184218799Snwhitehorn		;;
185218799Snwhitehorn	"Network")
186218799Snwhitehorn		bsdinstall netconfig
187218799Snwhitehorn		finalconfig
188218799Snwhitehorn		;;
189218799Snwhitehorn	"Services")
190218799Snwhitehorn		bsdinstall services
191218799Snwhitehorn		finalconfig
192218799Snwhitehorn		;;
193218799Snwhitehorn	"Time Zone")
194218799Snwhitehorn		bsdinstall time
195218799Snwhitehorn		finalconfig
196218799Snwhitehorn		;;
197223897Snwhitehorn	"Handbook")
198223897Snwhitehorn		bsdinstall docsinstall
199223897Snwhitehorn		finalconfig
200223897Snwhitehorn		;;
201218799Snwhitehorn	"Shell")
202218799Snwhitehorn		clear
203218799Snwhitehorn		echo This shell is operating in a chroot in the new system. \
204218799Snwhitehorn		    When finished making configuration changes, type \"exit\".
205222607Snwhitehorn		chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1
206218799Snwhitehorn		# Don't hose local rc.conf changes
207218799Snwhitehorn		cp $BSDINSTALL_CHROOT/etc/rc.conf $BSDINSTALL_TMPETC/rc.conf.manual
208218799Snwhitehorn		finalconfig
209218799Snwhitehorn		;;
210218799Snwhitehorn	esac
211218799Snwhitehorn}
212218799Snwhitehorn
213218799Snwhitehorn# Allow user to change his mind
214218799Snwhitehornfinalconfig
215218799Snwhitehorn
216218799Snwhitehorntrap error SIGINT	# SIGINT is bad again
217218799Snwhitehornbsdinstall config  || error
218218799Snwhitehorn
219218799Snwhitehornif [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
220218799Snwhitehorn	[ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \
221218799Snwhitehorn	    umount "$BSDINSTALL_DISTDIR"
222218799Snwhitehorn	rm -rf "$BSDINSTALL_FETCHDEST"
223218799Snwhitehornfi
224218799Snwhitehorn
225218799Snwhitehornecho "Installation Completed at $(date)" >> $BSDINSTALL_LOG
226218799Snwhitehorn
227