3 # Copyright (c) 2013 Nathan Whitehorn
4 # Copyright (c) 2013-2015 Devin Teske
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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.
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
29 ############################################################ INCLUDES
31 BSDCFG_SHARE="/usr/share/bsdconfig"
32 . $BSDCFG_SHARE/common.subr || exit 1
33 f_dprintf "%s: loading includes..." "$0"
34 f_include $BSDCFG_SHARE/dialog.subr
35 f_include $BSDCFG_SHARE/variable.subr
37 ############################################################ CONFIGURATION
45 # Default name of the ZFS boot-pool
47 : ${ZFSBOOT_POOL_NAME:=zroot}
49 ############################################################ GLOBALS
54 # Strings that should be moved to an i18n file and loaded with f_include_lang()
56 msg_installation_error="Installation Error!"
58 ############################################################ FUNCTIONS
63 f_getvar "$VAR_DEBUG_FILE#+" file
65 f_dialog_title "$msg_installation_error"
66 f_dialog_textbox "$file"
67 # No need to restore title, pining for the fjords
70 [ -f "$PATH_FSTAB" ] || exit
71 if [ "$ZFSBOOT_DISKS" ]; then
72 zpool export $ZFSBOOT_POOL_NAME
80 ############################################################ MAIN
88 f_dprintf "Began Installation at %s" "$( date )"
89 rm -rf $BSDINSTALL_TMPETC
90 mkdir $BSDINSTALL_TMPETC
92 split -a 2 -p '^#!.*' "$SCRIPT" $TMPDIR/bsdinstall-installscript-
94 . $TMPDIR/bsdinstall-installscript-aa
95 : ${DISTRIBUTIONS="kernel.txz base.txz"}; export DISTRIBUTIONS
96 export BSDINSTALL_DISTDIR
98 # Re-initialize a new log if preamble changed BSDINSTALL_LOG
99 if [ "$BSDINSTALL_LOG" != "${debugFile#+}" ]; then
100 export debugFile="$BSDINSTALL_LOG"
101 f_quietly f_debug_init
102 # NB: Being scripted, let debug go to terminal for invalid debugFile
103 f_dprintf "Began Installation at %s" "$( date )"
109 if [ "$ZFSBOOT_DISKS" ]; then
112 bsdinstall scriptedpart "$PARTITIONS"
116 # Fetch missing distribution files, if any
119 export BSDINSTALL_DISTDIR=$(`dirname $0`/fetchmissingdists 2>&1 1>&3)
123 ) || error "Could not fetch remote distributions"
125 # Unpack distributions
128 # If install is a tty, use distextract as normal
129 bsdinstall distextract
131 # Otherwise, we need to use tar (see https://reviews.freebsd.org/D10736)
132 for set in $DISTRIBUTIONS; do
133 f_dprintf "Extracting $BSDINSTALL_DISTDIR/$set"
134 # XXX: The below fails if any mountpoints are FAT, due to
135 # inability to set ctime/mtime on the root of FAT partitions,
136 # which is needed to support e.g. EFI system partitions. tar has
137 # no option to ignore this (distextract ignores them internally
138 # through a hack), and returns 1 on any warning or error,
139 # effectively turning all warnings into fatal errors.
141 # Work around this in an extremely lame way for the specific
142 # case of EFI system partitions only. This *ONLY WORKS* if
143 # /boot/efi is empty and does not handle analagous problems on
144 # other systems (ARM, PPC64).
145 tar -xf "$BSDINSTALL_DISTDIR/$set" -C $BSDINSTALL_CHROOT --exclude boot/efi
146 mkdir -p $BSDINSTALL_CHROOT/boot/efi
150 # Configure bootloader if needed
151 bsdinstall bootconfig
156 # Make sure networking is functional, if we can arrange that
157 if [ ! -f $BSDINSTALL_CHROOT/etc/resolv.conf -a -f /etc/resolv.conf ]; then
158 cp /etc/resolv.conf $BSDINSTALL_CHROOT/etc/resolv.conf
161 # Run post-install script
162 if [ -f $TMPDIR/bsdinstall-installscript-ab ]; then
163 cp $TMPDIR/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/tmp/installscript
164 chmod a+x $BSDINSTALL_CHROOT/tmp/installscript
165 chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1
166 rm $BSDINSTALL_CHROOT/tmp/installscript
171 if [ "$ZFSBOOT_DISKS" ]; then
172 zpool export $ZFSBOOT_POOL_NAME
175 f_dprintf "Installation Completed at %s" "$( date )"
180 ################################################################################
182 ################################################################################