auto revision 256361
1#!/bin/sh
2#-
3# Copyright (c) 2011 Nathan Whitehorn
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27# $FreeBSD: stable/10/usr.sbin/bsdinstall/scripts/auto 256361 2013-10-11 23:12:05Z dteske $
28
29echo "Begun Installation at $(date)" > $BSDINSTALL_LOG
30
31error() {
32	test -n "$DISTDIR_IS_UNIONFS" && umount -f $BSDINSTALL_DISTDIR
33	test -f $PATH_FSTAB && bsdinstall umount
34	dialog --backtitle "FreeBSD Installer" --title "Abort" \
35	    --no-label "Exit" --yes-label "Restart" --yesno \
36	    "An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
37	if [ $? -ne 0 ]; then
38		exit 1
39	else
40		exec $0
41	fi
42}
43
44
45rm -rf $BSDINSTALL_TMPETC
46mkdir $BSDINSTALL_TMPETC
47
48trap true SIGINT	# This section is optional
49bsdinstall keymap
50
51trap error SIGINT	# Catch cntrl-C here
52bsdinstall hostname || error
53
54export DISTRIBUTIONS="base.txz kernel.txz"
55if [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
56	DISTMENU=`awk -F'\t' '!/^(kernel|base)/{print $4,$5,$6}' $BSDINSTALL_DISTDIR/MANIFEST`
57
58	exec 3>&1
59	EXTRA_DISTS=$( eval dialog \
60	    --backtitle \"FreeBSD Installer\" \
61	    --title \"Distribution Select\" --nocancel --separate-output \
62	    --checklist \"Choose optional system components to install:\" \
63	    0 0 0 $DISTMENU \
64	2>&1 1>&3 )
65	for dist in $EXTRA_DISTS; do
66		export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
67	done
68fi
69
70FETCH_DISTRIBUTIONS=""
71for dist in $DISTRIBUTIONS; do
72	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
73		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
74	fi
75done
76FETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS`	# Trim white space
77
78if [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then
79	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
80	bsdinstall netconfig || error
81	NETCONFIG_DONE=yes
82fi
83
84if [ -n "$FETCH_DISTRIBUTIONS" ]; then
85	exec 3>&1
86	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
87	MIRROR_BUTTON=$?
88	exec 3>&-
89	test $MIRROR_BUTTON -eq 0 || error
90	export BSDINSTALL_DISTSITE
91fi
92
93rm $PATH_FSTAB
94touch $PATH_FSTAB
95
96PMODES="\
97Guided \"Partitioning Tool (Recommended for Beginners)\" \
98Manual \"Manually Configure Partitions (Expert)\" \
99Shell \"Open a shell and partition by hand\""
100
101CURARCH=$( uname -m )
102case $CURARCH in
103	amd64|i386)	# Booting ZFS Supported
104		PMODES="$PMODES ZFS \"Automatic Root-on-ZFS (Experimental)\""
105		;;
106	*)		# Booting ZFS Unspported
107		;;
108esac
109
110exec 3>&1
111PARTMODE=`echo $PMODES | xargs dialog --backtitle "FreeBSD Installer" \
112	--title "Partitioning" \
113	--menu "How would you like to partition your disk?" \
114	0 0 0 2>&1 1>&3`
115if [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi
116exec 3>&-
117
118case "$PARTMODE" in
119"Guided")	# Guided
120	bsdinstall autopart || error
121	bsdinstall mount || error
122	;;
123"Shell")	# Shell
124	clear
125	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'."
126	sh 2>&1
127	;;
128"Manual")	# Manual
129	bsdinstall partedit || error
130	bsdinstall mount || error
131	;;
132"ZFS")	# ZFS
133	bsdinstall zfsboot || error
134	bsdinstall mount || error
135	;;
136*)
137	error
138	;;
139esac
140
141if [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
142	ALL_DISTRIBUTIONS="$DISTRIBUTIONS"
143
144	# Download to a directory in the new system as scratch space
145	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
146	mkdir -p "$BSDINSTALL_FETCHDEST" || error
147
148	export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
149	# Try to use any existing distfiles
150	if [ -d $BSDINSTALL_DISTDIR ]; then
151		DISTDIR_IS_UNIONFS=1
152		mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
153	else
154		export DISTRIBUTIONS="MANIFEST $ALL_DISTRIBUTIONS"
155		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
156	fi
157		
158	export FTP_PASSIVE_MODE=YES
159	bsdinstall distfetch || error
160	export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
161fi
162
163bsdinstall checksum || error
164bsdinstall distextract || error
165bsdinstall rootpass || error
166
167trap true SIGINT	# This section is optional
168if [ "$NETCONFIG_DONE" != yes ]; then
169	bsdinstall netconfig	# Don't check for errors -- the user may cancel
170fi
171bsdinstall time
172bsdinstall services
173
174dialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
175    "Would you like to add users to the installed system now?" 0 0 && \
176    bsdinstall adduser
177
178finalconfig() {
179	exec 3>&1
180	REVISIT=$(dialog --backtitle "FreeBSD Installer" \
181	    --title "Final Configuration" --no-cancel --menu \
182	    "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 \
183		"Exit" "Apply configuration and exit installer" \
184		"Add User" "Add a user to the system" \
185		"Root Password" "Change root password" \
186		"Hostname" "Set system hostname" \
187		"Network" "Networking configuration" \
188		"Services" "Set daemons to run on startup" \
189		"Time Zone" "Set system timezone" \
190		"Handbook" "Install FreeBSD Handbook (requires network)" 2>&1 1>&3)
191	exec 3>&-
192
193	case "$REVISIT" in
194	"Add User")
195		bsdinstall adduser
196		finalconfig
197		;;
198	"Root Password")
199		bsdinstall rootpass 
200		finalconfig
201		;;
202	"Hostname")
203		bsdinstall hostname
204		finalconfig
205		;;
206	"Network")
207		bsdinstall netconfig
208		finalconfig
209		;;
210	"Services")
211		bsdinstall services
212		finalconfig
213		;;
214	"Time Zone")
215		bsdinstall time
216		finalconfig
217		;;
218	"Handbook")
219		bsdinstall docsinstall
220		finalconfig
221		;;
222	esac
223}
224
225# Allow user to change his mind
226finalconfig
227
228trap error SIGINT	# SIGINT is bad again
229bsdinstall config  || error
230
231if [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
232	[ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \
233	    umount "$BSDINSTALL_DISTDIR"
234	rm -rf "$BSDINSTALL_FETCHDEST"
235fi
236
237dialog --backtitle "FreeBSD Installer" --title "Manual Configuration" \
238    --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
239if [ $? -eq 0 ]; then
240	clear
241	mount -t devfs devfs "$BSDINSTALL_CHROOT/dev"
242	echo This shell is operating in a chroot in the new system. \
243	    When finished making configuration changes, type \"exit\".
244	chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1
245fi
246
247bsdinstall entropy
248bsdinstall umount
249
250echo "Installation Completed at $(date)" >> $BSDINSTALL_LOG
251
252