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# 282ffbec18SNathan Whitehorn# $FreeBSD$ 29bc4a673fSDevin Teske# 30bc4a673fSDevin Teske############################################################ INCLUDES 31bc4a673fSDevin Teske 32bc4a673fSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 33bc4a673fSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 34bc4a673fSDevin Teskef_dprintf "%s: loading includes..." "$0" 35bc4a673fSDevin Teskef_include $BSDCFG_SHARE/dialog.subr 36bc4a673fSDevin Teskef_include $BSDCFG_SHARE/variable.subr 37bc4a673fSDevin Teske 38bc4a673fSDevin Teske############################################################ CONFIGURATION 392ffbec18SNathan Whitehorn 402ffbec18SNathan Whitehorn# VARIABLES: 412ffbec18SNathan Whitehorn# PARTITIONS 422ffbec18SNathan Whitehorn# DISTRIBUTIONS 432ffbec18SNathan Whitehorn# BSDINSTALL_DISTDIR 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"} 53a107ddbbSRebecca Cran 54bc4a673fSDevin Teske# 55bc4a673fSDevin Teske# Strings that should be moved to an i18n file and loaded with f_include_lang() 56bc4a673fSDevin Teske# 57bc4a673fSDevin Teskemsg_installation_error="Installation Error!" 58bc4a673fSDevin Teske 59bc4a673fSDevin Teske############################################################ FUNCTIONS 60bc4a673fSDevin Teske 61bc4a673fSDevin Teskeerror() 62bc4a673fSDevin Teske{ 63bc4a673fSDevin Teske local file 64bc4a673fSDevin Teske f_getvar "$VAR_DEBUG_FILE#+" file 65bc4a673fSDevin Teske if [ "$file" ]; then 66bc4a673fSDevin Teske f_dialog_title "$msg_installation_error" 67bc4a673fSDevin Teske f_dialog_textbox "$file" 68bc4a673fSDevin Teske # No need to restore title, pining for the fjords 69bc4a673fSDevin Teske fi 70bc4a673fSDevin Teske 712f34d6c3SRoger Pau Monné [ -f "$PATH_FSTAB" ] || exit 722f34d6c3SRoger Pau Monné if [ "$ZFSBOOT_DISKS" ]; then 732f34d6c3SRoger Pau Monné zpool export $ZFSBOOT_POOL_NAME 742f34d6c3SRoger Pau Monné else 752f34d6c3SRoger Pau Monné bsdinstall umount 762f34d6c3SRoger Pau Monné fi 772f34d6c3SRoger Pau Monné 782ffbec18SNathan Whitehorn exit 1 792ffbec18SNathan Whitehorn} 802ffbec18SNathan Whitehorn 81bc4a673fSDevin Teske############################################################ MAIN 82bc4a673fSDevin Teske 832ffbec18SNathan Whitehornset -e 842ffbec18SNathan Whitehorntrap error EXIT 852ffbec18SNathan Whitehorn 862ffbec18SNathan WhitehornSCRIPT="$1" 872ffbec18SNathan Whitehornshift 882ffbec18SNathan Whitehorn 894c5d7fabSDevin Teskef_dprintf "Began Installation at %s" "$( date )" 902ffbec18SNathan Whitehornrm -rf $BSDINSTALL_TMPETC 912ffbec18SNathan Whitehornmkdir $BSDINSTALL_TMPETC 922ffbec18SNathan Whitehorn 93a107ddbbSRebecca Cransplit -a 2 -p '^#!.*' "$SCRIPT" $TMPDIR/bsdinstall-installscript- 942ffbec18SNathan Whitehorn 95a107ddbbSRebecca Cran. $TMPDIR/bsdinstall-installscript-aa 962ffbec18SNathan Whitehorn: ${DISTRIBUTIONS="kernel.txz base.txz"}; export DISTRIBUTIONS 972ffbec18SNathan Whitehornexport BSDINSTALL_DISTDIR 982ffbec18SNathan Whitehorn 99bc4a673fSDevin Teske# Re-initialize a new log if preamble changed BSDINSTALL_LOG 100bc4a673fSDevin Teskeif [ "$BSDINSTALL_LOG" != "${debugFile#+}" ]; then 101bc4a673fSDevin Teske export debugFile="$BSDINSTALL_LOG" 102bc4a673fSDevin Teske f_quietly f_debug_init 103bc4a673fSDevin Teske # NB: Being scripted, let debug go to terminal for invalid debugFile 1045104dfbeSNavdeep Parhar f_dprintf "Began Installation at %s" "$( date )" 105bc4a673fSDevin Teskefi 106bc4a673fSDevin Teske 1072ffbec18SNathan Whitehorn# Make partitions 1082ffbec18SNathan Whitehornrm -f $PATH_FSTAB 1092ffbec18SNathan Whitehorntouch $PATH_FSTAB 110c7684efdSDevin Teskeif [ "$ZFSBOOT_DISKS" ]; then 111c7684efdSDevin Teske bsdinstall zfsboot 112c7684efdSDevin Teskeelse 1132ffbec18SNathan Whitehorn bsdinstall scriptedpart "$PARTITIONS" 1142f34d6c3SRoger Pau Monnéfi 11534766aa8SNathan Whitehornbsdinstall mount 1162ffbec18SNathan Whitehorn 11740923b0cSNathan Whitehorn# Fetch missing distribution files, if any 1181f7746d8SCorvin Köhne( 11940923b0cSNathan Whitehorn exec 3>&1 12040923b0cSNathan Whitehorn export BSDINSTALL_DISTDIR=$(`dirname $0`/fetchmissingdists 2>&1 1>&3) 12140923b0cSNathan Whitehorn FETCH_RESULT=$? 12240923b0cSNathan Whitehorn exec 3>&- 1231f7746d8SCorvin Köhne return $FETCH_RESULT 1241f7746d8SCorvin Köhne) || error "Could not fetch remote distributions" 12540923b0cSNathan Whitehorn 1262ffbec18SNathan Whitehorn# Unpack distributions 1272ffbec18SNathan Whitehornbsdinstall checksum 128c2f16c59SNathan Whitehornif [ -t 0 ]; then 129c2f16c59SNathan Whitehorn # If install is a tty, use distextract as normal 130c2f16c59SNathan Whitehorn bsdinstall distextract 131c2f16c59SNathan Whitehornelse 132c2f16c59SNathan Whitehorn # Otherwise, we need to use tar (see https://reviews.freebsd.org/D10736) 133d7640440SRoger Pau Monné for set in $DISTRIBUTIONS; do 134d7640440SRoger Pau Monné f_dprintf "Extracting $BSDINSTALL_DISTDIR/$set" 135c2f16c59SNathan Whitehorn # XXX: The below fails if any mountpoints are FAT, due to 136c2f16c59SNathan Whitehorn # inability to set ctime/mtime on the root of FAT partitions, 137c2f16c59SNathan Whitehorn # which is needed to support e.g. EFI system partitions. tar has 138c2f16c59SNathan Whitehorn # no option to ignore this (distextract ignores them internally 139c2f16c59SNathan Whitehorn # through a hack), and returns 1 on any warning or error, 140c2f16c59SNathan Whitehorn # effectively turning all warnings into fatal errors. 141c2f16c59SNathan Whitehorn # 142c2f16c59SNathan Whitehorn # Work around this in an extremely lame way for the specific 143c2f16c59SNathan Whitehorn # case of EFI system partitions only. This *ONLY WORKS* if 144c2f16c59SNathan Whitehorn # /boot/efi is empty and does not handle analagous problems on 145c2f16c59SNathan Whitehorn # other systems (ARM, PPC64). 146c2f16c59SNathan Whitehorn tar -xf "$BSDINSTALL_DISTDIR/$set" -C $BSDINSTALL_CHROOT --exclude boot/efi 147c2f16c59SNathan Whitehorn mkdir -p $BSDINSTALL_CHROOT/boot/efi 148d7640440SRoger Pau Monné done 149c2f16c59SNathan Whitehornfi 1502ffbec18SNathan Whitehorn 1518befcf7bSNathan Whitehorn# Configure bootloader if needed 1528befcf7bSNathan Whitehornbsdinstall bootconfig 1538befcf7bSNathan Whitehorn 1542ffbec18SNathan Whitehorn# Finalize install 1552ffbec18SNathan Whitehornbsdinstall config 1562ffbec18SNathan Whitehorn 1574bdf7393SNathan Whitehorn# Make sure networking is functional, if we can arrange that 1584bdf7393SNathan Whitehornif [ ! -f $BSDINSTALL_CHROOT/etc/resolv.conf -a -f /etc/resolv.conf ]; then 1594bdf7393SNathan Whitehorn cp /etc/resolv.conf $BSDINSTALL_CHROOT/etc/resolv.conf 1604bdf7393SNathan Whitehornfi 1614bdf7393SNathan Whitehorn 1622ffbec18SNathan Whitehorn# Run post-install script 163a107ddbbSRebecca Cranif [ -f $TMPDIR/bsdinstall-installscript-ab ]; then 164a107ddbbSRebecca Cran cp $TMPDIR/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/tmp/installscript 1652ffbec18SNathan Whitehorn chmod a+x $BSDINSTALL_CHROOT/tmp/installscript 1662ffbec18SNathan Whitehorn chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1 1672ffbec18SNathan Whitehorn rm $BSDINSTALL_CHROOT/tmp/installscript 1682ffbec18SNathan Whitehornfi 1692ffbec18SNathan Whitehorn 170dfc23ba5SDag-Erling Smørgravbsdinstall entropy 171*450b4ac2SCorvin Köhnebsdinstall umount 1722f34d6c3SRoger Pau Monnéif [ "$ZFSBOOT_DISKS" ]; then 1732f34d6c3SRoger Pau Monné zpool export $ZFSBOOT_POOL_NAME 1742f34d6c3SRoger Pau Monnéfi 1752ffbec18SNathan Whitehorn 176bc4a673fSDevin Teskef_dprintf "Installation Completed at %s" "$( date )" 1772ffbec18SNathan Whitehorn 17896eeaba5SDevin Tesketrap - EXIT 17996eeaba5SDevin Teskeexit $SUCCESS 180bc4a673fSDevin Teske 181bc4a673fSDevin Teske################################################################################ 182bc4a673fSDevin Teske# END 183bc4a673fSDevin Teske################################################################################ 184