aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/bsdinstall/scripts/auto
blob: a4c5c821c453d36633a7d3743ab2f177d22552d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/sh
#-
# Copyright (c) 2011 Nathan Whitehorn
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$

echo "Begun Installation at $(date)" > $BSDINSTALL_LOG

error() {
	dialog --backtitle "FreeBSD Installer" --title "Abort" \
	    --no-label "Exit" --yes-label "Restart" --yesno \
	    "An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
	if [ $? -ne 0 ]; then
		exit
	else
		test -f $PATH_FSTAB && bsdinstall umount
		exec $0
	fi
}


rm -rf $BSDINSTALL_TMPETC
mkdir $BSDINSTALL_TMPETC

trap true SIGINT	# This section is optional
bsdinstall keymap

trap error SIGINT	# Catch cntrl-C here
bsdinstall hostname || error

LIB32=""
[ `uname -p` = amd64 -o `uname -p` = powerpc64 ] && \
    LIB32="lib32 \"32-bit compatibility\" on"

DISTMENU="doc	\"Additional documentation\" on \
	games	\"Games (fortune, etc.)\" on \
	$LIB32 \
	ports	\"Ports tree\" on \
	src	\"System source code\" off"

exec 3>&1
EXTRA_DISTS=$(echo $DISTMENU | xargs dialog --backtitle "FreeBSD Installer" \
    --title "Distribution Select" --nocancel --separate-output \
    --checklist "Choose optional system components to install:" \
    0 0 0 \
2>&1 1>&3)
export DISTRIBUTIONS="base.txz kernel.txz"
for dist in $EXTRA_DISTS; do
	export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
done

FETCH_DISTRIBUTIONS=""
for dist in $DISTRIBUTIONS; do
	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
	fi
done

if [ ! -z "$FETCH_DISTRIBUTIONS" -a ! -z $BSDINSTALL_CONFIGCURRENT ]; then
	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
	bsdinstall netconfig || error
	NETCONFIG_DONE=yes
fi

rm $PATH_FSTAB
touch $PATH_FSTAB

dialog --backtitle "FreeBSD Installer" --title "Partitioning" --extra-button \
    --extra-label "Manual" --ok-label "Guided" --cancel-label "Shell" \
    --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

case $? in
0)	# Guided
	bsdinstall autopart || error
	bsdinstall mount || error
	;;
1)	# Shell
	clear
	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'."
	sh
	;;
3)	# Manual
	bsdinstall partedit || error
	bsdinstall mount || error
	;;
*)
	error
	;;
esac

if [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
	ALL_DISTRIBUTIONS="$DISTRIBUTIONS"

	# Download to a directory in the new system as scratch space
	BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
	mkdir -p "$BSDINSTALL_FETCHDEST" || error

	export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
	# Try to use any existing distfiles
	[ -d $BSDINSTALL_DISTDIR -a "$FETCH_DISTRIBUTIONS" != "$ALL_DISTRIBUTIONS" ] && mount_unionfs "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"

	# Otherwise, fetch everything
	if [ $? -ne 0 ]; then
		export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
		export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
	fi
		
	bsdinstall distfetch || error
	export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
fi

bsdinstall distextract || error
bsdinstall rootpass || error

trap true SIGINT	# This section is optional
if [ "$NETCONFIG_DONE" != yes ]; then
	bsdinstall netconfig	# Don't check for errors -- the user may cancel
fi
bsdinstall time
bsdinstall services

dialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
    "Would you like to add users to the installed system now?" 0 0 && \
    bsdinstall adduser

finalconfig() {
	exec 3>&1
	REVISIT=$(dialog --backtitle "FreeBSD Installer" \
	    --title "Final Configuration" --no-cancel --menu \
	    "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 \
		"Add User" "Add a user to the system" \
		"Root Password" "Change root password" \
		"Hostname" "Set system hostname" \
		"Network" "Networking configuration" \
		"Services" "Set daemons to run on startup" \
		"Time Zone" "Set system timezone" \
		"Shell" "Open a shell in the new system" \
		"Reboot" "Apply configuration and reboot" 2>&1 1>&3)
	exec 3>&-

	case "$REVISIT" in
	"Add User")
		bsdinstall adduser
		finalconfig
		;;
	"Root Password")
		bsdinstall rootpass 
		finalconfig
		;;
	"Hostname")
		bsdinstall hostname
		finalconfig
		;;
	"Network")
		bsdinstall netconfig
		finalconfig
		;;
	"Services")
		bsdinstall services
		finalconfig
		;;
	"Time Zone")
		bsdinstall time
		finalconfig
		;;
	"Shell")
		clear
		echo This shell is operating in a chroot in the new system. \
		    When finished making configuration changes, type \"exit\".
		chroot "$BSDINSTALL_CHROOT" /bin/sh
		# Don't hose local rc.conf changes
		cp $BSDINSTALL_CHROOT/etc/rc.conf $BSDINSTALL_TMPETC/rc.conf.manual
		finalconfig
		;;
	esac
}

# Allow user to change his mind
finalconfig

trap error SIGINT	# SIGINT is bad again
bsdinstall config  || error

if [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
	[ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \
	    umount "$BSDINSTALL_DISTDIR"
	rm -rf "$BSDINSTALL_FETCHDEST"
fi

echo "Installation Completed at $(date)" >> $BSDINSTALL_LOG