12ffbec18SNathan Whitehorn#!/bin/sh 22ffbec18SNathan Whitehorn#- 32ffbec18SNathan Whitehorn# Copyright (c) 2013 Nathan Whitehorn 4e5a24129SDevin Teske# Copyright (c) 2013-2015 Devin Teske 52ffbec18SNathan Whitehorn# All rights reserved. 62ffbec18SNathan Whitehorn# 72ffbec18SNathan Whitehorn# Redistribution and use in source and binary forms, with or without 82ffbec18SNathan Whitehorn# modification, are permitted provided that the following conditions 92ffbec18SNathan Whitehorn# are met: 102ffbec18SNathan Whitehorn# 1. Redistributions of source code must retain the above copyright 112ffbec18SNathan Whitehorn# notice, this list of conditions and the following disclaimer. 122ffbec18SNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright 132ffbec18SNathan Whitehorn# notice, this list of conditions and the following disclaimer in the 142ffbec18SNathan Whitehorn# documentation and/or other materials provided with the distribution. 152ffbec18SNathan Whitehorn# 162ffbec18SNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 172ffbec18SNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 182ffbec18SNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 192ffbec18SNathan Whitehorn# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 202ffbec18SNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 212ffbec18SNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 222ffbec18SNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 232ffbec18SNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 242ffbec18SNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 252ffbec18SNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 262ffbec18SNathan Whitehorn# SUCH DAMAGE. 272ffbec18SNathan Whitehorn# 28bc4a673fSDevin Teske# 29bc4a673fSDevin Teske############################################################ INCLUDES 30bc4a673fSDevin Teske 31bc4a673fSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 32bc4a673fSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 33bc4a673fSDevin Teskef_dprintf "%s: loading includes..." "$0" 34bc4a673fSDevin Teskef_include $BSDCFG_SHARE/dialog.subr 35bc4a673fSDevin Teskef_include $BSDCFG_SHARE/variable.subr 36bc4a673fSDevin Teske 37bc4a673fSDevin Teske############################################################ CONFIGURATION 382ffbec18SNathan Whitehorn 392ffbec18SNathan Whitehorn# VARIABLES: 402ffbec18SNathan Whitehorn# PARTITIONS 412ffbec18SNathan Whitehorn# DISTRIBUTIONS 422ffbec18SNathan Whitehorn# BSDINSTALL_DISTDIR 43dc14ae42SAlan Somers# COMPONENTS 442ffbec18SNathan Whitehorn 452f34d6c3SRoger Pau Monné# 462f34d6c3SRoger Pau Monné# Default name of the ZFS boot-pool 472f34d6c3SRoger Pau Monné# 482f34d6c3SRoger Pau Monné: ${ZFSBOOT_POOL_NAME:=zroot} 492f34d6c3SRoger Pau Monné 50bc4a673fSDevin Teske############################################################ GLOBALS 51bc4a673fSDevin Teske 52a107ddbbSRebecca Cran: ${TMPDIR:="/tmp"} 53283959bbSJose Luis Duran: ${DISTRIBUTIONS=""}; export DISTRIBUTIONS 54a107ddbbSRebecca Cran 55bc4a673fSDevin Teske# 56bc4a673fSDevin Teske# Strings that should be moved to an i18n file and loaded with f_include_lang() 57bc4a673fSDevin Teske# 58bc4a673fSDevin Teskemsg_installation_error="Installation Error!" 59bc4a673fSDevin Teske 60bc4a673fSDevin Teske############################################################ FUNCTIONS 61bc4a673fSDevin Teske 62bc4a673fSDevin Teskeerror() 63bc4a673fSDevin Teske{ 64bc4a673fSDevin Teske local file 65bc4a673fSDevin Teske f_getvar "$VAR_DEBUG_FILE#+" file 66bc4a673fSDevin Teske if [ "$file" ]; then 67bc4a673fSDevin Teske f_dialog_title "$msg_installation_error" 68bc4a673fSDevin Teske f_dialog_textbox "$file" 69bc4a673fSDevin Teske # No need to restore title, pining for the fjords 70bc4a673fSDevin Teske fi 71bc4a673fSDevin Teske 722f34d6c3SRoger Pau Monné [ -f "$PATH_FSTAB" ] || exit 732f34d6c3SRoger Pau Monné if [ "$ZFSBOOT_DISKS" ]; then 742f34d6c3SRoger Pau Monné zpool export $ZFSBOOT_POOL_NAME 752f34d6c3SRoger Pau Monné else 762f34d6c3SRoger Pau Monné bsdinstall umount 772f34d6c3SRoger Pau Monné fi 782f34d6c3SRoger Pau Monné 792ffbec18SNathan Whitehorn exit 1 802ffbec18SNathan Whitehorn} 812ffbec18SNathan Whitehorn 82bc4a673fSDevin Teske############################################################ MAIN 83bc4a673fSDevin Teske 842ffbec18SNathan Whitehornset -e 852ffbec18SNathan Whitehorntrap error EXIT 862ffbec18SNathan Whitehorn 872ffbec18SNathan WhitehornSCRIPT="$1" 882ffbec18SNathan Whitehornshift 892ffbec18SNathan Whitehorn 904c5d7fabSDevin Teskef_dprintf "Began Installation at %s" "$( date )" 912ffbec18SNathan Whitehornrm -rf $BSDINSTALL_TMPETC 922ffbec18SNathan Whitehornmkdir $BSDINSTALL_TMPETC 93731704f5SMichael Gmelinrm -f $TMPDIR/bsdinstall-installscript-setup 942ffbec18SNathan Whitehorn 95731704f5SMichael Gmelin# split script into preamble and setup script at first shebang 96731704f5SMichael Gmelinawk 'BEGIN {pathb=ARGV[2]; ARGV[2]=""} /^#!/{b=1} { 97731704f5SMichael Gmelin if (b) print >pathb; else print}' \ 98731704f5SMichael Gmelin "$SCRIPT" $TMPDIR/bsdinstall-installscript-setup \ 99731704f5SMichael Gmelin >$TMPDIR/bsdinstall-installscript-preamble 1002ffbec18SNathan Whitehorn 101*70c9d047SStephen J. Kiernan: ${BSDINSTALL_LOG="${debugFile#+}"} 102731704f5SMichael Gmelin. $TMPDIR/bsdinstall-installscript-preamble 1032ffbec18SNathan Whitehornexport BSDINSTALL_DISTDIR 1042ffbec18SNathan Whitehorn 105bc4a673fSDevin Teske# Re-initialize a new log if preamble changed BSDINSTALL_LOG 106bc4a673fSDevin Teskeif [ "$BSDINSTALL_LOG" != "${debugFile#+}" ]; then 107bc4a673fSDevin Teske export debugFile="$BSDINSTALL_LOG" 108bc4a673fSDevin Teske f_quietly f_debug_init 109bc4a673fSDevin Teske # NB: Being scripted, let debug go to terminal for invalid debugFile 1105104dfbeSNavdeep Parhar f_dprintf "Began Installation at %s" "$( date )" 111bc4a673fSDevin Teskefi 112bc4a673fSDevin Teske 1132ffbec18SNathan Whitehorn# Make partitions 1142ffbec18SNathan Whitehornrm -f $PATH_FSTAB 1152ffbec18SNathan Whitehorntouch $PATH_FSTAB 116c7684efdSDevin Teskeif [ "$ZFSBOOT_DISKS" ]; then 117c7684efdSDevin Teske bsdinstall zfsboot 118c7684efdSDevin Teskeelse 1192ffbec18SNathan Whitehorn bsdinstall scriptedpart "$PARTITIONS" 1202f34d6c3SRoger Pau Monnéfi 12134766aa8SNathan Whitehornbsdinstall mount 1222ffbec18SNathan Whitehorn 123dc14ae42SAlan Somersif [ -n "$COMPONENTS" -a -n "$DISTRIBUTIONS" ]; then 124dc14ae42SAlan Somers error "Cannot set both COMPONENTS and DISTRIBUTIONS" 125dc14ae42SAlan Somerselif [ -z "$DISTRIBUTIONS" ]; then 126dc14ae42SAlan Somers # If COMPONENTS is set, or neither is, install with pkgbase 127dc14ae42SAlan Somers bsdinstall pkgbase --non-interactive 128dc14ae42SAlan Somerselse 129dc14ae42SAlan Somers # Otherwise, unpack distsets 130dc14ae42SAlan Somers 13140923b0cSNathan Whitehorn # Fetch missing distribution files, if any 132c0e249d3SLars Kellogg-Stedman exec 5>&1 133c0e249d3SLars Kellogg-Stedman export BSDINSTALL_DISTDIR=$(`dirname $0`/fetchmissingdists 2>&1 1>&5) 13440923b0cSNathan Whitehorn FETCH_RESULT=$? 135c0e249d3SLars Kellogg-Stedman exec 5>&- 136c0e249d3SLars Kellogg-Stedman 137c0e249d3SLars Kellogg-Stedman [ $FETCH_RESULT -ne 0 ] && error "Could not fetch remote distributions" 13840923b0cSNathan Whitehorn 1392ffbec18SNathan Whitehorn bsdinstall checksum 140c2f16c59SNathan Whitehorn if [ -t 0 ]; then 141c2f16c59SNathan Whitehorn # If install is a tty, use distextract as normal 142c2f16c59SNathan Whitehorn bsdinstall distextract 143c2f16c59SNathan Whitehorn else 144dc14ae42SAlan Somers # Otherwise, we need to use tar (see 145dc14ae42SAlan Somers # https://reviews.freebsd.org/D10736) 146d7640440SRoger Pau Monné for set in $DISTRIBUTIONS; do 147d7640440SRoger Pau Monné f_dprintf "Extracting $BSDINSTALL_DISTDIR/$set" 148dc14ae42SAlan Somers # XXX: The below fails if any mountpoints are FAT, due 149dc14ae42SAlan Somers # to inability to set ctime/mtime on the root of FAT 150dc14ae42SAlan Somers # partitions, which is needed to support e.g. EFI 151dc14ae42SAlan Somers # system partitions. tar has no option to ignore this 152dc14ae42SAlan Somers # (distextract ignores them internally through a hack), 153dc14ae42SAlan Somers # and returns 1 on any warning or error, effectively 154dc14ae42SAlan Somers # turning all warnings into fatal errors. 155c2f16c59SNathan Whitehorn # 156dc14ae42SAlan Somers # Work around this in an extremely lame way for the 157dc14ae42SAlan Somers # specific case of EFI system partitions only. This 158dc14ae42SAlan Somers # *ONLY WORKS* if /boot/efi is empty and does not 159dc14ae42SAlan Somers # handle analogous problems on other systems (ARM, 160dc14ae42SAlan Somers # PPC64). 161c2f16c59SNathan Whitehorn tar -xf "$BSDINSTALL_DISTDIR/$set" -C $BSDINSTALL_CHROOT --exclude boot/efi 162c2f16c59SNathan Whitehorn mkdir -p $BSDINSTALL_CHROOT/boot/efi 163d7640440SRoger Pau Monné done 164c2f16c59SNathan Whitehorn fi 165dc14ae42SAlan Somersfi 1662ffbec18SNathan Whitehorn 1678befcf7bSNathan Whitehorn# Configure bootloader if needed 1688befcf7bSNathan Whitehornbsdinstall bootconfig 1698befcf7bSNathan Whitehorn 1702ffbec18SNathan Whitehorn# Finalize install 1712ffbec18SNathan Whitehornbsdinstall config 1722ffbec18SNathan Whitehorn 1734bdf7393SNathan Whitehorn# Make sure networking is functional, if we can arrange that 1744bdf7393SNathan Whitehornif [ ! -f $BSDINSTALL_CHROOT/etc/resolv.conf -a -f /etc/resolv.conf ]; then 1754bdf7393SNathan Whitehorn cp /etc/resolv.conf $BSDINSTALL_CHROOT/etc/resolv.conf 1764bdf7393SNathan Whitehornfi 1774bdf7393SNathan Whitehorn 1782ffbec18SNathan Whitehorn# Run post-install script 179731704f5SMichael Gmelinif [ -f $TMPDIR/bsdinstall-installscript-setup ]; then 180731704f5SMichael Gmelin cp $TMPDIR/bsdinstall-installscript-setup \ 181731704f5SMichael Gmelin $BSDINSTALL_CHROOT/tmp/installscript 1822ffbec18SNathan Whitehorn chmod a+x $BSDINSTALL_CHROOT/tmp/installscript 1832ffbec18SNathan Whitehorn chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1 1842ffbec18SNathan Whitehorn rm $BSDINSTALL_CHROOT/tmp/installscript 1852ffbec18SNathan Whitehornfi 1862ffbec18SNathan Whitehorn 187dfc23ba5SDag-Erling Smørgravbsdinstall entropy 188450b4ac2SCorvin Köhnebsdinstall umount 1892f34d6c3SRoger Pau Monnéif [ "$ZFSBOOT_DISKS" ]; then 1902f34d6c3SRoger Pau Monné zpool export $ZFSBOOT_POOL_NAME 1912f34d6c3SRoger Pau Monnéfi 1922ffbec18SNathan Whitehorn 193bc4a673fSDevin Teskef_dprintf "Installation Completed at %s" "$( date )" 1942ffbec18SNathan Whitehorn 19596eeaba5SDevin Tesketrap - EXIT 19696eeaba5SDevin Teskeexit $SUCCESS 197bc4a673fSDevin Teske 198bc4a673fSDevin Teske################################################################################ 199bc4a673fSDevin Teske# END 200bc4a673fSDevin Teske################################################################################ 201