auto revision 232531
1178476Sjb#!/bin/sh
2178476Sjb#-
3178476Sjb# Copyright (c) 2011 Nathan Whitehorn
4178476Sjb# All rights reserved.
5178476Sjb#
6178476Sjb# Redistribution and use in source and binary forms, with or without
7178476Sjb# modification, are permitted provided that the following conditions
8178476Sjb# are met:
9178476Sjb# 1. Redistributions of source code must retain the above copyright
10178476Sjb#    notice, this list of conditions and the following disclaimer.
11178476Sjb# 2. Redistributions in binary form must reproduce the above copyright
12178476Sjb#    notice, this list of conditions and the following disclaimer in the
13178476Sjb#    documentation and/or other materials provided with the distribution.
14178476Sjb#
15178476Sjb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16178476Sjb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17178476Sjb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18178476Sjb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19178476Sjb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20178476Sjb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21178476Sjb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22178476Sjb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23178476Sjb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24178476Sjb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25178476Sjb# SUCH DAMAGE.
26178476Sjb#
27178476Sjb# $FreeBSD: head/usr.sbin/bsdinstall/scripts/auto 232531 2012-03-05 02:40:18Z nwhitehorn $
28178476Sjb
29178476Sjbecho "Begun Installation at $(date)" > $BSDINSTALL_LOG
30178476Sjb
31178476Sjberror() {
32178476Sjb	test -n "$DISTDIR_IS_UNIONFS" && umount -f $BSDINSTALL_DISTDIR
33178476Sjb	test -f $PATH_FSTAB && bsdinstall umount
34178476Sjb	dialog --backtitle "FreeBSD Installer" --title "Abort" \
35178476Sjb	    --no-label "Exit" --yes-label "Restart" --yesno \
36178476Sjb	    "An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
37178476Sjb	if [ $? -ne 0 ]; then
38178476Sjb		exit 1
39178476Sjb	else
40178476Sjb		exec $0
41178476Sjb	fi
42178476Sjb}
43178476Sjb
44178476Sjb
45178476Sjbrm -rf $BSDINSTALL_TMPETC
46178476Sjbmkdir $BSDINSTALL_TMPETC
47178476Sjb
48178476Sjbtrap true SIGINT	# This section is optional
49178476Sjbbsdinstall keymap
50178476Sjb
51178476Sjbtrap error SIGINT	# Catch cntrl-C here
52178476Sjbbsdinstall hostname || error
53178476Sjb
54178476Sjbexport DISTRIBUTIONS="base.txz kernel.txz"
55178476Sjbif [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
56178476Sjb	DISTMENU=`cut -f 4,5,6 $BSDINSTALL_DISTDIR/MANIFEST | grep -v -e ^kernel -e ^base`
57178476Sjb
58178476Sjb	exec 3>&1
59178476Sjb	EXTRA_DISTS=$(echo $DISTMENU | xargs dialog \
60178476Sjb	    --backtitle "FreeBSD Installer" \
61178476Sjb	    --title "Distribution Select" --nocancel --separate-output \
62178476Sjb	    --checklist "Choose optional system components to install:" \
63178476Sjb	    0 0 0 \
64178476Sjb	2>&1 1>&3)
65178476Sjb	for dist in $EXTRA_DISTS; do
66178476Sjb		export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
67178476Sjb	done
68178476Sjbfi
69178476Sjb
70178476SjbFETCH_DISTRIBUTIONS=""
71178476Sjbfor dist in $DISTRIBUTIONS; do
72178476Sjb	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
73178476Sjb		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
74178476Sjb	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
96dialog --backtitle "FreeBSD Installer" --title "Partitioning" --extra-button \
97    --extra-label "Manual" --ok-label "Guided" --cancel-label "Shell" \
98    --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
99
100case $? in
1010)	# Guided
102	bsdinstall autopart || error
103	bsdinstall mount || error
104	;;
1051)	# Shell
106	clear
107	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'."
108	sh 2>&1
109	;;
1103)	# Manual
111	bsdinstall partedit || error
112	bsdinstall mount || error
113	;;
114*)
115	error
116	;;
117esac
118
119if [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
120	ALL_DISTRIBUTIONS="$DISTRIBUTIONS"
121
122	# Download to a directory in the new system as scratch space
123	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
124	mkdir -p "$BSDINSTALL_FETCHDEST" || error
125
126	export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
127	# Try to use any existing distfiles
128	if [ -d $BSDINSTALL_DISTDIR ]; then
129		DISTDIR_IS_UNIONFS=1
130		mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
131	else
132		export DISTRIBUTIONS="MANIFEST $ALL_DISTRIBUTIONS"
133		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
134	fi
135		
136	export FTP_PASSIVE_MODE=YES
137	bsdinstall distfetch || error
138	export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
139fi
140
141bsdinstall checksum || error
142bsdinstall distextract || error
143bsdinstall rootpass || error
144
145trap true SIGINT	# This section is optional
146if [ "$NETCONFIG_DONE" != yes ]; then
147	bsdinstall netconfig	# Don't check for errors -- the user may cancel
148fi
149bsdinstall time
150bsdinstall services
151
152dialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
153    "Would you like to add users to the installed system now?" 0 0 && \
154    bsdinstall adduser
155
156finalconfig() {
157	exec 3>&1
158	REVISIT=$(dialog --backtitle "FreeBSD Installer" \
159	    --title "Final Configuration" --no-cancel --menu \
160	    "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 \
161		"Exit" "Apply configuration and exit installer" \
162		"Add User" "Add a user to the system" \
163		"Root Password" "Change root password" \
164		"Hostname" "Set system hostname" \
165		"Network" "Networking configuration" \
166		"Services" "Set daemons to run on startup" \
167		"Time Zone" "Set system timezone" \
168		"Handbook" "Install FreeBSD Handbook (requires network)" 2>&1 1>&3)
169	exec 3>&-
170
171	case "$REVISIT" in
172	"Add User")
173		bsdinstall adduser
174		finalconfig
175		;;
176	"Root Password")
177		bsdinstall rootpass 
178		finalconfig
179		;;
180	"Hostname")
181		bsdinstall hostname
182		finalconfig
183		;;
184	"Network")
185		bsdinstall netconfig
186		finalconfig
187		;;
188	"Services")
189		bsdinstall services
190		finalconfig
191		;;
192	"Time Zone")
193		bsdinstall time
194		finalconfig
195		;;
196	"Handbook")
197		bsdinstall docsinstall
198		finalconfig
199		;;
200	esac
201}
202
203# Allow user to change his mind
204finalconfig
205
206trap error SIGINT	# SIGINT is bad again
207bsdinstall config  || error
208
209if [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
210	[ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \
211	    umount "$BSDINSTALL_DISTDIR"
212	rm -rf "$BSDINSTALL_FETCHDEST"
213fi
214
215dialog --backtitle "FreeBSD Installer" --title "Manual Configuration" \
216    --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
217if [ $? -eq 0 ]; then
218	clear
219	mount -t devfs devfs "$BSDINSTALL_CHROOT/dev"
220	echo This shell is operating in a chroot in the new system. \
221	    When finished making configuration changes, type \"exit\".
222	chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1
223fi
224
225echo "Installation Completed at $(date)" >> $BSDINSTALL_LOG
226
227