xref: /freebsd/usr.sbin/bsdinstall/scripts/auto (revision aa0a1e58)
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$
28
29echo "Begun Installation at $(date)" > $BSDINSTALL_LOG
30
31error() {
32	dialog --backtitle "FreeBSD Installer" --title "Abort" \
33	    --no-label "Exit" --yes-label "Restart" --yesno \
34	    "An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
35	if [ $? -ne 0 ]; then
36		exit
37	else
38		test -f $PATH_FSTAB && bsdinstall umount
39		exec $0
40	fi
41}
42
43
44rm -rf $BSDINSTALL_TMPETC
45mkdir $BSDINSTALL_TMPETC
46
47trap true SIGINT	# This section is optional
48bsdinstall keymap
49
50trap error SIGINT	# Catch cntrl-C here
51bsdinstall hostname || error
52
53export DISTRIBUTIONS="base.txz kernel.txz"
54if [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
55	DISTMENU=`cut -f 4,5,6 $BSDINSTALL_DISTDIR/MANIFEST | grep -v -e ^kernel -e ^base`
56
57	exec 3>&1
58	EXTRA_DISTS=$(echo $DISTMENU | xargs dialog \
59	    --backtitle "FreeBSD Installer" \
60	    --title "Distribution Select" --nocancel --separate-output \
61	    --checklist "Choose optional system components to install:" \
62	    0 0 0 \
63	2>&1 1>&3)
64	for dist in $EXTRA_DISTS; do
65		export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
66	done
67fi
68
69FETCH_DISTRIBUTIONS=""
70for dist in $DISTRIBUTIONS; do
71	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
72		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
73	fi
74done
75
76if [ ! -z "$FETCH_DISTRIBUTIONS" -a ! -z $BSDINSTALL_CONFIGCURRENT ]; then
77	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
78	bsdinstall netconfig || error
79	NETCONFIG_DONE=yes
80fi
81
82rm $PATH_FSTAB
83touch $PATH_FSTAB
84
85dialog --backtitle "FreeBSD Installer" --title "Partitioning" --extra-button \
86    --extra-label "Manual" --ok-label "Guided" --cancel-label "Shell" \
87    --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
88
89case $? in
900)	# Guided
91	bsdinstall autopart || error
92	bsdinstall mount || error
93	;;
941)	# Shell
95	clear
96	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'."
97	sh
98	;;
993)	# Manual
100	bsdinstall partedit || error
101	bsdinstall mount || error
102	;;
103*)
104	error
105	;;
106esac
107
108if [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
109	ALL_DISTRIBUTIONS="$DISTRIBUTIONS"
110
111	# Download to a directory in the new system as scratch space
112	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
113	mkdir -p "$BSDINSTALL_FETCHDEST" || error
114
115	export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
116	# Try to use any existing distfiles
117	[ -d $BSDINSTALL_DISTDIR -a "$FETCH_DISTRIBUTIONS" != "$ALL_DISTRIBUTIONS" ] && mount_unionfs "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
118
119	# Otherwise, fetch everything
120	if [ $? -ne 0 ]; then
121		export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
122		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
123	fi
124
125	bsdinstall distfetch || error
126	export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
127fi
128
129bsdinstall checksum || error
130bsdinstall distextract || error
131bsdinstall rootpass || error
132
133trap true SIGINT	# This section is optional
134if [ "$NETCONFIG_DONE" != yes ]; then
135	bsdinstall netconfig	# Don't check for errors -- the user may cancel
136fi
137bsdinstall time
138bsdinstall services
139
140dialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
141    "Would you like to add users to the installed system now?" 0 0 && \
142    bsdinstall adduser
143
144finalconfig() {
145	exec 3>&1
146	REVISIT=$(dialog --backtitle "FreeBSD Installer" \
147	    --title "Final Configuration" --no-cancel --menu \
148	    "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 \
149		"Add User" "Add a user to the system" \
150		"Root Password" "Change root password" \
151		"Hostname" "Set system hostname" \
152		"Network" "Networking configuration" \
153		"Services" "Set daemons to run on startup" \
154		"Time Zone" "Set system timezone" \
155		"Shell" "Open a shell in the new system" \
156		"Reboot" "Apply configuration and reboot" 2>&1 1>&3)
157	exec 3>&-
158
159	case "$REVISIT" in
160	"Add User")
161		bsdinstall adduser
162		finalconfig
163		;;
164	"Root Password")
165		bsdinstall rootpass
166		finalconfig
167		;;
168	"Hostname")
169		bsdinstall hostname
170		finalconfig
171		;;
172	"Network")
173		bsdinstall netconfig
174		finalconfig
175		;;
176	"Services")
177		bsdinstall services
178		finalconfig
179		;;
180	"Time Zone")
181		bsdinstall time
182		finalconfig
183		;;
184	"Shell")
185		clear
186		echo This shell is operating in a chroot in the new system. \
187		    When finished making configuration changes, type \"exit\".
188		chroot "$BSDINSTALL_CHROOT" /bin/sh
189		# Don't hose local rc.conf changes
190		cp $BSDINSTALL_CHROOT/etc/rc.conf $BSDINSTALL_TMPETC/rc.conf.manual
191		finalconfig
192		;;
193	esac
194}
195
196# Allow user to change his mind
197finalconfig
198
199trap error SIGINT	# SIGINT is bad again
200bsdinstall config  || error
201
202if [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
203	[ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \
204	    umount "$BSDINSTALL_DISTDIR"
205	rm -rf "$BSDINSTALL_FETCHDEST"
206fi
207
208echo "Installation Completed at $(date)" >> $BSDINSTALL_LOG
209
210