]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - usr.sbin/bsdinstall/scripts/script
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / usr.sbin / bsdinstall / scripts / script
1 #!/bin/sh
2 #-
3 # Copyright (c) 2013 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 f_dprintf "%s: loading includes..." "$0"
35 f_include $BSDCFG_SHARE/dialog.subr
36 f_include $BSDCFG_SHARE/variable.subr
37
38 ############################################################ CONFIGURATION
39
40 # VARIABLES:
41 # PARTITIONS
42 # DISTRIBUTIONS
43 # BSDINSTALL_DISTDIR
44
45 ############################################################ GLOBALS
46
47 #
48 # Strings that should be moved to an i18n file and loaded with f_include_lang()
49 #
50 msg_installation_error="Installation Error!"
51
52 ############################################################ FUNCTIONS
53
54 error()
55 {
56         [ -f "$PATH_FSTAB" ] && bsdinstall umount
57         
58         local file
59         f_getvar "$VAR_DEBUG_FILE#+" file
60         if [ "$file" ]; then
61                 f_dialog_title "$msg_installation_error"
62                 f_dialog_textbox "$file"
63                 # No need to restore title, pining for the fjords
64         fi
65
66         exit 1
67 }
68
69 ############################################################ MAIN
70
71 set -e
72 trap error EXIT
73
74 SCRIPT="$1"
75 shift
76
77 f_dprintf "Began Installation at %s" "$( date )"
78 rm -rf $BSDINSTALL_TMPETC
79 mkdir $BSDINSTALL_TMPETC
80
81 split -a 2 -p '^#!.*' "$SCRIPT" /tmp/bsdinstall-installscript-
82
83 . /tmp/bsdinstall-installscript-aa
84 : ${DISTRIBUTIONS="kernel.txz base.txz"}; export DISTRIBUTIONS
85 export BSDINSTALL_DISTDIR
86
87 # Re-initialize a new log if preamble changed BSDINSTALL_LOG
88 if [ "$BSDINSTALL_LOG" != "${debugFile#+}" ]; then
89         export debugFile="$BSDINSTALL_LOG"
90         f_quietly f_debug_init
91         # NB: Being scripted, let debug go to terminal for invalid debugFile
92         f_dprintf "Began Instalation at %s" "$( date )"
93 fi
94
95 # Make partitions
96 rm -f $PATH_FSTAB
97 touch $PATH_FSTAB
98 if [ "$ZFSBOOT_DISKS" ]; then
99         bsdinstall zfsboot
100 else
101         bsdinstall scriptedpart "$PARTITIONS"
102 fi
103 bsdinstall mount
104
105 # Unpack distributions
106 bsdinstall checksum
107 bsdinstall distextract
108
109 # Finalize install
110 bsdinstall config
111
112 # Make sure networking is functional, if we can arrange that
113 if [ ! -f $BSDINSTALL_CHROOT/etc/resolv.conf -a -f /etc/resolv.conf ]; then
114         cp /etc/resolv.conf $BSDINSTALL_CHROOT/etc/resolv.conf
115 fi
116
117 # Run post-install script
118 if [ -f /tmp/bsdinstall-installscript-ab ]; then
119         cp /tmp/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/tmp/installscript
120         chmod a+x $BSDINSTALL_CHROOT/tmp/installscript
121         mount -t devfs devfs "$BSDINSTALL_CHROOT/dev"
122         chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1
123         umount "$BSDINSTALL_CHROOT/dev"
124         rm $BSDINSTALL_CHROOT/tmp/installscript
125 fi
126
127 bsdinstall entropy
128 bsdinstall umount
129
130 f_dprintf "Installation Completed at %s" "$( date )"
131
132 trap true EXIT
133
134 ################################################################################
135 # END
136 ################################################################################