auto revision 219528
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 219528 2011-03-11 19:40:49Z nwhitehorn $
28218799Snwhitehorn
29218799Snwhitehornecho "Begun Installation at $(date)" > $BSDINSTALL_LOG
30218799Snwhitehorn
31218799Snwhitehornerror() {
32218799Snwhitehorn	dialog --backtitle "FreeBSD Installer" --title "Abort" \
33218799Snwhitehorn	    --no-label "Exit" --yes-label "Restart" --yesno \
34218799Snwhitehorn	    "An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
35218799Snwhitehorn	if [ $? -ne 0 ]; then
36218799Snwhitehorn		exit
37218799Snwhitehorn	else
38218799Snwhitehorn		test -f $PATH_FSTAB && bsdinstall umount
39218799Snwhitehorn		exec $0
40218799Snwhitehorn	fi
41218799Snwhitehorn}
42218799Snwhitehorn
43218799Snwhitehorn
44218799Snwhitehornrm -rf $BSDINSTALL_TMPETC
45218799Snwhitehornmkdir $BSDINSTALL_TMPETC
46218799Snwhitehorn
47218799Snwhitehorntrap true SIGINT	# This section is optional
48218799Snwhitehornbsdinstall keymap
49218799Snwhitehorn
50218799Snwhitehorntrap error SIGINT	# Catch cntrl-C here
51218799Snwhitehornbsdinstall hostname || error
52218799Snwhitehorn
53218947SnwhitehornLIB32=""
54218947Snwhitehorn[ `uname -p` = amd64 -o `uname -p` = powerpc64 ] && \
55218947Snwhitehorn    LIB32="lib32 \"32-bit compatibility\" on"
56218947Snwhitehorn
57218947SnwhitehornDISTMENU="doc	\"Additional documentation\" on \
58218947Snwhitehorn	games	\"Games (fortune, etc.)\" on \
59218947Snwhitehorn	$LIB32 \
60218947Snwhitehorn	ports	\"Ports tree\" on \
61218947Snwhitehorn	src	\"System source code\" off"
62218947Snwhitehorn
63218947Snwhitehornexec 3>&1
64218947SnwhitehornEXTRA_DISTS=$(echo $DISTMENU | xargs dialog --backtitle "FreeBSD Installer" \
65218947Snwhitehorn    --title "Distribution Select" --nocancel --separate-output \
66218947Snwhitehorn    --checklist "Choose optional system components to install:" \
67218947Snwhitehorn    0 0 0 \
68218947Snwhitehorn2>&1 1>&3)
69219179Snwhitehornexport DISTRIBUTIONS="base.txz kernel.txz"
70218947Snwhitehornfor dist in $EXTRA_DISTS; do
71218947Snwhitehorn	export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
72218947Snwhitehorndone
73218947Snwhitehorn
74218799SnwhitehornFETCH_DISTRIBUTIONS=""
75218799Snwhitehornfor dist in $DISTRIBUTIONS; do
76218799Snwhitehorn	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
77218799Snwhitehorn		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
78218799Snwhitehorn	fi
79218799Snwhitehorndone
80218799Snwhitehorn
81218799Snwhitehornif [ ! -z "$FETCH_DISTRIBUTIONS" -a ! -z $BSDINSTALL_CONFIGCURRENT ]; then
82218799Snwhitehorn	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
83218799Snwhitehorn	bsdinstall netconfig || error
84218799Snwhitehorn	NETCONFIG_DONE=yes
85218799Snwhitehornfi
86218799Snwhitehorn
87218799Snwhitehornrm $PATH_FSTAB
88218799Snwhitehorntouch $PATH_FSTAB
89218799Snwhitehorn
90218799Snwhitehorndialog --backtitle "FreeBSD Installer" --title "Partitioning" --extra-button \
91218799Snwhitehorn    --extra-label "Manual" --ok-label "Guided" --cancel-label "Shell" \
92218799Snwhitehorn    --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
93218799Snwhitehorn
94218799Snwhitehorncase $? in
95218799Snwhitehorn0)	# Guided
96218799Snwhitehorn	bsdinstall autopart || error
97218799Snwhitehorn	bsdinstall mount || error
98218799Snwhitehorn	;;
99218799Snwhitehorn1)	# Shell
100218799Snwhitehorn	clear
101218799Snwhitehorn	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'."
102218799Snwhitehorn	sh
103218799Snwhitehorn	;;
104218799Snwhitehorn3)	# Manual
105218799Snwhitehorn	bsdinstall partedit || error
106218799Snwhitehorn	bsdinstall mount || error
107218799Snwhitehorn	;;
108218799Snwhitehorn*)
109218799Snwhitehorn	error
110218799Snwhitehorn	;;
111218799Snwhitehornesac
112218799Snwhitehorn
113218799Snwhitehornif [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
114218799Snwhitehorn	ALL_DISTRIBUTIONS="$DISTRIBUTIONS"
115218799Snwhitehorn
116218799Snwhitehorn	# Download to a directory in the new system as scratch space
117219528Snwhitehorn	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
118218799Snwhitehorn	mkdir -p "$BSDINSTALL_FETCHDEST" || error
119218799Snwhitehorn
120218799Snwhitehorn	export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
121218799Snwhitehorn	# Try to use any existing distfiles
122218799Snwhitehorn	[ -d $BSDINSTALL_DISTDIR -a "$FETCH_DISTRIBUTIONS" != "$ALL_DISTRIBUTIONS" ] && mount_unionfs "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
123218799Snwhitehorn
124218799Snwhitehorn	# Otherwise, fetch everything
125218799Snwhitehorn	if [ $? -ne 0 ]; then
126218799Snwhitehorn		export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
127218799Snwhitehorn		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
128218799Snwhitehorn	fi
129218799Snwhitehorn		
130218799Snwhitehorn	bsdinstall distfetch || error
131218799Snwhitehorn	export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
132218799Snwhitehornfi
133218799Snwhitehorn
134218799Snwhitehornbsdinstall distextract || error
135218799Snwhitehornbsdinstall rootpass || error
136218799Snwhitehorn
137218799Snwhitehorntrap true SIGINT	# This section is optional
138218799Snwhitehornif [ "$NETCONFIG_DONE" != yes ]; then
139218799Snwhitehorn	bsdinstall netconfig	# Don't check for errors -- the user may cancel
140218799Snwhitehornfi
141218799Snwhitehornbsdinstall time
142218799Snwhitehornbsdinstall services
143218799Snwhitehorn
144218799Snwhitehorndialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
145218799Snwhitehorn    "Would you like to add users to the installed system now?" 0 0 && \
146218799Snwhitehorn    bsdinstall adduser
147218799Snwhitehorn
148218799Snwhitehornfinalconfig() {
149218799Snwhitehorn	exec 3>&1
150218799Snwhitehorn	REVISIT=$(dialog --backtitle "FreeBSD Installer" \
151218799Snwhitehorn	    --title "Final Configuration" --no-cancel --menu \
152218799Snwhitehorn	    "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 \
153218799Snwhitehorn		"Add User" "Add a user to the system" \
154218799Snwhitehorn		"Root Password" "Change root password" \
155218799Snwhitehorn		"Hostname" "Set system hostname" \
156218799Snwhitehorn		"Network" "Networking configuration" \
157218799Snwhitehorn		"Services" "Set daemons to run on startup" \
158218799Snwhitehorn		"Time Zone" "Set system timezone" \
159218799Snwhitehorn		"Shell" "Open a shell in the new system" \
160218799Snwhitehorn		"Reboot" "Apply configuration and reboot" 2>&1 1>&3)
161218799Snwhitehorn	exec 3>&-
162218799Snwhitehorn
163218799Snwhitehorn	case "$REVISIT" in
164218799Snwhitehorn	"Add User")
165218799Snwhitehorn		bsdinstall adduser
166218799Snwhitehorn		finalconfig
167218799Snwhitehorn		;;
168218799Snwhitehorn	"Root Password")
169218799Snwhitehorn		bsdinstall rootpass 
170218799Snwhitehorn		finalconfig
171218799Snwhitehorn		;;
172218799Snwhitehorn	"Hostname")
173218799Snwhitehorn		bsdinstall hostname
174218799Snwhitehorn		finalconfig
175218799Snwhitehorn		;;
176218799Snwhitehorn	"Network")
177218799Snwhitehorn		bsdinstall netconfig
178218799Snwhitehorn		finalconfig
179218799Snwhitehorn		;;
180218799Snwhitehorn	"Services")
181218799Snwhitehorn		bsdinstall services
182218799Snwhitehorn		finalconfig
183218799Snwhitehorn		;;
184218799Snwhitehorn	"Time Zone")
185218799Snwhitehorn		bsdinstall time
186218799Snwhitehorn		finalconfig
187218799Snwhitehorn		;;
188218799Snwhitehorn	"Shell")
189218799Snwhitehorn		clear
190218799Snwhitehorn		echo This shell is operating in a chroot in the new system. \
191218799Snwhitehorn		    When finished making configuration changes, type \"exit\".
192218799Snwhitehorn		chroot "$BSDINSTALL_CHROOT" /bin/sh
193218799Snwhitehorn		# Don't hose local rc.conf changes
194218799Snwhitehorn		cp $BSDINSTALL_CHROOT/etc/rc.conf $BSDINSTALL_TMPETC/rc.conf.manual
195218799Snwhitehorn		finalconfig
196218799Snwhitehorn		;;
197218799Snwhitehorn	esac
198218799Snwhitehorn}
199218799Snwhitehorn
200218799Snwhitehorn# Allow user to change his mind
201218799Snwhitehornfinalconfig
202218799Snwhitehorn
203218799Snwhitehorntrap error SIGINT	# SIGINT is bad again
204218799Snwhitehornbsdinstall config  || error
205218799Snwhitehorn
206218799Snwhitehornif [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
207218799Snwhitehorn	[ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \
208218799Snwhitehorn	    umount "$BSDINSTALL_DISTDIR"
209218799Snwhitehorn	rm -rf "$BSDINSTALL_FETCHDEST"
210218799Snwhitehornfi
211218799Snwhitehorn
212218799Snwhitehornecho "Installation Completed at $(date)" >> $BSDINSTALL_LOG
213218799Snwhitehorn
214