]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/bsdinstall/scripts/script
Update ELF Tool Chain to upstream r3769
[FreeBSD/FreeBSD.git] / usr.sbin / bsdinstall / scripts / script
1 #!/bin/sh
2 #-
3 # Copyright (c) 2013 Nathan Whitehorn
4 # Copyright (c) 2013-2015 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 #
46 # Default name of the ZFS boot-pool
47 #
48 : ${ZFSBOOT_POOL_NAME:=zroot}
49
50 ############################################################ GLOBALS
51
52 #
53 # Strings that should be moved to an i18n file and loaded with f_include_lang()
54 #
55 msg_installation_error="Installation Error!"
56
57 ############################################################ FUNCTIONS
58
59 error()
60 {
61         local file
62         f_getvar "$VAR_DEBUG_FILE#+" file
63         if [ "$file" ]; then
64                 f_dialog_title "$msg_installation_error"
65                 f_dialog_textbox "$file"
66                 # No need to restore title, pining for the fjords
67         fi
68
69         [ -f "$PATH_FSTAB" ] || exit
70         if [ "$ZFSBOOT_DISKS" ]; then
71                 zpool export $ZFSBOOT_POOL_NAME
72         else
73                 bsdinstall umount
74         fi
75
76         exit 1
77 }
78
79 ############################################################ MAIN
80
81 set -e
82 trap error EXIT
83
84 SCRIPT="$1"
85 shift
86
87 f_dprintf "Began Installation at %s" "$( date )"
88 rm -rf $BSDINSTALL_TMPETC
89 mkdir $BSDINSTALL_TMPETC
90
91 split -a 2 -p '^#!.*' "$SCRIPT" /tmp/bsdinstall-installscript-
92
93 . /tmp/bsdinstall-installscript-aa
94 : ${DISTRIBUTIONS="kernel.txz base.txz"}; export DISTRIBUTIONS
95 export BSDINSTALL_DISTDIR
96
97 # Re-initialize a new log if preamble changed BSDINSTALL_LOG
98 if [ "$BSDINSTALL_LOG" != "${debugFile#+}" ]; then
99         export debugFile="$BSDINSTALL_LOG"
100         f_quietly f_debug_init
101         # NB: Being scripted, let debug go to terminal for invalid debugFile
102         f_dprintf "Began Instalation at %s" "$( date )"
103 fi
104
105 # Make partitions
106 rm -f $PATH_FSTAB
107 touch $PATH_FSTAB
108 if [ "$ZFSBOOT_DISKS" ]; then
109         bsdinstall zfsboot
110 else
111         bsdinstall scriptedpart "$PARTITIONS"
112         bsdinstall mount
113 fi
114
115 # Unpack distributions
116 bsdinstall checksum
117 for set in $DISTRIBUTIONS; do
118         f_dprintf "Extracting $BSDINSTALL_DISTDIR/$set"
119         # XXX: this will fail if any mountpoints are FAT, due to inability to
120         # set ctime/mtime on the root of FAT partitions. tar has no option to
121         # ignore this. We probably need to switch back to distextract here
122         # to properly support EFI.
123         tar -xf "$BSDINSTALL_DISTDIR/$set" -C $BSDINSTALL_CHROOT
124 done
125
126 # Configure bootloader if needed
127 bsdinstall bootconfig
128
129 # Finalize install
130 bsdinstall config
131
132 # Make sure networking is functional, if we can arrange that
133 if [ ! -f $BSDINSTALL_CHROOT/etc/resolv.conf -a -f /etc/resolv.conf ]; then
134         cp /etc/resolv.conf $BSDINSTALL_CHROOT/etc/resolv.conf
135 fi
136
137 # Run post-install script
138 if [ -f /tmp/bsdinstall-installscript-ab ]; then
139         cp /tmp/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/tmp/installscript
140         chmod a+x $BSDINSTALL_CHROOT/tmp/installscript
141         mount -t devfs devfs "$BSDINSTALL_CHROOT/dev"
142         chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1
143         umount "$BSDINSTALL_CHROOT/dev"
144         rm $BSDINSTALL_CHROOT/tmp/installscript
145 fi
146
147 bsdinstall entropy
148 if [ "$ZFSBOOT_DISKS" ]; then
149         zpool export $ZFSBOOT_POOL_NAME
150 else
151         bsdinstall umount
152 fi
153
154 f_dprintf "Installation Completed at %s" "$( date )"
155
156 trap - EXIT
157 exit $SUCCESS
158
159 ################################################################################
160 # END
161 ################################################################################