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
30 ############################################################ INCLUDES
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
38 ############################################################ CONFIGURATION
46 # Default name of the ZFS boot-pool
48 : ${ZFSBOOT_POOL_NAME:=zroot}
50 ############################################################ GLOBALS
55 # Strings that should be moved to an i18n file and loaded with f_include_lang()
57 msg_installation_error="Installation Error!"
59 ############################################################ FUNCTIONS
64 f_getvar "$VAR_DEBUG_FILE#+" file
66 f_dialog_title "$msg_installation_error"
67 f_dialog_textbox "$file"
68 # No need to restore title, pining for the fjords
71 [ -f "$PATH_FSTAB" ] || exit
72 if [ "$ZFSBOOT_DISKS" ]; then
73 zpool export $ZFSBOOT_POOL_NAME
81 ############################################################ MAIN
89 f_dprintf "Began Installation at %s" "$( date )"
90 rm -rf $BSDINSTALL_TMPETC
91 mkdir $BSDINSTALL_TMPETC
93 split -a 2 -p '^#!.*' "$SCRIPT" $TMPDIR/bsdinstall-installscript-
95 . $TMPDIR/bsdinstall-installscript-aa
96 : ${DISTRIBUTIONS="kernel.txz base.txz"}; export DISTRIBUTIONS
97 export BSDINSTALL_DISTDIR
99 # Re-initialize a new log if preamble changed BSDINSTALL_LOG
100 if [ "$BSDINSTALL_LOG" != "${debugFile#+}" ]; then
101 export debugFile="$BSDINSTALL_LOG"
102 f_quietly f_debug_init
103 # NB: Being scripted, let debug go to terminal for invalid debugFile
104 f_dprintf "Began Instalation at %s" "$( date )"
110 if [ "$ZFSBOOT_DISKS" ]; then
113 bsdinstall scriptedpart "$PARTITIONS"
117 # Unpack distributions
119 for set in $DISTRIBUTIONS; do
120 f_dprintf "Extracting $BSDINSTALL_DISTDIR/$set"
121 # XXX: this will fail if any mountpoints are FAT, due to inability to
122 # set ctime/mtime on the root of FAT partitions. tar has no option to
123 # ignore this. We probably need to switch back to distextract here
124 # to properly support EFI.
125 tar -xf "$BSDINSTALL_DISTDIR/$set" -C $BSDINSTALL_CHROOT
128 # Configure bootloader if needed
129 bsdinstall bootconfig
134 # Make sure networking is functional, if we can arrange that
135 if [ ! -f $BSDINSTALL_CHROOT/etc/resolv.conf -a -f /etc/resolv.conf ]; then
136 cp /etc/resolv.conf $BSDINSTALL_CHROOT/etc/resolv.conf
139 # Run post-install script
140 if [ -f $TMPDIR/bsdinstall-installscript-ab ]; then
141 cp $TMPDIR/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/tmp/installscript
142 chmod a+x $BSDINSTALL_CHROOT/tmp/installscript
143 mount -t devfs devfs "$BSDINSTALL_CHROOT/dev"
144 chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1
145 umount "$BSDINSTALL_CHROOT/dev"
146 rm $BSDINSTALL_CHROOT/tmp/installscript
150 if [ "$ZFSBOOT_DISKS" ]; then
151 zpool export $ZFSBOOT_POOL_NAME
156 f_dprintf "Installation Completed at %s" "$( date )"
161 ################################################################################
163 ################################################################################