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