diff options
Diffstat (limited to 'usr.sbin/bsdinstall/scripts')
29 files changed, 5923 insertions, 0 deletions
diff --git a/usr.sbin/bsdinstall/scripts/Makefile b/usr.sbin/bsdinstall/scripts/Makefile new file mode 100644 index 000000000000..4fd59e49d506 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/Makefile @@ -0,0 +1,38 @@ +.include <bsd.compat.pre.mk> + +SCRIPTS=auto \ + adduser \ + bootconfig \ + checksum \ + config \ + docsinstall \ + entropy \ + fetchmissingdists \ + finalconfig \ + firmware \ + hardening \ + hostname \ + jail \ + keymap \ + mirrorselect \ + mount \ + netconfig \ + netconfig_ipv4 \ + netconfig_ipv6 \ + pkgbase \ + rootpass \ + script \ + services \ + time \ + umount \ + wlanconfig \ + zfsboot + +BINDIR= ${LIBEXECDIR}/bsdinstall + +MAN= + +pkgbase: pkgbase.in + sed "s|%%_ALL_libcompats%%|${_ALL_libcompats}|" < ${.ALLSRC} > ${.TARGET} + +.include <bsd.prog.mk> diff --git a/usr.sbin/bsdinstall/scripts/Makefile.depend b/usr.sbin/bsdinstall/scripts/Makefile.depend new file mode 100644 index 000000000000..11aba52f82cf --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/Makefile.depend @@ -0,0 +1,10 @@ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/usr.sbin/bsdinstall/scripts/adduser b/usr.sbin/bsdinstall/scripts/adduser new file mode 100755 index 000000000000..df802156b992 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/adduser @@ -0,0 +1,36 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +clear +echo "$OSNAME Installer" +echo "========================" +echo "Add Users" +echo +chroot $BSDINSTALL_CHROOT adduser 2>&1 diff --git a/usr.sbin/bsdinstall/scripts/auto b/usr.sbin/bsdinstall/scripts/auto new file mode 100755 index 000000000000..5fefc07e4c07 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/auto @@ -0,0 +1,492 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2013-2018 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_include $BSDCFG_SHARE/dialog.subr + +############################################################ GLOBALS + +# +# List of environment variables that may be defined by the user, but modified +# during the installation process. They are then restored when restarting this +# script. +# +user_env_vars="BSDINSTALL_DISTSITE DISTRIBUTIONS WORKAROUND_GPTACTIVE WORKAROUND_LENOVO ZFSBOOT_PARTITION_SCHEME" + +# +# Strings that should be moved to an i18n file and loaded with f_include_lang() +# +hline_arrows_tab_enter="Press arrows, TAB or ENTER" +hline_arrows_tab_space_enter="Press arrows, TAB, SPACE or ENTER" +msg_abort="Abort" +msg_an_installation_step_has_been_aborted="An installation step has been aborted. Would you like\nto restart the installation or exit the installer?" +msg_auto_ufs="Auto (UFS)" +msg_auto_ufs_desc="Guided UFS Disk Setup" +msg_auto_ufs_help="Menu options help choose which disk to setup using UFS and standard partitions" +msg_auto_zfs="Auto (ZFS)" +msg_auto_zfs_desc="Guided Root-on-ZFS" +msg_auto_zfs_help="To use ZFS with less than 8GB RAM, see https://wiki.freebsd.org/ZFSTuningGuide" +msg_exit="Exit" +msg_freebsd_installer="$OSNAME Installer" +msg_gpt_active_fix="Your hardware is known to have issues booting in CSM/Legacy/BIOS mode from GPT partitions that are not set active. Would you like the installer to apply this workaround for you?" +msg_lenovo_fix="Your model of Lenovo is known to have a BIOS bug that prevents it booting from GPT partitions without UEFI. Would you like the installer to apply a workaround for you?" +msg_manual="Manual" +msg_manual_desc="Manual Disk Setup (experts)" +msg_manual_help="Create customized partitions from menu options" +msg_no="NO" +msg_restart="Restart" +msg_shell="Shell" +msg_shell_desc="Open a shell and partition by hand" +msg_shell_help="Create customized partitions using command-line utilities" +msg_yes="YES" + +############################################################ FUNCTIONS + +# error [$msg] +# +# Display generic error message when a script fails. An optional message +# argument can precede the generic message. User is given the choice of +# restarting the installer or exiting. +# +error() +{ + local title="$msg_abort" + local btitle="$msg_freebsd_installer" + local prompt="${1:+$1\n\n}$msg_an_installation_step_has_been_aborted" + local hline="$hline_arrows_tab_space_enter" + + [ -f "$PATH_FSTAB" ] && bsdinstall umount + + local height width + f_dialog_buttonbox_size height width \ + "$title" "$btitle" "$prompt" "$hline" + + if $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --hline "$hline" \ + --no-label "$msg_exit" \ + --yes-label "$msg_restart" \ + --yesno "$prompt" $height $width + then + environment_restore + exec $0 + # NOTREACHED + fi + exit 1 +} + +# dialog_workaround +# +# Ask the user if they wish to apply a workaround +# +dialog_workaround() +{ + local passed_msg="$1" + local title="$DIALOG_TITLE" + local btitle="$DIALOG_BACKTITLE" + local prompt # Calculated below + local hline="$hline_arrows_tab_enter" + + local height=8 width=50 prefix=" " + local plen=${#prefix} list= line= + local max_width=$(( $width - 3 - $plen )) + + local yes no defaultno extra_args format + if [ "$USE_XDIALOG" ]; then + yes=ok no=cancel defaultno=default-no + extra_args="--wrap --left" + format="$passed_msg" + else + yes=yes no=no defaultno=defaultno + extra_args="--cr-wrap" + format="$passed_msg" + fi + + # Add height for Xdialog(1) + [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) + + prompt=$( printf "$format" ) + f_dprintf "%s: Workaround prompt" "$0" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --hline "$hline" \ + --$yes-label "$msg_yes" \ + --$no-label "$msg_no" \ + $extra_args \ + --yesno "$prompt" $height $width +} + +# environment_restore +# +# Restore a list of environment variables when this script is restarted. +# +environment_restore() +{ + for var in $user_env_vars; do + eval "if [ -n \"\${ORIG_$var}\" -o -z \"\${ORIG_$var-z}\" ]; then $var=\${ORIG_$var}; else unset $var; fi" + done +} + +# environment_save +# +# Save any user-defined environment variable that may be modified during the +# installation process. They are then restored when restarting this script. +# +environment_save() +{ + for var in $user_env_vars; do + eval "if [ -n \"\${$var}\" -o -z \"\${$var-z}\" ]; then ORIG_$var=\${$var}; else unset ORIG_$var; fi" + done +} + +############################################################ MAIN + +f_dprintf "Began Installation at %s" "$( date )" + +environment_save + +rm -rf $BSDINSTALL_TMPETC +mkdir $BSDINSTALL_TMPETC + +# Reset the ESP list +: > ${TMPDIR:-"/tmp"}/bsdinstall-esps + +# With pkgbase, pkg OOM has been observed with QEMU-default 128 MiB memory size. +# Ensure we have at least about 256 MiB (with an allowance for rounding etc.). +physmem=$(($(sysctl -n hw.physmem) / 1048576)) +if [ $physmem -lt 200 ]; then + bsddialog --backtitle "$OSNAME Installer" --title "Warning" \ + --msgbox "Insufficient physical memory (${physmem} MiB) detected. At least 256 MiB is recommended. The installer or installed system may not function correctly." 0 0 +fi + +[ -f /usr/libexec/bsdinstall/local.pre-everything ] && f_dprintf "Running local.pre-everything" && sh /usr/libexec/bsdinstall/local.pre-everything "$BSDINSTALL_CHROOT" + +trap true SIGINT # This section is optional +[ -z "$BSDINSTALL_SKIP_KEYMAP" ] && bsdinstall keymap + +trap error SIGINT # Catch cntrl-C here +if [ -z "$BSDINSTALL_SKIP_HOSTNAME" ]; then bsdinstall hostname || error "Set hostname failed"; fi + +if [ -f /usr/freebsd-packages/repos/FreeBSD-base-offline.conf ]; then + HAVE_BASE_PACKAGES=yes + PKGBASE_DEFAULT_BUTTON=--default-no +else + unset HAVE_BASE_PACKAGES + unset PKGBASE_DEFAULT_BUTTON +fi + +if [ ! -f $BSDINSTALL_DISTDIR/MANIFEST ]; then + PKGBASE=yes +else + bsddialog --backtitle "$OSNAME Installer" --title "Select Installation Type" \ + --yes-label "Distribution Sets" --no-label "Packages (Tech Preview)" --yesno \ + $PKGBASE_DEFAULT_BUTTON \ + "Would you like to install the base system using traditional distribution sets or packages (technology preview)?" 0 0 + if [ $? -eq 1 ]; then + PKGBASE=yes + fi +fi + +if [ "$PKGBASE" == yes ]; then + if [ "$HAVE_BASE_PACKAGES" == yes ]; then + bsddialog --backtitle "$OSNAME Installer" --title "Network or Offline Installation" \ + --yes-label "Network" --no-label "Offline (Limited Packages)" --yesno \ + "Would you like to fetch packages from the internet or use the limited set of packages included in this installation media?" 0 0 + if [ $? -eq 1 ]; then + export BSDINSTALL_PKG_REPOS_DIR=/usr/freebsd-packages/repos/ + else + bsdinstall netconfig || error + NETCONFIG_DONE=yes + fi + else + bsddialog --backtitle "$OSNAME Installer" --title "Network Installation" \ + --msgbox "No base system packages are included in this installation media. The next few screens will allow you to configure networking." 0 0 + bsdinstall netconfig || error + NETCONFIG_DONE=yes + fi +else + export DISTRIBUTIONS="${DISTRIBUTIONS:-base.txz kernel.txz}" + if [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then + DISTMENU=`awk -F'\t' '!/^(kernel\.txz|base\.txz)/{print $1,$5,$6}' $BSDINSTALL_DISTDIR/MANIFEST` + DISTMENU="$(echo ${DISTMENU} | sed -E 's/\.txz//g')" + + if [ -n "$DISTMENU" ]; then + exec 5>&1 + EXTRA_DISTS=$( eval bsddialog \ + --backtitle \"$OSNAME Installer\" \ + --title \"Distribution Select\" --nocancel --separate-output \ + --checklist \"Choose optional system components to install:\" \ + 0 0 0 $DISTMENU \ + 2>&1 1>&5 ) + for dist in $EXTRA_DISTS; do + export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz" + done + fi + fi + + FETCH_DISTRIBUTIONS="" + for dist in $DISTRIBUTIONS; do + if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then + FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist" + fi + done + + if [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then + bsddialog --backtitle "$OSNAME Installer" --title "Network Installation" --msgbox "Some installation files were not found on the boot volume. The next few screens will allow you to configure networking so that they can be downloaded from the Internet." 0 0 + bsdinstall netconfig || error + NETCONFIG_DONE=yes + fi +fi + +rm -f $PATH_FSTAB +touch $PATH_FSTAB + +[ -f /usr/libexec/bsdinstall/local.pre-partition ] && f_dprintf "Running local.pre-partition" && sh /usr/libexec/bsdinstall/local.pre-partition "$BSDINSTALL_CHROOT" + +# +# Try to detect known broken platforms and apply their workarounds +# + +if f_interactive; then + sys_maker=$( kenv -q smbios.system.maker ) + f_dprintf "smbios.system.maker=[%s]" "$sys_maker" + sys_model=$( kenv -q smbios.system.product ) + f_dprintf "smbios.system.product=[%s]" "$sys_model" + sys_version=$( kenv -q smbios.system.version ) + f_dprintf "smbios.system.version=[%s]" "$sys_version" + sys_mb_maker=$( kenv -q smbios.planar.maker ) + f_dprintf "smbios.planar.maker=[%s]" "$sys_mb_maker" + sys_mb_product=$( kenv -q smbios.planar.product ) + f_dprintf "smbios.planar.product=[%s]" "$sys_mb_product" + + # + # Laptop Models + # + case "$sys_maker" in + "LENOVO") + case "$sys_version" in + "ThinkPad X220"|"ThinkPad T420"|"ThinkPad T520"|"ThinkPad W520"|"ThinkPad X1") + dialog_workaround "$msg_lenovo_fix" + retval=$? + f_dprintf "lenovofix_prompt=[%s]" "$retval" + if [ $retval -eq $DIALOG_OK ]; then + export ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix" + export WORKAROUND_LENOVO=1 + fi + ;; + esac + ;; + "Dell Inc.") + case "$sys_model" in + "Latitude E6330"|"Latitude E7440"|"Latitude E7240"|"Precision Tower 5810") + dialog_workaround "$msg_gpt_active_fix" + retval=$? + f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" + if [ $retval -eq $DIALOG_OK ]; then + export ZFSBOOT_PARTITION_SCHEME="GPT + Active" + export WORKAROUND_GPTACTIVE=1 + fi + ;; + esac + ;; + "Hewlett-Packard") + case "$sys_model" in + "HP ProBook 4330s") + dialog_workaround "$msg_gpt_active_fix" + retval=$? + f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" + if [ $retval -eq $DIALOG_OK ]; then + export ZFSBOOT_PARTITION_SCHEME="GPT + Active" + export WORKAROUND_GPTACTIVE=1 + fi + ;; + esac + ;; + esac + # + # Motherboard Models + # + case "$sys_mb_maker" in + "Intel Corporation") + case "$sys_mb_product" in + "DP965LT"|"D510MO") + dialog_workaround "$msg_gpt_active_fix" + retval=$? + f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" + if [ $retval -eq $DIALOG_OK ]; then + export ZFSBOOT_PARTITION_SCHEME="GPT + Active" + export WORKAROUND_GPTACTIVE=1 + fi + ;; + esac + ;; + "Acer") + case "$sys_mb_product" in + "Veriton M6630G") + dialog_workaround "$msg_gpt_active_fix" + retval=$? + f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" + if [ $retval -eq $DIALOG_OK ]; then + export ZFSBOOT_PARTITION_SCHEME="GPT + Active" + export WORKAROUND_GPTACTIVE=1 + fi + ;; + esac + ;; + esac +fi + +PMODES=" + '$msg_auto_ufs' '$msg_auto_ufs_desc' '$msg_auto_ufs_help' + '$msg_manual' '$msg_manual_desc' '$msg_manual_help' + '$msg_shell' '$msg_shell_desc' '$msg_shell_help' +" # END-QUOTE + +CURARCH=$( uname -m ) +case $CURARCH in + amd64|arm64|i386|riscv) # Booting ZFS Supported + PMODES=" + '$msg_auto_zfs' '$msg_auto_zfs_desc' '$msg_auto_zfs_help' + $PMODES + " # END-QUOTE + ;; + *) # Booting ZFS Unsupported + ;; +esac + +exec 5>&1 +PARTMODE=`echo $PMODES | xargs -o bsddialog --backtitle "$OSNAME Installer" \ + --title "Partitioning" \ + --item-help \ + --menu "How would you like to partition your disk?" \ + 0 0 0 2>&1 1>&5` || exit 1 +exec 5>&- + +case "$PARTMODE" in +"$msg_auto_zfs") # ZFS + bsdinstall zfsboot || error "ZFS setup failed" + bsdinstall mount || error "Failed to mount filesystem" + ;; +"$msg_auto_ufs") # Guided UFS + bsdinstall autopart || error "Partitioning error" + bsdinstall mount || error "Failed to mount filesystem" + ;; +"$msg_shell") # Shell + clear + echo "Use this shell to set up partitions for the new system. When finished, mount the system at $BSDINSTALL_CHROOT and place an fstab file for the new system at $PATH_FSTAB. Then type 'exit'. You can also enter the partition editor at any time by entering 'bsdinstall partedit'." + sh 2>&1 + ;; +"$msg_manual") # Manual + if f_isset debugFile; then + # Give partedit the path to our logfile so it can append + BSDINSTALL_LOG="${debugFile#+}" bsdinstall partedit || error "Partitioning error" + else + bsdinstall partedit || error "Partitioning error" + fi + bsdinstall mount || error "Failed to mount filesystem" + ;; +*) + error "Unknown partitioning mode" + ;; +esac + +[ -f /usr/libexec/bsdinstall/local.pre-fetch ] && f_dprintf "Running local.pre-fetch" && sh /usr/libexec/bsdinstall/local.pre-fetch "$BSDINSTALL_CHROOT" + +if [ "$PKGBASE" == yes ]; then + bsdinstall pkgbase || error "Installation of base system packages failed" +else + if [ -n "$FETCH_DISTRIBUTIONS" ]; then + exec 5>&1 + export BSDINSTALL_DISTDIR=$(`dirname $0`/fetchmissingdists 2>&1 1>&5) + FETCH_RESULT=$? + exec 5>&- + + [ $FETCH_RESULT -ne 0 ] && error "Could not fetch remote distributions" + fi + bsdinstall checksum || error "Distribution checksum failed" + bsdinstall distextract || error "Distribution extract failed" +fi + +# Set up boot loader +bsdinstall bootconfig || error "Failed to configure bootloader" + +[ -f /usr/libexec/bsdinstall/local.pre-configure ] && f_dprintf "Running local.pre-configure" && sh /usr/libexec/bsdinstall/local.pre-configure "$BSDINSTALL_CHROOT" + +bsdinstall rootpass || error "Could not set root password" + +trap true SIGINT # This section is optional +if [ "$NETCONFIG_DONE" != yes ]; then + bsdinstall netconfig # Don't check for errors -- the user may cancel +fi +[ -z "$BSDINSTALL_SKIP_TIME" ] && bsdinstall time +[ -z "$BSDINSTALL_SKIP_SERVICES" ] && bsdinstall services +[ -z "$BSDINSTALL_SKIP_HARDENING" ] && bsdinstall hardening +[ -z "$BSDINSTALL_SKIP_FIRMWARE" ] && bsdinstall firmware + +[ -z "$BSDINSTALL_SKIP_USERS" ] && bsddialog --backtitle "$OSNAME Installer" \ + --title "Add User Accounts" --yesno \ + "Would you like to add users to the installed system now?" 0 0 && \ + bsdinstall adduser + +# Allow user to change his mind +[ -z "$BSDINSTALL_SKIP_FINALCONFIG" ] && bsdinstall finalconfig + +trap error SIGINT # SIGINT is bad again +bsdinstall config || error "Failed to save config" + +if [ ! -z "$BSDINSTALL_FETCHDEST" ]; then + rm -rf "$BSDINSTALL_FETCHDEST" +fi + +[ -f /usr/libexec/bsdinstall/local.post-configure ] && f_dprintf "Running local.post-configure" && sh /usr/libexec/bsdinstall/local.post-configure "$BSDINSTALL_CHROOT" + +if [ -z "$BSDINSTALL_SKIP_MANUAL" ]; then + bsddialog --backtitle "$OSNAME Installer" --title "Manual Configuration" \ + --default-no --yesno \ + "The installation is now finished. Before exiting the installer, would you like to open a shell in the new system to make any final manual modifications?" 0 0 + if [ $? -eq 0 ]; then + clear + echo This shell is operating in a chroot in the new system. \ + When finished making configuration changes, type \"exit\". + chroot "$BSDINSTALL_CHROOT" /bin/sh -l 2>&1 + fi +fi + +bsdinstall entropy +bsdinstall umount + +f_dprintf "Installation Completed at %s" "$( date )" + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdinstall/scripts/bootconfig b/usr.sbin/bsdinstall/scripts/bootconfig new file mode 100755 index 000000000000..9c188c1d8a91 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/bootconfig @@ -0,0 +1,174 @@ +#!/bin/sh +#- +# Copyright (c) 2018 Rebecca Cran +# Copyright (c) 2017 Nathan Whitehorn +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +FREEBSD_BOOTLABEL=$OSNAME + +f_dprintf "%s: loading_includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr + +: ${TMPDIR:="/tmp"} + +die() { + echo $* + exit 1 +} + +dialog_uefi_entryname() +{ + local prompt="Please enter a name for the new entry" + local hline= + local value="$*" + local height width + + f_dialog_inputbox_size height width \ + "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$prompt" "$value" "$hline" + + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "Ok" \ + --no-cancel \ + --inputbox "$prompt" \ + $height $width "$value" \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD +} + +# Copy to the normal FreeBSD location. Also copy to the default location if it +# doesn't exist. This covers setups where UEFI NV variables can't be set and +# some buggy firmware, while preserving complex UEFI setups for multiple booting +# (rEFInd, etc). +uefi_copy_loader() +{ + local ldr=$1 + local freebsd_dir=$2 + local default_dir=$3 + local dest=$4 + + mkdir -p "${freebsd_dir}" "${default_dir}" + cp "${ldr}" "${freebsd_dir}" + if [ ! -f "${default_dir}/${dest}" ]; then + cp "${ldr}" "${default_dir}/${dest}" + fi +} + +update_uefi_bootentry() +{ + nentries=$(efibootmgr | grep -c "${EFI_LABEL_NAME}$") + # No entries so directly create one and return + if [ ${nentries} -eq 0 ]; then + f_dprintf "Creating UEFI boot entry" + efibootmgr --create --activate --label "$EFI_LABEL_NAME" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null + return + fi + + $DIALOG --backtitle "$OSNAME Installer" --title 'Boot Configuration' \ + --yesno "One or more \"$OSNAME\" EFI boot manager entries already exist. Would you like to remove them all and add a new one?" 0 0 + if [ $? -eq $DIALOG_OK ]; then + for entry in $(efibootmgr | awk "\$NF == \"$EFI_LABEL_NAME\" { sub(/.*Boot/,\"\", \$1); sub(/\*/,\"\", \$1); print \$1 }"); do + efibootmgr -B -b ${entry} + done + efibootmgr --create --activate --label "$EFI_LABEL_NAME" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null + return + fi + + FREEBSD_BOOTLABEL=$(dialog_uefi_entryname "${EFI_LABEL_NAME}") + [ $? -eq $DIALOG_CANCEL ] && exit 1 + efibootmgr --create --activate --label "$FREEBSD_BOOTLABEL" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null +} + +f_dialog_title "Boot Configuration" +f_dialog_backtitle "$OSNAME Installer" + +if [ `uname -m` == powerpc ]; then + platform=`sysctl -n hw.platform` + if [ "$platform" == ps3 -o "$platform" == powernv ]; then + rootpart=$(awk '{ if($2 == "/") printf("%s:%s\n", $3, $1); }' $PATH_FSTAB) + kboot_conf=$BSDINSTALL_CHROOT/boot/etc/kboot.conf + mkdir -p $BSDINSTALL_CHROOT/boot/etc/ + echo default=$FREEBSD_BOOTLABEL > $kboot_conf + echo $FREEBSD_BOOTLABEL=\'/kernel/kernel kernelname=/boot/kernel/kernel vfs.root.mountfrom=${rootpart}\' >> $kboot_conf + fi +fi + +# Update the ESP (EFI System Partition) with the new bootloader if we have an ESP +if [ -n "$(awk '{if ($2=="/boot/efi") printf("%s\n",$1);}' $PATH_FSTAB)" ]; then + case $(uname -m) in + arm64) ARCHBOOTNAME=aa64 ;; + amd64) ARCHBOOTNAME=x64 ;; + riscv) ARCHBOOTNAME=riscv64 ;; + # arm) ARCHBOOTNAME=arm ;; # No other support for arm install + # i386) ARCHBOOTNAME=ia32 ;; # no support for this in i386 kernels, rare machines + *) die "Unsupported arch $(uname -m) for UEFI install" + esac + + # Support the weird 32-bit firmware loading 64-bit kernels + if [ `sysctl -n machdep.efi_arch` == i386 ]; then + ARCHBOOTNAME=ia32 + file=loader_ia32.efi + else + file=loader.efi + fi + + # Copy the boot loader + mntpt="$BSDINSTALL_CHROOT/boot/efi" + f_dprintf "Installing ${file} onto ESP" + uefi_copy_loader "$BSDINSTALL_CHROOT/boot/${file}" \ + "${mntpt}/efi/freebsd" "${mntpt}/efi/boot" \ + boot${ARCHBOOTNAME}.efi + + # zfsboot records the extra esp partitions it creates to -esps. These + # are newfs'd at the time of creation. We don't support installing ufs + # over gmirror, so we only do this for ZFS. + esps=${TMPDIR:-"/tmp"}/bsdinstall-esps + if [ -f "$esps" ]; then + mntpt=$(mktemp -d -t bsdinstall-esp) + for dev in $(cat $esps); do + f_dprintf "Installing ${file} onto redundant ESP ${dev}" + mount -t msdos "$dev" "$mntpt" + uefi_copy_loader "$BSDINSTALL_CHROOT/boot/${file}" \ + "${mntpt}/efi/freebsd" "${mntpt}/efi/boot" \ + boot${ARCHBOOTNAME}.efi + umount "$mntpt" + done + rmdir "${mntpt}" + fi + + # Try to set the UEFI NV BootXXXX variables to record the boot location + if [ "$BSDINSTALL_CONFIGCURRENT" ] && [ "$ARCHBOOTNAME" != ia32 ]; then + update_uefi_bootentry + fi + + f_dprintf "Finished configuring ESP" +fi + +# Add boot0cfg for MBR BIOS booting? diff --git a/usr.sbin/bsdinstall/scripts/checksum b/usr.sbin/bsdinstall/scripts/checksum new file mode 100755 index 000000000000..ee93cb342f25 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/checksum @@ -0,0 +1,87 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +test -f $BSDINSTALL_DISTDIR/MANIFEST || exit 0 + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +dist_to_statusvar() +{ + printf 'status_' + echo "$1" | sed 's/_/__/g;s/\./_dot_/g;s/-/_dash_/g' +} + +percentage=0 +for dist in $DISTRIBUTIONS; do + statusvar=$(dist_to_statusvar $dist) + eval "$statusvar=-8" + + items="" + for i in $DISTRIBUTIONS; do + items="$items $i `eval echo \\\${$(dist_to_statusvar $i):--11}`" + done + bsddialog --backtitle "$OSNAME Installer" --title "Checksum Verification" \ + --mixedgauge "\nVerifying checksums of selected distributions.\n" \ + 0 0 $percentage -- $items + + CK=`sha256 -q $BSDINSTALL_DISTDIR/$dist` + awk -v checksum=$CK -v dist=$dist -v found=0 '{ + if (dist == $1) { + found = 1 + if (checksum == $2) + exit(0) + else + exit(2) + } + } END {if (!found) exit(1);}' $BSDINSTALL_DISTDIR/MANIFEST + + CK_VALID=$? + if [ $CK_VALID -le 1 ]; then + if [ $CK_VALID -eq 0 ]; then + eval "$statusvar=-3" + else + eval "$statusvar=-7" + fi + percentage=$(echo $percentage + 100/`echo $DISTRIBUTIONS | wc -w` | bc) + else + eval "$statusvar=-2" + case $(/bin/freebsd-version -u) in + *-ALPHA*|*-CURRENT|*-STABLE|*-PRERELEASE) + bsddialog --backtitle "$OSNAME Installer" --title "Error" \ + --msgbox "The checksum for $dist does not match. It may have become corrupted, or it may be from a newer version of $OSNAME. Please check for a newer snapshot." 0 0 + ;; + *) + bsddialog --backtitle "$OSNAME Installer" --title "Error" \ + --msgbox "The checksum for $dist does not match. It may have become corrupted, and should be redownloaded." 0 0 + ;; + esac + exit 1 + fi +done + +exit 0 diff --git a/usr.sbin/bsdinstall/scripts/config b/usr.sbin/bsdinstall/scripts/config new file mode 100755 index 000000000000..ba39b8bdf305 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/config @@ -0,0 +1,59 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2013-2015 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ MAIN + +cat $BSDINSTALL_TMPETC/rc.conf.* >> $BSDINSTALL_TMPETC/rc.conf +rm $BSDINSTALL_TMPETC/rc.conf.* + +cat $BSDINSTALL_CHROOT/etc/sysctl.conf $BSDINSTALL_TMPETC/sysctl.conf.* >> $BSDINSTALL_TMPETC/sysctl.conf +rm $BSDINSTALL_TMPETC/sysctl.conf.* + +if [ -f $BSDINSTALL_TMPETC/ttys.hardening ]; then + cat $BSDINSTALL_TMPETC/ttys.hardening > $BSDINSTALL_TMPETC/ttys + rm $BSDINSTALL_TMPETC/ttys.hardening +fi + +cp $BSDINSTALL_TMPETC/* $BSDINSTALL_CHROOT/etc + +cat $BSDINSTALL_TMPBOOT/loader.conf.* >> $BSDINSTALL_TMPBOOT/loader.conf +rm $BSDINSTALL_TMPBOOT/loader.conf.* +df -t zfs $BSDINSTALL_CHROOT > /dev/null && echo "zfs_load=\"YES\"" >> $BSDINSTALL_TMPBOOT/loader.conf + +cp $BSDINSTALL_TMPBOOT/* $BSDINSTALL_CHROOT/boot + +[ "${debugFile#+}" ] && cp "${debugFile#+}" $BSDINSTALL_CHROOT/var/log/ + +# Set up other things from installed config +chroot $BSDINSTALL_CHROOT /usr/bin/newaliases > /dev/null 2>&1 + +exit 0 + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdinstall/scripts/docsinstall b/usr.sbin/bsdinstall/scripts/docsinstall new file mode 100755 index 000000000000..68a5798b0493 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/docsinstall @@ -0,0 +1,166 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Marc Fonvieille +# Copyright (c) 2013-2015 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +f_include $BSDCFG_SHARE/packages/packages.subr + +############################################################ CONFIGURATION + +# +# List of languages to display (descriptions pulled from $msg_{lang}doc_desc) +# +: ${DOCSINSTALL_LANGS:=\ + bn da de el en es fr hu id it ja ko mn nl pl pt ru tr zh_cn zh_tw \ +} + +############################################################ GLOBALS + +# +# Strings that should be moved to an i18n file and loaded with f_include_lang() +# +hline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER" +msg_bndoc_desc="Bengali Documentation" +msg_cancel="Cancel" +msg_dadoc_desc="Danish Documentation" +msg_dedoc_desc="German Documentation" +msg_docsinstall_menu_text="This menu allows you to install the whole documentation set from\nthe $OSNAME Documentation Project: Handbook, FAQ, and articles.\n\nPlease select the language versions you wish to install. At\nminimum, you should install the English version, the original\nversion of the documentation." +msg_eldoc_desc="Greek Documentation" +msg_endoc_desc="English Documentation (recommended)" +msg_esdoc_desc="Spanish Documentation" +msg_frdoc_desc="French Documentation" +msg_freebsd_documentation_installation="$OSNAME Documentation Installation" +msg_freebsd_installer="$OSNAME Installer" +msg_hudoc_desc="Hungarian Documentation" +msg_iddoc_desc="Indonesian Documentation" +msg_itdoc_desc="Italian Documentation" +msg_jadoc_desc="Japanese Documentation" +msg_kodoc_desc="Korean Documentation" +msg_mndoc_desc="Mongolian Documentation" +msg_nldoc_desc="Dutch Documentation" +msg_ok="OK" +msg_pldoc_desc="Polish Documentation" +msg_ptdoc_desc="Portuguese Documentation" +msg_rudoc_desc="Russian Documentation" +msg_trdoc_desc="Turkish Documentation" +msg_zh_cndoc_desc="Simplified Chinese Documentation" +msg_zh_twdoc_desc="Traditional Chinese Documentation" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local title="$DIALOG_TITLE" + local btitle="$DIALOG_BACKTITLE" + local prompt="$msg_docsinstall_menu_text" + local check_list= # Calculated below + local hline="$hline_arrows_space_tab_enter" + + local lang desc upper status + for lang in $DOCSINSTALL_LANGS; do + # Fetch the i18n description to display + f_getvar msg_${lang}doc_desc desc + f_shell_escape "$desc" desc + + # Get default status for each language + upper=$( echo "$lang" | awk '{print toupper($0)}' ) + case "$lang" in + en) f_getvar DIST_DOC_$upper:-on status ;; + *) f_getvar DIST_DOC_$upper:-off status + esac + + check_list="$check_list + '$lang' '$desc' '$status' + " # END-QUOTE + done + + local height width rows + eval f_dialog_checklist_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$prompt\" \ + \"\$hline\" \ + $check_list + local selected + selected=$( eval $DIALOG \ + --title \"\$title\" \ + --backtitle \"\$btitle\" \ + --separate-output \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --checklist \"\$prompt\" \ + $height $width $rows \ + $check_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_menutag_store -s "$selected" + return $retval +} + +############################################################ MAIN + +# +# Initialize +# +f_dialog_title "$msg_freebsd_documentation_installation" +f_dialog_backtitle "$msg_freebsd_installer" +f_mustberoot_init + +# +# Launch application main menu +# +dialog_menu_main || f_die +f_dialog_menutag_fetch selected + +# Let pkg(8) be able to use name servers +f_quietly cp -f $BSDINSTALL_TMPETC/resolv.conf $BSDINSTALL_CHROOT/etc/ + +# +# Install each of the selected packages +# +docsets="" +for lang in $selected; do + docsets="$docsets $lang-freebsd-doc" +done + +ASSUME_ALWAYS_YES=YES chroot $BSDINSTALL_CHROOT pkg install $docsets + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdinstall/scripts/entropy b/usr.sbin/bsdinstall/scripts/entropy new file mode 100755 index 000000000000..91ccbf99fbcc --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/entropy @@ -0,0 +1,33 @@ +#!/bin/sh +#- +# Copyright (c) 2013 Dag-Erling Smørgrav +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +umask 077 +for i in /entropy /boot/entropy; do + i="$BSDINSTALL_CHROOT/$i" + dd if=/dev/random of="$i" bs=4096 count=1 + chown 0:0 "$i" +done diff --git a/usr.sbin/bsdinstall/scripts/fetchmissingdists b/usr.sbin/bsdinstall/scripts/fetchmissingdists new file mode 100644 index 000000000000..f5da3ee45c39 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/fetchmissingdists @@ -0,0 +1,131 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2013-2018 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +error() +{ + bsddialog --backtitle "$OSNAME Installer" --title "Error" --msgbox "$1" 0 0 + exit 1 +} + +FETCH_DISTRIBUTIONS="" +LOCAL_DISTRIBUTIONS="" +for dist in $DISTRIBUTIONS; do + if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then + FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist" + else + LOCAL_DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS $dist" + fi +done +LOCAL_DISTRIBUTIONS=`echo $LOCAL_DISTRIBUTIONS` # Trim white space +FETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS` # Trim white space + +if [ -z "$FETCH_DISTRIBUTIONS" ]; then + echo $BSDINSTALL_DISTDIR >&2 + exit 0 +fi + +WANT_DEBUG= + +# Download to a directory in the new system as scratch space +BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist" +mkdir -p "$BSDINSTALL_FETCHDEST" || error "Could not create directory $BSDINSTALL_FETCHDEST" + +if [ -z "$BSDINSTALL_DISTSITE" ]; then + exec 5>&1 + BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&5) + MIRROR_BUTTON=$? + exec 5>&- + test $MIRROR_BUTTON -eq 0 || error "No mirror selected" + export BSDINSTALL_DISTSITE +fi + +BSDINSTALL_DISTDIR_ORIG="$BSDINSTALL_DISTDIR" +export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST" +export FTP_PASSIVE_MODE=YES + +if [ -f "$BSDINSTALL_DISTDIR_ORIG/MANIFEST" ]; then + cp "$BSDINSTALL_DISTDIR_ORIG/MANIFEST" "$BSDINSTALL_DISTDIR/MANIFEST" +else + FETCH_DISTRIBUTIONS="MANIFEST $FETCH_DISTRIBUTIONS" + + # XXX actually verify signature on manifest + bsddialog --backtitle "$OSNAME Installer" --title "Warning" --msgbox "Manifest not found on local disk and will be fetched from an unverified source. This is a potential security risk. If you do not wish to proceed, press control-C now." 0 0 +fi + +if [ ! -z "$LOCAL_DISTRIBUTIONS" ]; then + # Copy local stuff first + env DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS" \ + BSDINSTALL_DISTSITE="file://$BSDINSTALL_DISTDIR_ORIG" \ + bsdinstall distfetch || \ + error "Failed to fetch distribution from local media" +fi + +export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS" + +# Iterate through the distribution list and set a flag if debugging +# distributions have been selected. +for _DISTRIBUTION in $DISTRIBUTIONS; do + case $_DISTRIBUTION in + *-dbg.*) + [ -e $BSDINSTALL_DISTDIR/$_DISTRIBUTION ] \ + && continue + WANT_DEBUG=1 + DEBUG_LIST="\n$DEBUG_LIST\n$_DISTRIBUTION" + ;; + *) + ;; + esac +done + +# Fetch the distributions. +bsdinstall distfetch +rc=$? + +if [ $rc -ne 0 ]; then + # If unable to fetch the remote distributions, recommend + # deselecting the debugging distributions, and retrying the + # installation, since failure to fetch *-dbg.txz should not + # be considered a fatal installation error. + msg="Failed to fetch remote distribution" + if [ ! -z "$WANT_DEBUG" ]; then + # Trim leading and trailing newlines. + DEBUG_LIST="${DEBUG_LIST%%\n}" + DEBUG_LIST="${DEBUG_LIST##\n}" + msg="$msg\n\nPlease deselect the following distributions" + msg="$msg and retry the installation:" + msg="$msg\n$DEBUG_LIST" + fi + error "$msg" +fi + +echo $BSDINSTALL_DISTDIR >&2 + diff --git a/usr.sbin/bsdinstall/scripts/finalconfig b/usr.sbin/bsdinstall/scripts/finalconfig new file mode 100755 index 000000000000..c7814a3b6a45 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/finalconfig @@ -0,0 +1,90 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2013-2018 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +: ${BSDDIALOG_OK=0} + +while true; do + exec 5>&1 + REVISIT=$(bsddialog --backtitle "$OSNAME Installer" \ + --title "Final Configuration" --ok-label "Select" \ + --no-cancel --menu \ + "Setup of your $OSNAME system is nearly complete. You can now modify your configuration choices. After this screen, you will have an opportunity to make more complex changes using a shell." 0 0 0 \ + "Finish" "Apply configuration and exit installer" \ + "Add User" "Add a user to the system" \ + "Root Password" "Change root password" \ + "Hostname" "Set system hostname" \ + "Network" "Networking configuration" \ + "Services" "Set daemons to run on startup" \ + "System Hardening" "Set security options" \ + "Time Zone" "Set system timezone" \ + "Firmware" "Install Firmware (requires network)" \ + "Handbook" "Install $OSNAME Handbook (requires network)" 2>&1 1>&5) + retval=$? + exec 5>&- + + if [ $retval -ne $BSDDIALOG_OK ]; then + break + fi + + case "$REVISIT" in + "Finish") + break + ;; + "Add User") + bsdinstall adduser + ;; + "Root Password") + bsdinstall rootpass + ;; + "Hostname") + bsdinstall hostname + ;; + "Network") + bsdinstall netconfig + ;; + "Services") + bsdinstall services + ;; + "System Hardening") + bsdinstall hardening + ;; + "Time Zone") + bsdinstall time + ;; + "Firmware") + bsdinstall firmware + ;; + "Handbook") + bsdinstall docsinstall + ;; + esac +done diff --git a/usr.sbin/bsdinstall/scripts/firmware b/usr.sbin/bsdinstall/scripts/firmware new file mode 100644 index 000000000000..0fc66f0a0261 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/firmware @@ -0,0 +1,137 @@ +#!/bin/sh +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 The FreeBSD Foundation +# +# This software was developed by Björn Zeeb +# under sponsorship from the FreeBSD Foundation. +# + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +f_include $BSDCFG_SHARE/packages/packages.subr + +msg_freebsd_firmware_installation="$OSNAME Firmware Installation" +msg_freebsd_installer="$OSNAME Installer" +msg_firmware_menu_text="This menu allows you to install firmware packages for your system" +hline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER" +hline_ok="Press OK to continue" + +dialog_menu_main() +{ + local title="$DIALOG_TITLE" + local btitle="$DIALOG_BACKTITLE" + local prompt="$msg_firmware_menu_text" + local hline + local check_list= # Empty; filled below + local fwlist _fw + + fwlist=`chroot $BSDINSTALL_CHROOT fwget -q -n` + case "${fwlist}" in + "") # No firmware to install + # Print a dialog with OK and a 3 line timeout bar. + local height width rows msg + + msg="No firmware to install, continuing..." + hline="$hline_ok" + + eval f_dialog_checklist_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$msg\" \ + \"-\" \ + \"n\" \ + \"-\" \ + \"\$hline\" + + ${DIALOG} --title "${title}" --backtitle "${btitle}" \ + --hline "${hline}" \ + --nocancel --pause "${msg}" $height $width 5 + f_dialog_menutag_store -s "" + return $DIALOG_OK + ;; + *) + local desc status height width rows selected retval + hline="$hline_arrows_space_tab_enter" + + for _fw in ${fwlist}; do + desc="${_fw}" + f_shell_escape "$desc" desc + # install each firmware package by default. + check_list="$check_list + '$_fw' '$desc' 'on' + " + done + + eval f_dialog_checklist_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$prompt\" \ + \"\$hline\" \ + $check_list + + selected=$( eval $DIALOG \ + --title \"\$title\" \ + --backtitle \"\$btitle\" \ + --separate-output \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --checklist \"\$prompt\" \ + $height $width $rows \ + $check_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + retval=$? + f_dialog_menutag_store -s "$selected" + return $retval + ;; + esac +} + +# Initialize +f_dialog_title "$msg_freebsd_firmware_installation" +f_dialog_backtitle "$msg_freebsd_installer" + +# Gather the firmware files and present them to the user +dialog_menu_main || f_die +f_dialog_menutag_fetch selected + +# Nothing to install? +if [ "${selected}" == "" ]; then + exit 0 +fi + +f_mustberoot_init + +# pkg(8) needs name servers (unless we could use a local repo in the future). +f_quietly cp -f $BSDINSTALL_TMPETC/resolv.conf $BSDINSTALL_CHROOT/etc/ + +${DIALOG} --title "$DIALOG_TITLE" --backtitle "$DIALOG_BACKTITLE" \ + --infobox "Installing firmware. This may take a moment." 0 0 + +pkg_install_fail= +# Install each of the selected firmware packages +for fw in ${selected}; do + # We install one at a time in case one is not avail. + # pkg-install.8 needs an option to skip unavail. + ASSUME_ALWAYS_YES=YES chroot $BSDINSTALL_CHROOT pkg install -qy ${fw} + if [ $? -ne 0 ]; then + pkg_install_fail="$pkg_install_fail $fw" + fi +done +if [ -n "$pkg_install_fail" ]; then + # Error(s) were likely spammed to the console; give the user a moment + # to read them. + sleep 5 + bsddialog --backtitle "$OSNAME Installer" --title "Error" \ + --msgbox "Error fetching firmware file(s)$pkg_install_fail" 0 0 + exit 1 +fi + +# end diff --git a/usr.sbin/bsdinstall/scripts/hardening b/usr.sbin/bsdinstall/scripts/hardening new file mode 100755 index 000000000000..a77fcdeaf540 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/hardening @@ -0,0 +1,93 @@ +#!/bin/sh +#- +# Copyright (c) 2016 Bartek Rutkowski +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +: ${BSDDIALOG_OK=0} + +echo -n > $BSDINSTALL_TMPETC/rc.conf.hardening +echo -n > $BSDINSTALL_TMPETC/sysctl.conf.hardening +echo -n > $BSDINSTALL_TMPBOOT/loader.conf.hardening + +exec 5>&1 +FEATURES=$( bsddialog --backtitle "$OSNAME Installer" \ + --title "System Hardening" --nocancel --separate-output \ + --checklist "Choose system security hardening options:" \ + 0 0 0 \ + "0 hide_uids" "Hide processes running as other users" ${hide_uids:-off} \ + "1 hide_gids" "Hide processes running as other groups" ${hide_gids:-off} \ + "2 hide_jail" "Hide processes running in jails" ${hide_jail:-off} \ + "3 read_msgbuf" "Disable reading kernel message buffer for unprivileged users" ${read_msgbuf:-off} \ + "4 proc_debug" "Disable process debugging facilities for unprivileged users" ${proc_debug:-off} \ + "5 random_pid" "Randomize the PID of newly created processes" ${random_pid:-off} \ + "6 clear_tmp" "Clean the /tmp filesystem on system startup" ${clear_tmp:-off} \ + "7 disable_syslogd" "Disable opening Syslogd network socket (disables remote logging)" ${disable_syslogd:-off} \ + "8 secure_console" "Enable console password prompt" ${secure_console:-off} \ + "9 disable_ddtrace" "Disallow DTrace destructive-mode" ${disable_ddtrace:-off} \ +2>&1 1>&5 ) +retval=$? +exec 5>&- + +if [ $retval -ne $BSDDIALOG_OK ]; then + exit 1 +fi + +for feature in $FEATURES; do + case "$feature" in + hide_uids) + echo security.bsd.see_other_uids=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening + ;; + hide_gids) + echo security.bsd.see_other_gids=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening + ;; + hide_jail) + echo security.bsd.see_jail_proc=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening + ;; + read_msgbuf) + echo security.bsd.unprivileged_read_msgbuf=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening + ;; + proc_debug) + echo security.bsd.unprivileged_proc_debug=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening + ;; + random_pid) + echo kern.randompid=1 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening + ;; + clear_tmp) + echo 'clear_tmp_enable="YES"' >> $BSDINSTALL_TMPETC/rc.conf.hardening + ;; + disable_syslogd) + echo 'syslogd_flags="-ss"' >> $BSDINSTALL_TMPETC/rc.conf.hardening + ;; + secure_console) + sed "s/unknown off secure/unknown off insecure/g" $BSDINSTALL_CHROOT/etc/ttys > $BSDINSTALL_TMPETC/ttys.hardening + ;; + disable_ddtrace) + echo 'security.bsd.allow_destructive_dtrace=0' >> $BSDINSTALL_TMPBOOT/loader.conf.hardening + ;; + esac +done diff --git a/usr.sbin/bsdinstall/scripts/hostname b/usr.sbin/bsdinstall/scripts/hostname new file mode 100755 index 000000000000..19df8885893b --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/hostname @@ -0,0 +1,124 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2015-2018 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading_includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr + +############################################################ CONFIGURATION + +# +# Default value +# +: ${HOSTNAME=$( hostname )} + +# +# Default file to store hostname entry in +# +: ${HOSTNAMEFILE:=$BSDINSTALL_TMPETC/rc.conf.hostname} + +############################################################ GLOBALS + +# +# Strings that should be moved to an i18n file and loaded with f_include_lang() +# +msg_freebsd_installer="$OSNAME Installer" +msg_ok="OK" +msg_please_choose_a_hostname="Please choose a hostname for this machine.\n\nIf you are running on a managed network, please ask\nyour network administrator for an appropriate name." +msg_set_hostname="Set Hostname" + +# +# Command strings for various tasks +# +ECHO_OVERWRITE='echo "%s" > "%s"' +SET_HOSTNAME='hostname -s "%s"' + +############################################################ FUNCTIONS + +# dialog_hostname +# +# Display input box (without cancel button) for user to enter desired hostname. +# +dialog_hostname() +{ + local prompt="$msg_please_choose_a_hostname" + local hline= + local value="$*" + + local height width + f_dialog_inputbox_size height width \ + "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$prompt" "$value" "$hline" + + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --no-cancel \ + --inputbox "$prompt" \ + $height $width "$value" \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD +} + +############################################################ MAIN + +# +# Initialize +# +f_dialog_title "$msg_set_hostname" +f_dialog_backtitle "$msg_freebsd_installer" + +# +# Get user input +# +HOSTNAME=$( dialog_hostname "$HOSTNAME" ) +[ $? -eq $DIALOG_CANCEL ] && exit 1 + +# +# Store the user's choice +# +f_eval_catch "$pgm" echo "$ECHO_OVERWRITE" \ + 'hostname=\"$HOSTNAME\"' "$HOSTNAMEFILE" +retval=$? + +# +# Activate entry if configured +# +if [ "$BSDINSTALL_CONFIGCURRENT" ]; then + f_eval_catch "$pgm" hostname "$SET_HOSTNAME" "$HOSTNAME" + retval=$? +fi + +exit $retval + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdinstall/scripts/jail b/usr.sbin/bsdinstall/scripts/jail new file mode 100755 index 000000000000..e4238ac0a687 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/jail @@ -0,0 +1,231 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2013-2015 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +############################################################ GLOBALS + +# +# List of environment variables that may be defined by the user, but modified +# during the installation process. They are then restored when restarting this +# script. +# +user_env_vars="BSDINSTALL_DISTSITE DISTRIBUTIONS" + +############################################################ FUNCTIONS + +# error [$msg] +# +# Display generic error message when a script fails. An optional message +# argument can precede the generic message. User is given the choice of +# restarting the installer or exiting. +# +error() { + local msg + if [ -n "$1" ]; then + msg="$1\n\n" + fi + bsddialog --backtitle "$OSNAME Installer" --title "Abort" \ + --no-label "Exit" --yes-label "Restart" --yesno \ + "${msg}An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0 + if [ $? -ne $BSDDIALOG_OK ]; then + exit + else + environment_restore + exec $0 $BSDINSTALL_CHROOT + fi +} + +distbase() { + test ! -d $BSDINSTALL_DISTDIR && mkdir -p $BSDINSTALL_DISTDIR + + if [ ! -f $BSDINSTALL_DISTDIR/MANIFEST -a -z "$BSDINSTALL_DISTSITE" ]; then + exec 5>&1 + BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&5) + MIRROR_BUTTON=$? + exec 5>&- + test $MIRROR_BUTTON -eq 0 || error "No mirror selected" + export BSDINSTALL_DISTSITE + fetch -o $BSDINSTALL_DISTDIR/MANIFEST $BSDINSTALL_DISTSITE/MANIFEST || error "Could not download $BSDINSTALL_DISTSITE/MANIFEST" + fi + + : ${DISTRIBUTIONS="base.txz"}; export DISTRIBUTIONS + if [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then + DISTMENU=$(cut -f 1,5,6 $BSDINSTALL_DISTDIR/MANIFEST | grep -v -e ^kernel -e ^base | sed -E 's/\.txz//g') + + if [ ! "$nonInteractive" == "YES" ] + then + exec 5>&1 + EXTRA_DISTS=$(echo $DISTMENU | xargs -o bsddialog \ + --backtitle "$OSNAME Installer" \ + --title "Distribution Select" --no-cancel \ + --separate-output \ + --checklist "Choose optional system components to install:" \ + 0 0 0 \ + 2>&1 1>&5) + for dist in $EXTRA_DISTS; do + export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz" + done + fi + fi + + FETCH_DISTRIBUTIONS="" + for dist in $DISTRIBUTIONS; do + if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then + FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist" + fi + done + FETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS` # Trim white space + + if [ -n "$FETCH_DISTRIBUTIONS" -a -z "$BSDINSTALL_DISTSITE" ]; then + exec 5>&1 + BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&5) + MIRROR_BUTTON=$? + exec 5>&- + test $MIRROR_BUTTON -eq 0 || error "No mirror selected" + export BSDINSTALL_DISTSITE + fi + + if [ ! -z "$FETCH_DISTRIBUTIONS" ]; then + bsdinstall distfetch || error "Failed to fetch distribution" + fi + + bsdinstall checksum || error "Distribution checksum failed" + bsdinstall distextract || error "Distribution extract failed" +} + +# environment_restore +# +# Restore a list of environment variables when this script is restarted. +# +environment_restore() +{ + for var in $user_env_vars; do + eval "if [ -n \"\${ORIG_$var}\" -o -z \"\${ORIG_$var-z}\" ]; then $var=\${ORIG_$var}; else unset $var; fi" + done +} + +# environment_save +# +# Save any user-defined environment variable that may be modified during the +# installation process. They are then restored when restarting this script. +# +environment_save() +{ + for var in $user_env_vars; do + eval "if [ -n \"\${$var}\" -o -z \"\${$var-z}\" ]; then ORIG_$var=\${$var}; else unset ORIG_$var; fi" + done +} + +############################################################ MAIN + +: ${BSDDIALOG_OK=0} + +f_dprintf "Began Installation at %s" "$( date )" + +if [ -z "$1" ]; then + error "Directory can not be empty\n\nUsage:\nbsdinstall jail directory" +fi +export BSDINSTALL_CHROOT=$1 + +environment_save + +rm -rf $BSDINSTALL_TMPETC +mkdir $BSDINSTALL_TMPETC +mkdir -p $1 || error "mkdir failed for $1" +rm -f $TMPDIR/bsdinstall-installscript-setup + +if [ -n "$SCRIPT" ]; then + # split script into preamble and setup script at first shebang + awk 'BEGIN {pathb=ARGV[2]; ARGV[2]=""} /^#!/{b=1} { + if (b) print >pathb; else print}' \ + "$SCRIPT" $TMPDIR/bsdinstall-installscript-setup \ + >$TMPDIR/bsdinstall-installscript-preamble + + . $TMPDIR/bsdinstall-installscript-preamble +fi + +if [ ! "$nonInteractive" == "YES" ]; then + bsddialog --backtitle "$OSNAME Installer" --title "Select Installation Type" \ + --yes-label "Distribution Sets" --no-label "Packages (Tech Preview)" --yesno \ + "Would you like to install the base system using traditional distribution sets or packages (technology preview)?" 0 0 + if [ $? -eq 1 ]; then + PKGBASE=yes + fi +fi + +if [ "$PKGBASE" == yes ]; then + bsdinstall pkgbase --jail || error "Installation of base system packages failed" +else + distbase +fi + +if [ ! "$nonInteractive" == "YES" ] +then + bsdinstall rootpass || error "Could not set root password" +fi + +trap true SIGINT # This section is optional + +if [ ! "$nonInteractive" == "YES" ] +then +bsdinstall services + + bsddialog --backtitle "$OSNAME Installer" --title "Add User Accounts" --yesno \ + "Would you like to add users to the installed system now?" 0 0 && \ + bsdinstall adduser +fi + +trap error SIGINT # SIGINT is bad again +bsdinstall config || error "Failed to save config" +cp /etc/resolv.conf $1/etc +cp -P /etc/localtime $1/etc +cp /var/db/zoneinfo $1/var/db + +# Run post-install script +if [ -f $TMPDIR/bsdinstall-installscript-setup ]; then + cp $TMPDIR/bsdinstall-installscript-setup \ + $BSDINSTALL_CHROOT/tmp/installscript + chmod a+x $BSDINSTALL_CHROOT/tmp/installscript + mount -t devfs devfs "$BSDINSTALL_CHROOT/dev" + chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1 + umount "$BSDINSTALL_CHROOT/dev" + rm $BSDINSTALL_CHROOT/tmp/installscript +fi + +bsdinstall entropy + +f_dprintf "Installation Completed at %s" "$(date)" +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdinstall/scripts/keymap b/usr.sbin/bsdinstall/scripts/keymap new file mode 100755 index 000000000000..669a1062df95 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/keymap @@ -0,0 +1,232 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2013-2015 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/keymap.subr +f_include $BSDCFG_SHARE/sysrc.subr + +############################################################ CONFIGURATION + +# +# Default file to store keymap selection in +# +: ${KEYMAPFILE:=$BSDINSTALL_TMPETC/rc.conf.keymap} + +############################################################ GLOBALS + +# +# Strings that should be moved to an i18n file and loaded with f_include_lang() +# +hline_arrows_tab_enter="Press arrows, TAB or ENTER" +msg_continue_with_keymap="Continue with %s keymap" +msg_default="default" +msg_error="Error" +msg_freebsd_installer="$OSNAME Installer" +msg_keymap_menu_text="The system console driver for $OSNAME defaults to standard \"US\"\nkeyboard map. Other keymaps can be chosen below." +msg_keymap_selection="Keymap Selection" +msg_ok="OK" +msg_select="Select" +msg_test_keymap="Test %s keymap" +msg_test_the_currently_selected_keymap="Test the currently selected keymap" +msg_test_the_keymap_by_typing="Test the keymap by typing letters, numbers, and symbols. Characters\nshould match labels on the keyboard keys. Press Enter to stop testing." + +############################################################ FUNCTIONS + +# dialog_keymap_test $keymap +# +# Activate $keymap and display an input box (without cancel button) for the +# user to test keyboard input and return. Always returns success. +# +dialog_keymap_test() +{ + local keym="$1" + local title= # Calculated below + local btitle= # Calculated below + local prompt="$msg_test_the_keymap_by_typing" + local hline= + + # Attempt to activate the keymap + if [ "$keym" ]; then + local err + err=$( f_keymap_kbdcontrol "$keym" 2>&1 > /dev/null ) + if [ "$err" ]; then + f_dialog_title "$msg_error" + f_dialog_msgbox "$err" + f_dialog_title_restore + return $FAILURE + fi + fi + + f_dialog_title "$( printf "$msg_test_keymap" "${keym:-$msg_default}" )" + title="$DIALOG_TITLE" + btitle="$DIALOG_BACKTITLE" + f_dialog_title_restore + + local height width + f_dialog_inputbox_size height width \ + "$title" "$btitle" "$prompt" "" "$hline" + + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --no-cancel \ + --inputbox "$prompt" \ + $height $width \ + 2>/dev/null >&$DIALOG_TERMINAL_PASSTHRU_FD + + return $DIALOG_OK +} + +############################################################ MAIN + +# +# Initialize +# +f_dialog_title "$msg_keymap_selection" +f_dialog_backtitle "$msg_freebsd_installer" + +# +# Die immediately if we can't dump the current keyboard map +# +#error=$( kbdcontrol -d 2>&1 > /dev/null ) || f_die $FAILURE "%s" "$error" + +# Capture Ctrl-C for clean-up +trap 'rm -f $KEYMAPFILE; exit $FAILURE' SIGINT + +# Get a value from rc.conf(5) as initial value (if not being scripted) +f_getvar $VAR_KEYMAP keymap +if [ ! "$keymap" ]; then + keymap=$( f_sysrc_get keymap ) + case "$keymap" in [Nn][Oo]) keymap="";; esac +fi + +# +# Loop until the user has finalized their selection (by clicking the +# [relabeled] Cancel button). +# +width=67 first_pass=1 back_from_testing= +[ "$USE_XDIALOG" ] && width=70 +prompt="$msg_keymap_menu_text" +hline="$hline_arrows_tab_enter" +while :; do + # + # Re/Build list of keymaps + # + cont_msg=$( printf "$msg_continue_with_keymap" \ + "${keymap:-$msg_default}" ) + test_msg=$( printf "$msg_test_keymap" "${keymap:-$msg_default}" ) + menu_list=" + '>>> $cont_msg' '' '$msg_continue_with_current_keymap' + '->- $test_msg' '' '$msg_test_the_currently_selected_keymap' + " # END-QUOTE + if [ "$first_pass" ]; then + defaultitem= + first_pass= + else + defaultitem="->- $test_msg" + fi + for k in $KEYMAPS; do + keymap_$k get keym keym + keymap_$k get desc desc + radio=" " + if [ "$keym" = "$keymap" ]; then + radio="*" + if [ "$back_from_testing" ]; then + defaultitem="(*) $desc" + back_from_testing= + fi + fi + f_shell_escape "$desc" desc + menu_list="$menu_list + '($radio) $desc' '' '$keym: $desc' + " # END-QUOTE + done + back_from_testing= + + # + # Display keymap configuration menu + # + eval f_dialog_menu_with_help_size height \"\" rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --keep-tite \ + --item-help \ + --ok-label \"\$msg_select\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + ${USE_DIALOG:+--} $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) || { + f_quietly rm -f "$KEYMAPFILE" + exit $FAILURE # Exit with an error so bsdinstall restarts + } + f_dialog_data_sanitize menu_choice + + case "$menu_choice" in + ">>> "*) # Continue with keymap + break ;; + "->-"*) # Test keymap + dialog_keymap_test "$keymap" + back_from_testing=1 + continue ;; + esac + + # Turn the user's choice into a number + n=$( eval f_dialog_menutag2index_with_help \ + \"\$menu_choice\" $menu_list ) + + # Turn that number into the name of the keymap struct + k=$( set -- $KEYMAPS; eval echo \"\${$(( $n - 2))}\" ) + + # Get actual keymap setting while we update $keymap and $KEYMAPFILE + keymap_$k get keym keymap + echo "keymap=\"$keymap\"" > "$KEYMAPFILE" +done + +f_quietly f_keymap_kbdcontrol "$keymap" +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdinstall/scripts/mirrorselect b/usr.sbin/bsdinstall/scripts/mirrorselect new file mode 100755 index 000000000000..05eff9fee56e --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/mirrorselect @@ -0,0 +1,127 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +: ${BSDDIALOG_OK=0} +: ${BSDDIALOG_CANCEL=1} +: ${BSDDIALOG_HELP=2} +: ${BSDDIALOG_EXTRA=3} +: ${BSDDIALOG_ESC=5} +: ${BSDDIALOG_ERROR=255} + +exec 5>&1 +MIRROR=`bsddialog --backtitle "$OSNAME Installer" \ + --title "Mirror Selection" --extra-button --extra-label "Other" \ + --menu "Please select the best suitable site for you or \"other\" if you want to specify a different choice. The \"Main Site\" directs users to the nearest project managed mirror via GeoDNS (they carry the full range of possible distributions and support both IPv4 and IPv6). All other sites are known as \"Community Mirrors\"; not every site listed here carries more than the base distribution kits. Select a site!" \ + 0 0 16 \ + http://ftp.freebsd.org "Main Site (GeoDNS, HTTP)"\ + ftp://ftp.freebsd.org "Main Site (GeoDNS, FTP)"\ + http://ftp.au.freebsd.org "Australia - IPv6"\ + ftp://ftp3.au.freebsd.org "Australia #3"\ + ftp://ftp.at.freebsd.org "Austria - IPv6"\ + ftp://ftp2.br.freebsd.org "Brazil #2"\ + ftp://ftp3.br.freebsd.org "Brazil #3"\ + ftp://ftp.bg.freebsd.org "Bulgaria - IPv6"\ + ftp://ftp.cz.freebsd.org "Czech Republic - IPv6"\ + ftp://ftp.dk.freebsd.org "Denmark - IPv6"\ + ftp://ftp.fi.freebsd.org "Finland"\ + ftp://ftp.fr.freebsd.org "France - IPv6"\ + ftp://ftp3.fr.freebsd.org "France #3"\ + ftp://ftp6.fr.freebsd.org "France #6"\ + ftp://ftp.de.freebsd.org "Germany - IPv6"\ + ftp://ftp1.de.freebsd.org "Germany #1 - IPv6"\ + ftp://ftp2.de.freebsd.org "Germany #2 - IPv6"\ + ftp://ftp5.de.freebsd.org "Germany #5 - IPv6"\ + ftp://ftp7.de.freebsd.org "Germany #7 - IPv6"\ + ftp://ftp.gr.freebsd.org "Greece - IPv6"\ + ftp://ftp2.gr.freebsd.org "Greece #2 - IPv6"\ + ftp://ftp.jp.freebsd.org "Japan - IPv6"\ + ftp://ftp2.jp.freebsd.org "Japan #2"\ + ftp://ftp3.jp.freebsd.org "Japan #3"\ + ftp://ftp4.jp.freebsd.org "Japan #4"\ + ftp://ftp6.jp.freebsd.org "Japan #6 - IPv6"\ + ftp://ftp.kr.freebsd.org "Korea"\ + ftp://ftp2.kr.freebsd.org "Korea #2"\ + ftp://ftp.lv.freebsd.org "Latvia"\ + ftp://ftp.nl.freebsd.org "Netherlands - IPv6"\ + ftp://ftp2.nl.freebsd.org "Netherlands #2"\ + ftp://ftp.nz.freebsd.org "New Zealand"\ + ftp://ftp.no.freebsd.org "Norway - IPv6"\ + ftp://ftp.pl.freebsd.org "Poland - IPv6"\ + ftp://ftp.ru.freebsd.org "Russia - IPv6"\ + ftp://ftp2.ru.freebsd.org "Russia #2"\ + ftp://ftp.si.freebsd.org "Slovenia - IPv6"\ + ftp://ftp.za.freebsd.org "South Africa - IPv6"\ + ftp://ftp2.za.freebsd.org "South Africa #2 - IPv6"\ + ftp://ftp4.za.freebsd.org "South Africa #4"\ + ftp://ftp.se.freebsd.org "Sweden - IPv6"\ + ftp://ftp4.tw.freebsd.org "Taiwan #4"\ + ftp://ftp5.tw.freebsd.org "Taiwan #5"\ + ftp://ftp.uk.freebsd.org "UK - IPv6"\ + ftp://ftp2.uk.freebsd.org "UK #2 - IPv6"\ + ftp://ftp.ua.FreeBSD.org "Ukraine - IPv6"\ + ftp://ftp5.us.freebsd.org "USA #5 - IPv6"\ + 2>&1 1>&5` +MIRROR_BUTTON=$? +exec 5>&- + +_UNAME_R=`uname -r` +_UNAME_R=${_UNAME_R%-p*} + +case ${_UNAME_R} in + *-ALPHA*|*-CURRENT|*-STABLE|*-PRERELEASE) + RELDIR="snapshots" + ;; + *) + RELDIR="releases" + ;; +esac + +BSDINSTALL_DISTSITE="$MIRROR/pub/FreeBSD/${RELDIR}/`uname -m`/`uname -p`/${_UNAME_R}" + +case $MIRROR_BUTTON in +$BSDDIALOG_ERROR | $BSDDIALOG_CANCEL | $BSDDIALOG_ESC) + exit 1 + ;; +$BSDDIALOG_OK) + ;; +$BSDDIALOG_EXTRA) + exec 5>&1 + BSDINSTALL_DISTSITE=`bsddialog --backtitle "$OSNAME Installer" \ + --title "Mirror Selection" \ + --inputbox "Please enter the URL to an alternate $OSNAME mirror:" \ + 0 74 "$BSDINSTALL_DISTSITE" 2>&1 1>&5` + MIRROR_BUTTON=$? + exec 5>&- + test $MIRROR_BUTTON -eq $BSDDIALOG_OK || exec $0 $@ + ;; +esac + +export BSDINSTALL_DISTSITE +echo $BSDINSTALL_DISTSITE >&2 diff --git a/usr.sbin/bsdinstall/scripts/mount b/usr.sbin/bsdinstall/scripts/mount new file mode 100755 index 000000000000..fd13e13c6a77 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/mount @@ -0,0 +1,63 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +TMP_FSTAB=${TMPDIR:-"/tmp"}/bsdinstall-tmp-fstab + +cat $PATH_FSTAB | awk -v BSDINSTALL_CHROOT=$BSDINSTALL_CHROOT '{ + if ($2 ~ "^/.*") { + fsname = $2; + if (fsname == "/") + fsname = "" + printf("%s\t%s%s\t%s\t%s\t%s\t%s\n", $1, BSDINSTALL_CHROOT, + fsname, $3, $4, $5, $6); + } +}' > $TMP_FSTAB + +FILESYSTEMS=`cat $TMP_FSTAB | awk '/^[^#].*/ {if ($2 ~ "^/.*") printf("%s\n", $2);}' | sort -t /` + +for i in $FILESYSTEMS; do + mkdir -p $i 2>/dev/null + MNTERROR=`mount -F $TMP_FSTAB $i 2>&1` + if [ $? -ne 0 ]; then + bsddialog --backtitle "$OSNAME Installer" --title "Error" \ + --msgbox "Error mounting partition $i:\n$MNTERROR" 0 0 + exit 1 + fi +done + +# User might want a shell and require devfs, so mount it +mkdir $BSDINSTALL_CHROOT/dev 2>/dev/null +mount -t devfs devfs $BSDINSTALL_CHROOT/dev + +# If installing from the DVD, mount packages where they'll be accessible +if [ -d /packages ]; then + mkdir -p $BSDINSTALL_CHROOT/dist/packages + mount -t nullfs /packages $BSDINSTALL_CHROOT/dist/packages +fi diff --git a/usr.sbin/bsdinstall/scripts/netconfig b/usr.sbin/bsdinstall/scripts/netconfig new file mode 100755 index 000000000000..0f23ae134cb6 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/netconfig @@ -0,0 +1,261 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# All rights reserved. +# Copyright (c) 2011 The FreeBSD Foundation +# All rights reserved. +# +# Portions of this software were developed by Bjoern Zeeb +# under sponsorship from the FreeBSD Foundation. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +INTERFACES="" +BSDDIALOG_ITEMS="" + +: ${BSDDIALOG_OK=0} +: ${BSDDIALOG_CANCEL=1} +: ${BSDDIALOG_HELP=2} +: ${BSDDIALOG_EXTRA=3} +: ${BSDDIALOG_ESC=5} +: ${BSDDIALOG_ERROR=255} + +for IF in `ifconfig -l`; do + test "$IF" = "lo0" && continue + (ifconfig -g wlan | egrep -wq $IF) && continue + INTERFACES="$INTERFACES $IF" +done + +WIRELESS_INTERFACES="$(sysctl -in net.wlan.devices)" +INTERFACES="$INTERFACES${WIRELESS_INTERFACES:+ }$WIRELESS_INTERFACES" +is_wireless_if() { + for IF in $(sysctl -in net.wlan.devices); do + if [ $IF = $1 ]; then + return 0 + fi + done + return 1 +} + +for IF in $INTERFACES; do + DESC=`sysctl -n dev.$(echo $IF | sed -E 's/([[:alpha:]]*)([[:digit:]]*)/\1.\2/g').%desc` + BSDDIALOG_ITEMS="$BSDDIALOG_ITEMS $IF \"$DESC\"" +done + +if [ -z "$INTERFACES" ]; then + bsddialog --backtitle "$OSNAME Installer" \ + --title 'Network Configuration' \ + --msgbox 'No network interfaces present to configure.' 0 0 + exit 1 +fi + +exec 5>&1 +INTERFACE=$(echo $BSDDIALOG_ITEMS | xargs -o bsddialog \ + --backtitle "$OSNAME Installer" --title 'Network Configuration' \ + --ok-label 'Auto' --extra-button --extra-label 'Manual' \ + --menu 'Please select a network interface and configuration mode:' 0 0 0 2>&1 1>&5) +# xargs collapses exit codes to 0/1 (ignoring signals and 255), so exploit +# bsddialog output being empty when cancelling to distinguish Manual (Extra) +# from Cancel. +if [ $? -eq $BSDDIALOG_OK ]; then + AUTO=auto +else + if [ -z "$INTERFACE" ]; then + exit 1 + fi + AUTO= +fi +exec 5>&- + +: > $BSDINSTALL_TMPETC/._rc.conf.net + +IFCONFIG_PREFIX="" +if is_wireless_if $INTERFACE; then + NEXT_WLAN_IFACE=wlan0 # XXX + sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net wlans_$INTERFACE="$NEXT_WLAN_IFACE" + IFCONFIG_PREFIX="WPA " + if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then + ifconfig $NEXT_WLAN_IFACE create wlandev $INTERFACE + ifconfig $NEXT_WLAN_IFACE up + fi + bsdinstall wlanconfig $NEXT_WLAN_IFACE || exec $0 + INTERFACE="$NEXT_WLAN_IFACE" +fi + +IPV6_AVAIL=0 +IPV4_AVAIL=0 +sysctl -N kern.features.inet6 > /dev/null 2>&1 +case $? in +0) IPV6_AVAIL=1 ;; +esac +sysctl -N kern.features.inet > /dev/null 2>&1 +case $? in +0) IPV4_AVAIL=1 ;; +esac + +AUTO_FAIL= +if [ ${IPV4_AVAIL} -eq 1 -a -z "$AUTO" ]; then + bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ + --yesno 'Would you like to configure IPv4 for this interface?' 0 0 + if [ $? -ne $BSDDIALOG_OK ]; then + IPV4_AVAIL=0 + fi +fi +if [ ${IPV4_AVAIL} -eq 1 ]; then + bsdinstall netconfig_ipv4 ${INTERFACE} "${IFCONFIG_PREFIX}" $AUTO + if [ $? -ne $BSDDIALOG_OK ]; then + if [ -z "$AUTO" ]; then + exec $0 + fi + IPV4_AVAIL=0 + AUTO_FAIL="$AUTO_FAIL${AUTO_FAIL:+, }IPv4" + fi +fi +# In case wlanconfig left an option and we do not support IPv4 we need to write +# it out on its own. We cannot write it out with IPv6 as that suffix. +if [ ${IPV4_AVAIL} -eq 0 -a -n ${IFCONFIG_PREFIX} ]; then + sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net ifconfig_$INTERFACE="${IFCONFIG_PREFIX}" +fi +if [ ${IPV6_AVAIL} -eq 1 -a -z "$AUTO" ]; then + bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ + --yesno 'Would you like to configure IPv6 for this interface?' 0 0 + if [ $? -ne $BSDDIALOG_OK ]; then + IPV6_AVAIL=0 + fi +fi +if [ ${IPV6_AVAIL} -eq 1 ]; then + bsdinstall netconfig_ipv6 ${INTERFACE} $AUTO + if [ $? -ne $BSDDIALOG_OK ]; then + if [ -z "$AUTO" ]; then + exec $0 + fi + IPV6_AVAIL=0 + AUTO_FAIL="$AUTO_FAIL${AUTO_FAIL:+, }IPv6" + fi +fi + +SEARCH="" +IP4_1="" +IP4_2="" +IP6_1="" +IP6_2="" +while read key value; do + case "${key}" in + search) SEARCH="${value}" ;; + nameserver) # is more trick as we have to distinguish v4 and v6 + case "${value}" in + [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*) + if [ -z "${IP4_1}" ] ; then + IP4_1="${value}" + elif [ -z "${IP4_2}" ]; then + IP4_2="${value}" + fi + ;; + [0-9A-Fa-f:]*:*) + if [ -z "${IP6_1}" ] ; then + IP6_1="${value}" + elif [ -z "${IP6_2}" ]; then + IP6_2="${value}" + fi + ;; + esac + ;; + # ignore others + esac +done < ${BSDINSTALL_TMPETC}/resolv.conf + +RESOLV="" +if [ ${IPV6_AVAIL} -eq 1 -a ${IPV4_AVAIL} -eq 1 ]; then + RESOLV=" + 'Search' 1 1 \"${SEARCH}\" 1 16 50 50 0 + 'Nameserver' 2 1 \"Nameserver\" 2 1 11 11 2 + 'IPv6 DNS #1' 2 1 \"${IP6_1}\" 2 16 50 50 0 + 'IPv6 DNS #2' 3 1 \"${IP6_2}\" 3 16 50 50 0 + 'IPv4 DNS #1' 4 1 \"${IP4_1}\" 4 16 16 16 0 + 'IPv4 DNS #2' 5 1 \"${IP4_2}\" 5 16 16 16 0" +elif [ ${IPV6_AVAIL} -eq 1 ]; then + RESOLV=" + 'Search' 1 1 \"${SEARCH}\" 1 16 50 50 0 + 'Nameserver' 2 1 \"Nameserver\" 2 1 11 11 2 + 'IPv6 DNS #1' 2 1 \"${IP6_1}\" 2 16 50 50 0 + 'IPv6 DNS #2' 3 1 \"${IP6_2}\" 3 16 50 50 0" +elif [ ${IPV4_AVAIL} -eq 1 ]; then + RESOLV=" + 'Search' 1 1 \"${SEARCH}\" 1 16 50 50 0 + 'Nameserver' 2 1 \"Nameserver\" 2 1 11 11 2 + 'IPv4 DNS #1' 2 1 \"${IP4_1}\" 2 16 16 16 0 + 'IPv4 DNS #2' 3 1 \"${IP4_2}\" 3 16 16 16 0" +else + if [ -n "$AUTO_FAIL" ]; then + bsddialog --backtitle "$OSNAME Installer" \ + --msgbox "Failed to automatically configure interface (tried $AUTO_FAIL)." 0 0 + exec $0 + fi + exit 0 +fi + +# Auto only guaranteed to have IPv4 and/or IPv6 address; may not have +# nameserver available +if [ -n "$AUTO" ] && [ -n "${IP4_1}" -o -n "${IP6_1}" ]; then + # Convert from bsddialog arguments to default output + RESOLV=$(echo "${RESOLV}" | xargs -n9 sh -c 'echo "$4"' '') +else + exec 5>&1 + RESOLV=$(echo "${RESOLV}" | xargs -o bsddialog --backtitle "$OSNAME Installer" \ + --title 'Network Configuration' \ + --mixedform 'Resolver Configuration' 0 0 0 \ + 2>&1 1>&5) + if [ $? -eq $BSDDIALOG_CANCEL ]; then exec $0; fi + exec 5>&- +fi + +echo ${RESOLV} | tr ' ' '\n' | \ +awk ' +BEGIN { + search=-1; +} +{ + if (/^[[:space:]]+$/) { + next; + } + if (/^Nameserver$/) { + printf "\n"; + search=0; + next; + } + if (search == -1) { + printf "search "; + search=1; + } + if (search > 0) { + printf "%s%s", (search > 1) ? " " : "", $1; + search++; + next; + } + printf "nameserver %s\n", $1; +}' > ${BSDINSTALL_TMPETC}/resolv.conf + +mv $BSDINSTALL_TMPETC/._rc.conf.net $BSDINSTALL_TMPETC/rc.conf.net diff --git a/usr.sbin/bsdinstall/scripts/netconfig_ipv4 b/usr.sbin/bsdinstall/scripts/netconfig_ipv4 new file mode 100755 index 000000000000..7e3669f697d9 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/netconfig_ipv4 @@ -0,0 +1,130 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2013-2015 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr + +############################################################ MAIN + +: ${BSDDIALOG_OK=0} +: ${BSDDIALOG_CANCEL=1} + +INTERFACE=$1 +IFCONFIG_PREFIX="$2" +AUTO="${3:-}" +test -z "$IFCONFIG_PREFIX" || IFCONFIG_PREFIX="$2 " +case "${INTERFACE}" in +"") bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ + --msgbox 'No interface specified for IPv4 configuration.' 0 0 + exit 1 + ;; +esac +case "$AUTO" in +""|auto) + ;; +*) + bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ + --msgbox "Bad auto option '$AUTO'." 0 0 + exit 1 + ;; +esac + +if [ -n "$AUTO" ]; then + DHCP=1 +else + bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' --yesno 'Would you like to use DHCP to configure this interface?' 0 0 + if [ $? -eq $BSDDIALOG_OK ]; then + DHCP=1 + else + DHCP=0 + fi +fi +if [ $DHCP -eq 1 ]; then + if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then + # XXX: get interface down otherwise after installation restart + # dhclient does not build a new resolv.conf (see PR262262). + ifconfig $INTERFACE down + ifconfig $INTERFACE up + bsddialog --backtitle "$OSNAME Installer" --infobox "Acquiring DHCP lease..." 0 0 + err=$( pkill -F /var/run/dhclient/dhclient.${INTERFACE}.pid; dhclient $INTERFACE 2>&1 ) + if [ $? -ne 0 ]; then + f_dprintf "%s" "$err" + if [ -n "$AUTO" ]; then + exit 1 + fi + bsddialog --backtitle "$OSNAME Installer" --msgbox "DHCP lease acquisition failed." 0 0 + exec $0 ${INTERFACE} "${IFCONFIG_PREFIX}" + fi + fi + sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net ifconfig_$INTERFACE="${IFCONFIG_PREFIX}DHCP" + exit 0 +fi + +IP_ADDRESS=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $2); }'` +NETMASK=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $4); }'` +ROUTER=`netstat -rn -f inet | awk '/default/ {printf("%s\n", $2);}'` + +exec 5>&1 +IF_CONFIG=$(bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' --form 'Static Network Interface Configuration' 0 0 0 \ + 'IP Address' 1 1 "$IP_ADDRESS" 1 20 16 0 \ + 'Subnet Mask' 2 1 "$NETMASK" 2 20 16 0 \ + 'Default Router' 3 1 "$ROUTER" 3 20 16 0 \ +2>&1 1>&5) +if [ $? -eq $BSDDIALOG_CANCEL ]; then exit 1; fi +exec 5>&- + +echo $INTERFACE $IF_CONFIG | + awk -v prefix="$IFCONFIG_PREFIX" '{ + printf("ifconfig_%s=\"%s\inet %s netmask %s\"\n", $1, prefix, $2, $3); + printf("defaultrouter=\"%s\"\n", $4); + }' >> $BSDINSTALL_TMPETC/._rc.conf.net +retval=$? + +if [ "$BSDINSTALL_CONFIGCURRENT" ]; then + . $BSDINSTALL_TMPETC/._rc.conf.net + if [ -n "$2" ]; then + ifconfig $INTERFACE `eval echo \\\$ifconfig_$INTERFACE | sed "s|$2||"` + else + ifconfig $INTERFACE `eval echo \\\$ifconfig_$INTERFACE` + fi + if [ "$defaultrouter" ]; then + route delete -inet default + route add -inet default $defaultrouter + retval=$? + fi +fi + +exit $retval + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdinstall/scripts/netconfig_ipv6 b/usr.sbin/bsdinstall/scripts/netconfig_ipv6 new file mode 100755 index 000000000000..d60a3014ccc4 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/netconfig_ipv6 @@ -0,0 +1,184 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2011 The FreeBSD Foundation +# Copyright (c) 2013-2015 Devin Teske +# All rights reserved. +# +# Portions of this software were developed by Bjoern Zeeb +# under sponsorship from the FreeBSD Foundation. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr + +############################################################ MAIN + +: ${BSDDIALOG_OK=0} +: ${BSDDIALOG_CANCEL=1} + +# +# TODO: +# - Add DHCPv6 support once FreeBSD ships with it. +# + +INTERFACE=$1 +AUTO="${2:-}" +case "${INTERFACE}" in +"") bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ + --msgbox 'No interface specified for IPv6 configuration.' 0 0 + exit 1 + ;; +esac +case "$AUTO" in +""|auto) + ;; +*) + bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ + --msgbox "Bad auto option '$AUTO'." 0 0 + exit 1 + ;; +esac + +AGAIN="" +while : ; do + if [ -n "$AUTO" ]; then + SLAAC=1 + else + MSG="Would you like to try stateless address autoconfiguration (SLAAC)${AGAIN}?" + bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ + --yesno "${MSG}" 0 0 + if [ $? -eq $BSDDIALOG_OK ]; then + SLAAC=1 + else + SLAAC=0 + fi + fi + if [ $SLAAC -eq 1 ]; then + if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then + bsddialog --backtitle "$OSNAME Installer" \ + --infobox "Sending Router Solicitation ..." 0 0 + ifconfig ${INTERFACE} inet6 -ifdisabled accept_rtadv up + err=$( rtsol -F $INTERFACE 2>&1 ) + if [ $? -ne 0 ]; then + f_dprintf "%s" "$err" + if [ -n "$AUTO" ]; then + exit 1 + fi + bsddialog --backtitle "$OSNAME Installer" --msgbox "SLAAC failed." 0 0 + AGAIN=" again" + continue + fi + fi + sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net ifconfig_${INTERFACE}_ipv6="inet6 accept_rtadv" + exit 0 + else + break + fi +done + +ROUTER6=`netstat -Wrn -f inet6 | awk '/default/ {printf("%s\n", $2);}'` +ADDRS=`ifconfig ${INTERFACE} inet6 | \ +awk -v dfr="${ROUTER6}" ' +BEGIN { + n=0; +} +{ + if (/inet6/) { + if (match($2, "^fe80:")) { next; }; + # For the moment ignore all but the first address; it might confuse the user. + if (n > 0) { next; }; + n++; + printf "\"IPv6 Address\" %d 1 \"%s/%s\" %d 16 50 50 0 ", n, $2, $4, n; + } +} +END { + if (n == 0) { + n++; + printf "\"IPv6 Address\" %d 1 \"\" %d 16 50 50 0 ", n, n; + } + n++; + # Nasty trick adding a (hidden, same y) read-only field as a marker + # to separate interface address(es) from the default router. + printf "\"Default Router\" %d 1 \"%s\" %d 1 14 14 2 ", n, "DefaultRouter", n; + printf "\"Default Router\" %d 1 \"%s\" %d 16 50 50 0 ", n, dfr, n; +}'` + +exec 5>&1 +IF_CONFIG=$(echo ${ADDRS} | xargs -o bsddialog --backtitle "$OSNAME Installer" \ + --title 'Network Configuration' \ + --mixedform 'Static IPv6 Network Interface Configuration' 0 0 0 \ +2>&1 1>&5) +if [ $? -eq $BSDDIALOG_CANCEL ]; then exit 1; fi +exec 5>&- + +echo ${IF_CONFIG} | tr ' ' '\n' | \ +awk -v iface="${INTERFACE}" ' +BEGIN { + dfr=0; + count=0; +} +{ + if (/^[[:space:]]+$/) { + next; + } + if (/DefaultRouter/) { + dfr=1; + next; + } + if (dfr == 1) { + printf("ipv6_defaultrouter=\"%s\"\n", $1); + next; + } + if (count > 0) { + # Ignore all but the first IP address for now. + next; + } + count++; + if (!match($1, "/")) { + sub("$", "/64", $1); + } + printf("ifconfig_%s_ipv6=\"inet6 %s\"\n", iface, $1); +}' >> $BSDINSTALL_TMPETC/._rc.conf.net +retval=$? + +if [ "$BSDINSTALL_CONFIGCURRENT" ]; then + . $BSDINSTALL_TMPETC/._rc.conf.net + ifconfig ${INTERFACE} `eval echo \\\$ifconfig_${INTERFACE}_ipv6` + if [ "$ipv6_defaultrouter" ]; then + route delete -inet6 default + route add -inet6 default ${ipv6_defaultrouter} + retval=$? + fi +fi + +exit $retval + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdinstall/scripts/pkgbase.in b/usr.sbin/bsdinstall/scripts/pkgbase.in new file mode 100755 index 000000000000..5299d34fcb71 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/pkgbase.in @@ -0,0 +1,368 @@ +#!/usr/libexec/flua + +-- SPDX-License-Identifier: BSD-2-Clause +-- +-- Copyright(c) 2025 The FreeBSD Foundation. +-- +-- This software was developed by Isaac Freund <ifreund@freebsdfoundation.org> +-- under sponsorship from the FreeBSD Foundation. + +local sys_wait = require("posix.sys.wait") +local unistd = require("posix.unistd") + +local all_libcompats <const> = "%%_ALL_libcompats%%" + +-- Run a command using the OS shell and capture the stdout +-- Strips exactly one trailing newline if present, does not strip any other whitespace. +-- Asserts that the command exits cleanly +local function capture(command) + local p = io.popen(command) + local output = p:read("*a") + assert(p:close()) + -- Strip exactly one trailing newline from the output, if there is one + return output:match("(.-)\n$") or output +end + +local function append_list(list, other) + for _, item in ipairs(other) do + table.insert(list, item) + end +end + +-- Read from the given fd until EOF +-- Returns all the data read as a single string +local function read_all(fd) + local ret = "" + repeat + local buffer = assert(unistd.read(fd, 1024)) + ret = ret .. buffer + until buffer == "" + return ret +end + +-- Run bsddialog with the given argument list +-- Returns the exit code and stderr output of bsddialog +local function bsddialog(args) + local r, w = assert(unistd.pipe()) + + local pid = assert(unistd.fork()) + if pid == 0 then + assert(unistd.close(r)) + assert(unistd.dup2(w, 2)) + assert(unistd.execp("bsddialog", args)) + unistd._exit() + end + assert(unistd.close(w)) + + local output = read_all(r) + assert(unistd.close(r)) + + local _, _, exit_code = assert(sys_wait.wait(pid)) + return exit_code, output +end + +-- Prompts the user for a yes/no answer to the given question using bsddialog +-- Returns true if the user answers yes and false if the user answers no. +local function prompt_yn(question) + local exit_code = bsddialog({ + "--yesno", + "--disable-esc", + question, + 0, 0, -- autosize + }) + return exit_code == 0 +end + +-- Creates a dialog for component selection mirroring the +-- traditional tarball component selection dialog. +local function select_components(components, options) + local descriptions = { + ["kernel-dbg"] = "Debug symbols for the kernel", + ["devel"] = "C/C++ compilers and related utilities", + ["optional"] = "Optional software (excluding compilers)", + ["optional-jail"] = "Optional software (excluding compilers)", + ["base"] = "The complete base system (includes devel and optional)", + ["base-jail"] = "The complete base system (includes devel and optional)", + ["src"] = "System source tree", + ["tests"] = "Test suite", + ["lib32"] = "32-bit compatibility libraries", + ["debug"] = "Debug symbols for the selected components", + } + + -- These defaults match what the non-pkgbase installer selects + -- by default. + local defaults = { + ["base"] = "on", + ["base-jail"] = "on", + ["kernel-dbg"] = "on", + } + -- Enable compat sets by default. + for compat in all_libcompats:gmatch("%S+") do + defaults["lib" .. compat] = "on" + end + + -- Sorting the components is necessary to ensure that the ordering is + -- consistent in the UI. + local sorted_components = {} + + -- Determine which components we want to offer the user. + local show_component = function (component) + -- "pkg" is always installed if present. + if component == "pkg" then return false end + + -- Don't include individual "-dbg" components, because those + -- are handled via the "debug" component, except for kernel-dbg + -- which is always shown for non-jail installations. + if component == "kernel-dbg" then + return (not options.jail) + end + if component:match("%-dbg$") then return false end + + -- Some sets have "-jail" variants which are jail-specific + -- variants of the base set. + + if options.jail and components[component.."-jail"] then + -- If we're installing in a jail, and this component + -- has a jail variant, hide it. + return false + end + + if not options.jail and component:match("%-jail$") then + -- Otherwise if we're not installing in a jail, and + -- this is a jail variant, hide it. + return false + end + + -- "minimal(-jail)" is always installed if present. + if component == "minimal" or component == "minimal-jail" then + return false + end + + -- "kernel" (the generic kernel) and "kernels" (the set) are + -- never offered; we always install the kernel for a non-jail + -- installation. + if component == "kernel" or component == "kernels" then + return false + end + + -- If we didn't find a reason to hide this component, show it. + return true + end + + for component, _ in pairs(components) do + if show_component(component) then + table.insert(sorted_components, component) + end + end + + table.sort(sorted_components) + + local checklist_items = {} + for _, component in ipairs(sorted_components) do + local description = descriptions[component] or "" + local default = defaults[component] or "off" + table.insert(checklist_items, component) + table.insert(checklist_items, description) + table.insert(checklist_items, default) + end + + local bsddialog_args = { + "--backtitle", "FreeBSD Installer", + "--title", "Select System Components", + "--nocancel", + "--disable-esc", + "--separate-output", + "--checklist", + "A minimal set of packages suitable for a multi-user system ".. + "is always installed. Select additional packages you wish ".. + "to install:", + "0", "0", "0", -- autosize + } + append_list(bsddialog_args, checklist_items) + + local exit_code, output = bsddialog(bsddialog_args) + -- This should only be possible if bsddialog is killed by a signal + -- or buggy, we disable the cancel option and esc key. + -- If this does happen, there's not much we can do except exit with a + -- hopefully useful stack trace. + assert(exit_code == 0) + + -- Always install the minimal set, since it's required for the system + -- to work. The base set depends on minimal, but it's fine to install + -- both, and this way the user can remove the base set without pkg + -- autoremove then trying to remove minimal. + local selected = {} + if options.jail then + table.insert(selected, "minimal-jail") + else + table.insert(selected, "minimal") + end + + -- If pkg is available, always install it so the user can manage the + -- installed system. This is optional, because a repository built + -- from src alone won't have a pkg package. + if components["pkg"] then + table.insert(selected, "pkg") + end + + if not options.jail then + table.insert(selected, "kernel") + end + + for component in output:gmatch("[^\n]+") do + table.insert(selected, component) + end + + return selected +end + +-- Returns a list of pkgbase packages selected by the user +local function select_packages(pkg, options) + -- These are the components which aren't generated automatically from + -- package sets. + local components = { + ["kernel"] = {}, + ["kernel-dbg"] = {}, + ["debug"] = {}, + } + + -- Note: if you update this list, you must also update the list in + -- release/scripts/pkgbase-stage.lua. + local kernel_packages = { + -- Most architectures use this + ["FreeBSD-kernel-generic"] = true, + -- PowerPC uses either of these, depending on platform + ["FreeBSD-kernel-generic64"] = true, + ["FreeBSD-kernel-generic64le"] = true, + } + + local rquery = capture(pkg .. "rquery -U -r FreeBSD-base %n") + for package in rquery:gmatch("[^\n]+") do + local setname = package:match("^FreeBSD%-set%-(.+)$") + + if setname then + components[setname] = components[setname] or {} + table.insert(components[setname], package) + elseif kernel_packages[package] then + table.insert(components["kernel"], package) + elseif kernel_packages[package:match("(.*)%-dbg$")] then + table.insert(components["kernel-dbg"], package) + elseif package == "pkg" then + components["pkg"] = components["pkg"] or {} + table.insert(components["pkg"], package) + end + end + + -- Assert that both a kernel and the "minimal" set are available, since + -- those are both required to install a functional system. Don't worry + -- if other sets are missing (e.g. base or src), which might happen + -- when using custom install media. + assert(#components["kernel"] == 1) + assert(#components["minimal"] == 1) + + -- Prompt the user for what to install. + local selected = select_components(components, options) + + -- Determine if the "debug" component was selected. + local debug = false + for _, component in ipairs(selected) do + if component == "debug" then + debug = true + break + end + end + + local packages = {} + for _, component in ipairs(selected) do + local pkglist = components[component] + append_list(packages, pkglist) + + -- If the debug component was selected, install the -dbg + -- package for each set. We have to check if the dbg set + -- actually exists, because some sets (src, tests) don't + -- have a -dbg subpackage. + for _, c in ipairs(pkglist) do + local setname = c:match("^FreeBSD%-set%-(.*)$") + if debug and setname then + local dbgset = setname.."-dbg" + if components[dbgset] then + append_list(packages, components[dbgset]) + end + end + end + end + + return packages +end + +local function parse_options() + local options = {} + for _, a in ipairs(arg) do + if a == "--jail" then + options.jail = true + else + io.stderr:write("Error: unknown option " .. a .. "\n") + os.exit(1) + end + end + return options +end + +-- Fetch and install pkgbase packages to BSDINSTALL_CHROOT. +-- Respect BSDINSTALL_PKG_REPOS_DIR if set, otherwise use pkg.freebsd.org. +local function pkgbase() + local options = parse_options() + + -- TODO Support fully offline pkgbase installation by taking a new enough + -- version of pkg.pkg as input. + if not os.execute("pkg -N > /dev/null 2>&1") then + print("Bootstrapping pkg on the host system") + assert(os.execute("pkg bootstrap -y")) + end + + local chroot = assert(os.getenv("BSDINSTALL_CHROOT")) + assert(os.execute("mkdir -p " .. chroot)) + + -- Always install the default FreeBSD-base.conf file to the chroot, even + -- if we don't actually fetch the packages from the repository specified + -- there (e.g. because we are performing an offline installation). + local chroot_repos_dir = chroot .. "/usr/local/etc/pkg/repos/" + assert(os.execute("mkdir -p " .. chroot_repos_dir)) + assert(os.execute("cp /usr/share/bsdinstall/FreeBSD-base.conf " .. + chroot_repos_dir)) + + local repos_dir = os.getenv("BSDINSTALL_PKG_REPOS_DIR") + if not repos_dir then + repos_dir = chroot_repos_dir + -- Since pkg always interprets fingerprints paths as relative to + -- the --rootdir we must copy the key from the host. + assert(os.execute("mkdir -p " .. chroot .. "/usr/share/keys")) + assert(os.execute("cp -R /usr/share/keys/pkg " .. chroot .. "/usr/share/keys/")) + end + + -- We must use --repo-conf-dir rather than -o REPOS_DIR here as the latter + -- is interpreted relative to the --rootdir. BSDINSTALL_PKG_REPOS_DIR must + -- be allowed to point to a path outside the chroot. + local pkg = "pkg --rootdir " .. chroot .. + " --repo-conf-dir " .. repos_dir .. " -o IGNORE_OSVERSION=yes " + + while not os.execute(pkg .. "update") do + if not prompt_yn("Updating repositories failed, try again?") then + os.exit(1) + end + end + + local packages = table.concat(select_packages(pkg, options), " ") + + while not os.execute(pkg .. "install -U -F -y -r FreeBSD-base " .. packages) do + if not prompt_yn("Fetching packages failed, try again?") then + os.exit(1) + end + end + + if not os.execute(pkg .. "install -U -y -r FreeBSD-base " .. packages) then + os.exit(1) + end +end + +pkgbase() diff --git a/usr.sbin/bsdinstall/scripts/rootpass b/usr.sbin/bsdinstall/scripts/rootpass new file mode 100755 index 000000000000..9d25569ae946 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/rootpass @@ -0,0 +1,116 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2024 The FreeBSD Foundation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +if [ -n "$ROOTPASS_ENC" ]; then + printf '%s\n' "$ROOTPASS_ENC" | pw -R $BSDINSTALL_CHROOT usermod root -H 0 + exit $? +elif [ -n "$ROOTPASS_PLAIN" ]; then + printf '%s\n' "$ROOTPASS_PLAIN" | pw -R $BSDINSTALL_CHROOT usermod root -h 0 + exit $? +fi + +: ${BSDDIALOG_OK:=0} + +error_get_message() +{ + case $1 in + 62) + echo "The password cannot be empty" + ;; + 63) + echo "The passwords do not match" + ;; + 64) #EX_USAGE + echo "Command used incorrectly" + ;; + 65) #EX_DATAERR + echo "Incorrect input data" + ;; + 67) #EX_NOUSER + echo "User not found" + ;; + 70) #EX_SOFTWARE + echo "Internal software error" + ;; + 71) #EX_OSERR + echo "Operating System error detected" + ;; + 72) #EX_OSFILE + echo "Error in a system file" + ;; + 74) #EX_IOERR + echo "I/O error" + ;; + 77) #EX_NOPERM + echo "Insufficient permissions" + ;; + 78) #EX_CONFIG + echo "Configuration error" + ;; + 0) + ;; + *) + echo "An unknown error occurred (code $1)" + return 1 + ;; + esac + return $1 +} + +errormsg= +username="root" +while true; do + exec 5>&1 + output=$(bsddialog --backtitle "$OSNAME Installer" \ + --title "Set $username password" \ + --cancel-label "Skip" \ + --passwordform --insecure \ + "Please select a password for the system management account ($username) +$errormsg" \ + 0 0 2 \ + "Password" 0 0 '' 0 17 32 32 \ + "Repeat password" 1 0 '' 1 17 32 32 \ + 2>&1 1>&5) + res=$? + exec 5>&- + [ $res -eq $BSDDIALOG_OK ] || exit 0 + + echo -n "$output" | (read password1 + read password2 + [ -n "$password1" -o -n "$password2" ] || exit 62 + [ "$password1" = "$password2" ] || exit 63 + echo "$password1" | chroot $BSDINSTALL_CHROOT \ + /usr/sbin/pw usermod "$username" -h 0 + ) + err=$? + [ $err -eq 0 ] && exit 0 + errormsg=$(error_get_message $err) +done diff --git a/usr.sbin/bsdinstall/scripts/script b/usr.sbin/bsdinstall/scripts/script new file mode 100755 index 000000000000..21da2ea7c366 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/script @@ -0,0 +1,187 @@ +#!/bin/sh +#- +# Copyright (c) 2013 Nathan Whitehorn +# Copyright (c) 2013-2015 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/variable.subr + +############################################################ CONFIGURATION + +# VARIABLES: +# PARTITIONS +# DISTRIBUTIONS +# BSDINSTALL_DISTDIR + +# +# Default name of the ZFS boot-pool +# +: ${ZFSBOOT_POOL_NAME:=zroot} + +############################################################ GLOBALS + +: ${TMPDIR:="/tmp"} + +# +# Strings that should be moved to an i18n file and loaded with f_include_lang() +# +msg_installation_error="Installation Error!" + +############################################################ FUNCTIONS + +error() +{ + local file + f_getvar "$VAR_DEBUG_FILE#+" file + if [ "$file" ]; then + f_dialog_title "$msg_installation_error" + f_dialog_textbox "$file" + # No need to restore title, pining for the fjords + fi + + [ -f "$PATH_FSTAB" ] || exit + if [ "$ZFSBOOT_DISKS" ]; then + zpool export $ZFSBOOT_POOL_NAME + else + bsdinstall umount + fi + + exit 1 +} + +############################################################ MAIN + +set -e +trap error EXIT + +SCRIPT="$1" +shift + +f_dprintf "Began Installation at %s" "$( date )" +rm -rf $BSDINSTALL_TMPETC +mkdir $BSDINSTALL_TMPETC +rm -f $TMPDIR/bsdinstall-installscript-setup + +# split script into preamble and setup script at first shebang +awk 'BEGIN {pathb=ARGV[2]; ARGV[2]=""} /^#!/{b=1} { + if (b) print >pathb; else print}' \ + "$SCRIPT" $TMPDIR/bsdinstall-installscript-setup \ + >$TMPDIR/bsdinstall-installscript-preamble + +. $TMPDIR/bsdinstall-installscript-preamble +: ${DISTRIBUTIONS="kernel.txz base.txz"}; export DISTRIBUTIONS +export BSDINSTALL_DISTDIR + +# Re-initialize a new log if preamble changed BSDINSTALL_LOG +if [ "$BSDINSTALL_LOG" != "${debugFile#+}" ]; then + export debugFile="$BSDINSTALL_LOG" + f_quietly f_debug_init + # NB: Being scripted, let debug go to terminal for invalid debugFile + f_dprintf "Began Installation at %s" "$( date )" +fi + +# Make partitions +rm -f $PATH_FSTAB +touch $PATH_FSTAB +if [ "$ZFSBOOT_DISKS" ]; then + bsdinstall zfsboot +else + bsdinstall scriptedpart "$PARTITIONS" +fi +bsdinstall mount + +# Fetch missing distribution files, if any +exec 5>&1 +export BSDINSTALL_DISTDIR=$(`dirname $0`/fetchmissingdists 2>&1 1>&5) +FETCH_RESULT=$? +exec 5>&- + +[ $FETCH_RESULT -ne 0 ] && error "Could not fetch remote distributions" + +# Unpack distributions +bsdinstall checksum +if [ -t 0 ]; then + # If install is a tty, use distextract as normal + bsdinstall distextract +else + # Otherwise, we need to use tar (see https://reviews.freebsd.org/D10736) + for set in $DISTRIBUTIONS; do + f_dprintf "Extracting $BSDINSTALL_DISTDIR/$set" + # XXX: The below fails if any mountpoints are FAT, due to + # inability to set ctime/mtime on the root of FAT partitions, + # which is needed to support e.g. EFI system partitions. tar has + # no option to ignore this (distextract ignores them internally + # through a hack), and returns 1 on any warning or error, + # effectively turning all warnings into fatal errors. + # + # Work around this in an extremely lame way for the specific + # case of EFI system partitions only. This *ONLY WORKS* if + # /boot/efi is empty and does not handle analogous problems on + # other systems (ARM, PPC64). + tar -xf "$BSDINSTALL_DISTDIR/$set" -C $BSDINSTALL_CHROOT --exclude boot/efi + mkdir -p $BSDINSTALL_CHROOT/boot/efi + done +fi + +# Configure bootloader if needed +bsdinstall bootconfig + +# Finalize install +bsdinstall config + +# Make sure networking is functional, if we can arrange that +if [ ! -f $BSDINSTALL_CHROOT/etc/resolv.conf -a -f /etc/resolv.conf ]; then + cp /etc/resolv.conf $BSDINSTALL_CHROOT/etc/resolv.conf +fi + +# Run post-install script +if [ -f $TMPDIR/bsdinstall-installscript-setup ]; then + cp $TMPDIR/bsdinstall-installscript-setup \ + $BSDINSTALL_CHROOT/tmp/installscript + chmod a+x $BSDINSTALL_CHROOT/tmp/installscript + chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1 + rm $BSDINSTALL_CHROOT/tmp/installscript +fi + +bsdinstall entropy +bsdinstall umount +if [ "$ZFSBOOT_DISKS" ]; then + zpool export $ZFSBOOT_POOL_NAME +fi + +f_dprintf "Installation Completed at %s" "$( date )" + +trap - EXIT +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdinstall/scripts/services b/usr.sbin/bsdinstall/scripts/services new file mode 100755 index 000000000000..110b6f321ed1 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/services @@ -0,0 +1,112 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +: ${BSDDIALOG_OK=0} + +if [ -f $BSDINSTALL_TMPETC/rc.conf.services ]; then + eval "$( sed -E -e 's/\<(YES|AUTO)\>/on/i' -e 's/\<NO\>/off/i' \ + $BSDINSTALL_TMPETC/rc.conf.services )" +else + # Default service states. Everything is off if not enabled. + sshd_enable="on" +fi + +echo -n > $BSDINSTALL_TMPETC/rc.conf.services + +DAEMON_OPTIONS="" + +if [ -x "${BSDINSTALL_CHROOT}/etc/rc.d/sshd" ]; then + DAEMON_OPTIONS="$DAEMON_OPTIONS \ + sshd \"Secure shell daemon\" ${sshd_enable:-off}" +fi + +if [ -x "${BSDINSTALL_CHROOT}/etc/rc.d/ntpd" ]; then + DAEMON_OPTIONS="$DAEMON_OPTIONS \ + ntpd \"Synchronize system and network time\" ${ntpd_enable:-off} \ + ntpd_sync_on_start \"Sync time on ntpd startup, even if offset is high\" \ + ${ntpd_sync_on_start:-off}" +fi + +if [ -x "${BSDINSTALL_CHROOT}/etc/rc.d/local_unbound" ]; then + DAEMON_OPTIONS="$DAEMON_OPTIONS \ + local_unbound \"Local caching validating resolver\" \ + ${local_unbound_enable:-off}" +fi + +if [ -x "${BSDINSTALL_CHROOT}/etc/rc.d/powerd" ]; then + DAEMON_OPTIONS="$DAEMON_OPTIONS \ + powerd \"Adjust CPU frequency dynamically if supported\" \ + ${powerd_enable:-off}" +fi + +if [ -x "${BSDINSTALL_CHROOT}/etc/rc.d/moused" ]; then + DAEMON_OPTIONS="$DAEMON_OPTIONS \ + moused \"PS/2 mouse pointer on console\" ${moused_enable:-off}" +fi + +exec 5>&1 +DAEMONS=$(eval bsddialog --backtitle \"$OSNAME Installer\" \ + --title \"System Configuration\" --no-cancel --separate-output \ + --checklist \"Choose the services you would like to be started at boot:\" \ + 0 0 0 \ + $DAEMON_OPTIONS \ + dumpdev \"Enable kernel crash dumps to /var/crash\" ${dumpdev:-on} \ +2>&1 1>&5 ) +retval=$? +exec 5>&- + +if [ $retval -ne $BSDDIALOG_OK ]; then + exit 1 +fi + +havedump= +havemouse= +for daemon in $DAEMONS; do + [ "$daemon" = "dumpdev" ] && havedump=1 continue + [ "$daemon" = "moused" ] && havemouse=1 + if [ "$daemon" = "ntpd_sync_on_start" ]; then + rcvar=${daemon} + else + rcvar=${daemon}_enable + fi + echo ${rcvar}=\"YES\" >> $BSDINSTALL_TMPETC/rc.conf.services +done + +if [ ! "$havemouse" ]; then + echo moused_nondefault_enable=\"NO\" >> $BSDINSTALL_TMPETC/rc.conf.services +fi + +echo '# Set dumpdev to "AUTO" to enable crash dumps, "NO"' \ + 'to disable' >> $BSDINSTALL_TMPETC/rc.conf.services +if [ "$havedump" ]; then + echo dumpdev=\"AUTO\" >> $BSDINSTALL_TMPETC/rc.conf.services +else + echo dumpdev=\"NO\" >> $BSDINSTALL_TMPETC/rc.conf.services +fi diff --git a/usr.sbin/bsdinstall/scripts/time b/usr.sbin/bsdinstall/scripts/time new file mode 100755 index 000000000000..7197ae4e7f47 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/time @@ -0,0 +1,69 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +# Select timezone +chroot $BSDINSTALL_CHROOT tzsetup -s + +# Switch to target timezone +saved_TZ="$TZ" +TZ="${BSDINSTALL_CHROOT}/etc/localtime" +export TZ + +# Set date +exec 5>&1 +DATE=$(bsddialog --backtitle "$OSNAME Installer" \ + --title 'Time & Date' \ + --ok-label 'Set Date' \ + --cancel-label 'Skip' \ + --default-no \ + --date-format '%Y%m%d%H%M.%S' \ + --calendar '' 0 40 \ +2>&1 1>&5) && date $DATE +exec 5>&- + +# Set time +exec 5>&1 +TIME=$(bsddialog --backtitle "$OSNAME Installer" \ + --title 'Time & Date' \ + --ok-label 'Set Time' \ + --cancel-label 'Skip' \ + --default-no \ + --time-format '%H%M.%S' \ + --timebox '' 0 40 \ +2>&1 1>&5) && date $TIME +exec 5>&- + +# Switch back +if [ -n "$saved_TZ" ]; then + TZ="$saved_TZ" +else + unset TZ +fi +unset saved_TZ diff --git a/usr.sbin/bsdinstall/scripts/umount b/usr.sbin/bsdinstall/scripts/umount new file mode 100755 index 000000000000..345cd1938b0d --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/umount @@ -0,0 +1,50 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +# If we mounted the DVD packages, unmount them +if [ -d $BSDINSTALL_CHROOT/dist/packages ]; then + umount $BSDINSTALL_CHROOT/dist/packages + rmdir $BSDINSTALL_CHROOT/dist/packages + rmdir $BSDINSTALL_CHROOT/dist +fi + +TMP_FSTAB=${TMPDIR:-"/tmp"}/bsdinstall-tmp-fstab + +cat $PATH_FSTAB | awk -v BSDINSTALL_CHROOT=$BSDINSTALL_CHROOT '{ + if ($2 ~ "^/.*") { + fsname = $2; + if (fsname == "/") + fsname = "" + printf("%s\t%s%s\t%s\t%s\t%s\t%s\n", $1, BSDINSTALL_CHROOT, + fsname, $3, $4, $5, $6); + } +}' > $TMP_FSTAB + +umount $BSDINSTALL_CHROOT/dev 2>/dev/null +if [ -n "$TMP_FSTAB" ]; then + umount -F $TMP_FSTAB -a 2>/dev/null +fi diff --git a/usr.sbin/bsdinstall/scripts/wlanconfig b/usr.sbin/bsdinstall/scripts/wlanconfig new file mode 100755 index 000000000000..33d94a933f45 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/wlanconfig @@ -0,0 +1,370 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2013-2020 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_include $BSDCFG_SHARE/dialog.subr +f_dialog_backtitle "$OSNAME Installer" + +############################################################ FUNCTIONS + +country_set() +{ + local error_str iface_up ifconfig_args= + + # + # Setup what was selected + # NB: Do not change order of arguments (or regdomain will be ignored) + # + [ "$2" ] && ifconfig_args="$ifconfig_args country $2" + [ "$1" ] && ifconfig_args="$ifconfig_args regdomain $1" + [ "$ifconfig_args" ] || return $SUCCESS # Nothing to do + ifconfig_args="${ifconfig_args# }" + + # Regdomain/country cannot be applied while interface is running + iface_up=$( ifconfig -lu | grep -w "$WLAN_IFACE" ) + [ "$iface_up" ] && ifconfig "$WLAN_IFACE" down + f_eval_catch -dk error_str wlanconfig ifconfig "ifconfig %s %s" \ + "$WLAN_IFACE" "$ifconfig_args" + error_str="${error_str#ifconfig: }" + # Restart wpa_supplicant(8) (should not fail). + [ "$iface_up" ] && ifconfig "$WLAN_IFACE" up && \ + f_eval_catch -d wlanconfig wpa_supplicant \ + 'wpa_supplicant -B -i "%s" -c "%s/wpa_supplicant.conf"' \ + "$WLAN_IFACE" "$BSDINSTALL_TMPETC" + if [ "$error_str" ]; then + $DIALOG --title "$msg_error" \ + --backtitle "$DIALOG_BACKTITLE" \ + --yes-label Change \ + --no-label Ignore \ + --yesno \ + "Error while applying chosen settings ($error_str)" \ + 0 0 || return $SUCCESS # Skip + return $FAILURE # Restart + else + cat > "$BSDINSTALL_TMPETC/rc.conf.net.wlan" <<-EOF + create_args_$WLAN_IFACE="$ifconfig_args" + EOF + fi + + return $SUCCESS +} + +dialog_country_select() +{ + local input regdomains countries regdomain country prompt + local no_default="<not selected>" + local default_regdomain="${1:-$no_default}" + local default_country="${2:-$no_default}" + + # + # Parse available countries/regdomains + # + input=$( ifconfig "$WLAN_IFACE" list countries | sed -e 's/DEBUG//gi' ) + regdomains=$( echo "$input" | awk ' + sub(/.*domains:/, ""), /[^[:alnum:][[:space:]]/ { + n = split($0, domains) + for (i = 1; i <= n; i++) + printf "'\''%s'\'' '\'\''\n", domains[i] + } + ' | sort ) + countries=$( echo "$input" | awk ' + sub(/Country codes:/, ""), sub(/Regulatory.*/, "") { + while (match($0, /[[:upper:]][[:upper:][:digit:]] /)) { + country = substr($0, RSTART) + sub(/ [[:upper:]][[:upper:][:digit:]].*/, "", + country) + code = substr(country, 1, 2) + desc = substr(country, 4) + sub(/[[:space:]]*$/, "", desc) + printf "'\''%s'\'' '\''%s'\''\n", code, desc + $0 = substr($0, RSTART + RLENGTH) + } + } + ' | sort ) + + f_dialog_title "Regdomain selection" + prompt="Select your regdomain." + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \"\" $regdomains + regdomain=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --cancel-label \"\$msg_skip\" \ + --default-item \"\$default_regdomain\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $regdomains \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + f_dialog_data_sanitize regdomain + + f_dialog_title "Country selection" + prompt="Select your country." + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \"\" $countries + country=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --cancel-label \"\$msg_skip\" \ + --default-item \"\$default_country\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $countries \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + f_dialog_data_sanitize country + + country_set "$regdomain" "$country" +} + +############################################################ MAIN + +: > "$BSDINSTALL_TMPETC/wpa_supplicant.conf" +chmod 0600 "$BSDINSTALL_TMPETC/wpa_supplicant.conf" + +cat >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<EOF +ctrl_interface=/var/run/wpa_supplicant +eapol_version=2 +ap_scan=1 +fast_reauth=1 + +EOF + +# +# Try to reach wpa_supplicant. If it isn't running and we can modify the +# existing system, start it. Otherwise, fail. +# +if ! f_eval_catch -d wlanconfig wpa_cli "wpa_cli ping"; then + if [ ! "$BSDINSTALL_CONFIGCURRENT" ]; then + f_show_err "Wireless cannot be configured without %s" \ + "making changes to the local system!" + exit 1 + fi + f_eval_catch wlanconfig wpa_supplicant \ + 'wpa_supplicant -B -i "%s" -c "%s/wpa_supplicant.conf"' \ + "$1" "$BSDINSTALL_TMPETC" || exit 1 + + # See if we succeeded + f_eval_catch wlanconfig wpa_cli "wpa_cli ping" || exit 1 +fi + +# +# There is no way to check country/regdomain without (possible) +# interface state modification +# +if [ "$BSDINSTALL_CONFIGCURRENT" ]; then + # Get current country/regdomain for selected interface + WLAN_IFACE=$( wpa_cli ifname | tail -n 1 ) + INPUT=$( ifconfig "$WLAN_IFACE" list regdomain | head -n 1 ) + DEF_REGDOMAIN=$( echo "$INPUT" | cut -w -f 2 ) + DEF_COUNTRY=$( echo "$INPUT" | cut -w -f 4 ) + [ "$DEF_REGDOMAIN" = 0 ] && DEF_REGDOMAIN="<not selected>" + [ "$DEF_COUNTRY" = 0 ] && DEF_COUNTRY="<not selected>" + f_dialog_title "Regdomain/country" + if f_yesno "Change regdomain/country ($DEF_REGDOMAIN/$DEF_COUNTRY)?" + then + while ! dialog_country_select "$DEF_REGDOMAIN" "$DEF_COUNTRY" + do :; done + fi +fi + +while :; do + SCANSSID=0 + # While wpa_supplicant may IFF_UP the interface, we do not want to rely + # in this. In case the script is run manually (outside the installer, + # e.g., for testing) wpa_supplicant may be running and the wlanN + # interface may be down (especially if dialog_country_select is not + # run successfully either) and scanning will not work. + f_eval_catch -d wlanconfig ifconfig "ifconfig $WLAN_IFACE up" + f_eval_catch -d wlanconfig wpa_cli "wpa_cli scan" + f_dialog_title "Scanning" + f_dialog_pause "Waiting 5 seconds to scan for wireless networks..." 5 || + exit 1 + + f_eval_catch -dk SCAN_RESULTS wlanconfig wpa_cli "wpa_cli scan_results" + NETWORKS=$( echo "$SCAN_RESULTS" | awk -F '\t' ' + /..:..:..:..:..:../ && $5 { printf "\"%s\"\t\"%s\"\n", $5, $4 } + ' | sort | uniq ) + + if [ ! "$NETWORKS" ]; then + f_dialog_title "$msg_error" + f_yesno "No wireless networks were found. Rescan?" && continue + else + f_dialog_title "Network Selection" + prompt="Select a wireless network to connect to." + f_dialog_menu_size height width rows "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" "$prompt" "" $NETWORKS + NETWORK=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --extra-button \ + --extra-label \"Rescan\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $NETWORKS \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + fi + retval=$? + f_dialog_data_sanitize NETWORK + case $retval in + $DIALOG_OK) break ;; + $DIALOG_CANCEL) + # Ask if the user wants to select network manually + f_dialog_title "Network Selection" + f_yesno "Do you want to select the network manually?" || exit 1 + f_dialog_input NETWORK "Enter SSID" || exit 1 + prompt="Select encryption type" + menu_list=" + '1 WPA/WPA2 PSK' '' + '2 WPA/WPA2 EAP' '' + '3 WEP' '' + '0 None' '' + " # END-QUOTE + eval f_dialog_menu_size height width rows \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \"\$prompt\" \"\" $menu_list + ENCRYPTION=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) || exit 1 + SCANSSID=1 + break + ;; + $DIALOG_EXTRA) # Rescan + ;; + esac +done + +[ "$ENCRYPTION" ] || ENCRYPTION=$( echo "$NETWORKS" | + awk -F '\t' "/^\"$NETWORK\"\t/ { print \$2 }" ) + +if echo "$ENCRYPTION" | grep -q PSK; then + PASS=$( $DIALOG \ + --title "WPA Setup" \ + --backtitle "$DIALOG_BACKTITLE" \ + --insecure \ + --mixedform "" \ + 0 0 0 \ + "SSID" 1 0 "$NETWORK" 1 12 0 0 2 \ + "Password" 2 0 "" 2 12 15 63 1 \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) || exec "$0" "$@" + awk 'sub(/^\\/,"")||1' \ + >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<-EOF + network={ + \ ssid="$NETWORK" + \ scan_ssid=$SCANSSID + \ psk="$PASS" + \ priority=5 + } + EOF +elif echo "$ENCRYPTION" | grep -q EAP; then + USERPASS=$( $DIALOG \ + --title "WPA-Enterprise Setup" \ + --backtitle "$DIALOG_BACKTITLE" \ + --insecure \ + --mixedform "" \ + 0 0 0 \ + "SSID" 1 0 "$NETWORK" 1 12 0 0 2 \ + "Username" 2 0 "" 2 12 25 63 0 \ + "Password" 3 0 "" 3 12 25 63 1 \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) || exec "$0" "$@" + awk 'sub(/^\\/,"")||1' \ + >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<-EOF + network={ + \ ssid="$NETWORK" + \ scan_ssid=$SCANSSID + \ key_mgmt=WPA-EAP$( + echo "$USERPASS" | awk ' + NR == 1 { printf "\n\tidentity=\"%s\"", $1 } + NR == 2 { printf "\n\tpassword=\"%s\"", $1 } + ' ) + \ priority=5 + } + EOF +elif echo "$ENCRYPTION" | grep -q WEP; then + WEPKEY=$( $DIALOG \ + --title "WEP Setup" \ + --backtitle "$DIALOG_BACKTITLE" \ + --insecure \ + --mixedform "" \ + 0 0 0 \ + "SSID" 1 0 "$NETWORK" 1 12 0 0 2 \ + "WEP Key 0" 2 0 "" 2 12 15 0 1 \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) || exec "$0" "$@" + awk 'sub(/^\\/,"")||1' \ + >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<-EOF + network={ + \ ssid="$NETWORK" + \ scan_ssid=$SCANSSID + \ key_mgmt=NONE + \ wep_key0="$WEPKEY" + \ wep_tx_keyidx=0 + \ priority=5 + } + EOF +else # Open + awk 'sub(/^\\/,"")||1' \ + >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<-EOF + network={ + \ ssid="$NETWORK" + \ scan_ssid=$SCANSSID + \ key_mgmt=NONE + \ priority=5 + } + EOF +fi + +# Connect to any open networks policy +cat >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<EOF +network={ + priority=0 + key_mgmt=NONE +} +EOF + +# Bring up new network +[ "$BSDINSTALL_CONFIGCURRENT" ] && + f_eval_catch -d wlanconfig wpa_cli "wpa_cli reconfigure" + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdinstall/scripts/zfsboot b/usr.sbin/bsdinstall/scripts/zfsboot new file mode 100755 index 000000000000..9ea6ec3a4ac9 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/zfsboot @@ -0,0 +1,1753 @@ +#!/bin/sh +#- +# Copyright (c) 2013-2016 Allan Jude +# Copyright (c) 2013-2018 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/device.subr +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/password/password.subr +f_include $BSDCFG_SHARE/variable.subr + +############################################################ CONFIGURATION + +# +# Default name of the boot-pool +# +: ${ZFSBOOT_POOL_NAME:=zroot} + +# +# Default pool size is optional +# +: ${ZFSBOOT_POOL_SIZE=} + +# +# Default options to use when creating zroot pool +# +: ${ZFSBOOT_POOL_CREATE_OPTIONS:=-O compression=on -O atime=off} + +# +# Default name for the boot environment parent dataset +# +: ${ZFSBOOT_BEROOT_NAME:=ROOT} + +# +# Default name for the primary boot environment +# +: ${ZFSBOOT_BOOTFS_NAME:=default} + +# +# Default Virtual Device (vdev) type to create +# +: ${ZFSBOOT_VDEV_TYPE:=stripe} + +# +# Should we use sysctl(8) vfs.zfs.vdev.min_auto_ashift=12 to force 4K sectors? +# +: ${ZFSBOOT_FORCE_4K_SECTORS=1} + +# +# Should we use geli(8) to encrypt the drives? +# NB: Automatically enables ZFSBOOT_BOOT_POOL +# +: ${ZFSBOOT_GELI_ENCRYPTION=} + +# +# Default path to the geli(8) keyfile used in drive encryption +# +: ${ZFSBOOT_GELI_KEY_FILE:=/boot/encryption.key} + +# +# Create a separate boot pool? +# NB: Automatically set when using geli(8) +# +: ${ZFSBOOT_BOOT_POOL=} + +# +# Options to use when creating separate boot pool (if any) +# +: ${ZFSBOOT_BOOT_POOL_CREATE_OPTIONS:=} + +# +# Default name for boot pool when enabled (e.g., geli(8)) +# +: ${ZFSBOOT_BOOT_POOL_NAME:=bootpool} + +# +# Default size for boot pool when enabled (e.g., geli(8)) +# +: ${ZFSBOOT_BOOT_POOL_SIZE:=2g} + +# +# Default disks to use (always empty unless being scripted) +# +: ${ZFSBOOT_DISKS:=} + +# +# Default partitioning scheme to use on disks +# +: ${ZFSBOOT_PARTITION_SCHEME:=} + +# +# Default boot type to use on disks +# +: ${ZFSBOOT_BOOT_TYPE:=} + +# +# How much swap to put on each block device in the boot pool +# NOTE: Value passed to gpart(8); which supports SI unit suffixes. +# +: ${ZFSBOOT_SWAP_SIZE:=2g} + +# +# Should we use geli(8) to encrypt the swap? +# +: ${ZFSBOOT_SWAP_ENCRYPTION=} + +# +# Should we use gmirror(8) to mirror the swap? +# +: ${ZFSBOOT_SWAP_MIRROR=} + +# +# Default ZFS datasets for root pool +# +# NOTE: Requires /tmp, /var/tmp, /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME +# NOTE: Anything after pound/hash character [#] is ignored as a comment. +# +f_isset ZFSBOOT_DATASETS || ZFSBOOT_DATASETS=" + # DATASET OPTIONS (comma or space separated; or both) + + # Boot Environment [BE] root and default boot dataset + /$ZFSBOOT_BEROOT_NAME mountpoint=none + /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME mountpoint=/ + + # Home directories separated so they are common to all BEs + /home mountpoint=/home + + # Create /tmp and allow exec but not setuid + /tmp mountpoint=/tmp,exec=on,setuid=off + + # Don't mount /usr so that 'base' files go to the BEROOT + /usr mountpoint=/usr,canmount=off + + # Ports tree + /usr/ports setuid=off + + # Source tree + /usr/src + + # Create /var and friends + /var mountpoint=/var,canmount=off + /var/audit exec=off,setuid=off + /var/crash exec=off,setuid=off + /var/log exec=off,setuid=off + /var/mail atime=on + /var/tmp setuid=off +" # END-QUOTE + +# +# If interactive and the user has not explicitly chosen a vdev type or disks, +# make the user confirm scripted/default choices when proceeding to install. +# +: ${ZFSBOOT_CONFIRM_LAYOUT:=1} + +############################################################ GLOBALS + +# +# Format of a line in printf(1) syntax to add to fstab(5) +# +FSTAB_FMT="%s\t\t%s\t%s\t%s\t\t%s\t%s\n" + +# +# Command strings for various tasks +# +COPY='cp "%s" "%s"' +CHMOD_MODE='chmod %s "%s"' +DD_WITH_OPTIONS='dd if="%s" of="%s" %s' +ECHO_APPEND='echo "%s" >> "%s"' +ECHO_OVERWRITE='echo "%s" > "%s"' +GELI_ATTACH='geli attach -j - -k "%s" "%s"' +GELI_ATTACH_NOKEY='geli attach -j - "%s"' +GELI_DETACH_F='geli detach -f "%s"' +GELI_PASSWORD_INIT='geli init -b -B "%s" -e %s -J - -K "%s" -l 256 -s 4096 "%s"' +GELI_PASSWORD_GELIBOOT_INIT='geli init -bg -e %s -J - -l 256 -s 4096 "%s"' +GPART_ADD_ALIGN='gpart add %s -t %s "%s"' +GPART_ADD_ALIGN_INDEX='gpart add %s -i %s -t %s "%s"' +GPART_ADD_ALIGN_INDEX_WITH_SIZE='gpart add %s -i %s -t %s -s %s "%s"' +GPART_ADD_ALIGN_LABEL='gpart add %s -l %s -t %s "%s"' +GPART_ADD_ALIGN_LABEL_WITH_SIZE='gpart add %s -l %s -t %s -s %s "%s"' +GPART_BOOTCODE='gpart bootcode -b "%s" "%s"' +GPART_BOOTCODE_PART='gpart bootcode -b "%s" -p "%s" -i %s "%s"' +GPART_CREATE='gpart create -s %s "%s"' +GPART_DESTROY_F='gpart destroy -F "%s"' +GPART_SET_ACTIVE='gpart set -a active -i %s "%s"' +GPART_SET_LENOVOFIX='gpart set -a lenovofix "%s"' +GPART_SET_PMBR_ACTIVE='gpart set -a active "%s"' +GRAID_DELETE='graid delete "%s"' +KLDLOAD='kldload %s' +LN_SF='ln -sf "%s" "%s"' +MKDIR_P='mkdir -p "%s"' +MOUNT_TYPE='mount -t %s "%s" "%s"' +NEWFS_ESP='newfs_msdos "%s"' +PRINTF_CONF="printf '%s=\"%%s\"\\\n' %s >> \"%s\"" +PRINTF_FSTAB='printf "$FSTAB_FMT" "%s" "%s" "%s" "%s" "%s" "%s" >> "%s"' +SHELL_TRUNCATE=':> "%s"' +SWAP_GMIRROR_LABEL='gmirror label swap %s' +SYSCTL_ZFS_MIN_ASHIFT_12='sysctl vfs.zfs.vdev.min_auto_ashift=12' +UMOUNT='umount "%s"' +ZFS_CREATE_WITH_OPTIONS='zfs create %s "%s"' +ZFS_MOUNT='zfs mount "%s"' +ZFS_SET='zfs set "%s" "%s"' +ZFS_UNMOUNT='zfs unmount "%s"' +ZPOOL_CREATE_WITH_OPTIONS='zpool create %s "%s" %s %s' +ZPOOL_DESTROY='zpool destroy "%s"' +ZPOOL_EXPORT='zpool export "%s"' +ZPOOL_EXPORT_F='zpool export -f "%s"' +ZPOOL_IMPORT_WITH_OPTIONS='zpool import %s "%s"' +ZPOOL_LABELCLEAR_F='zpool labelclear -f "%s"' +ZPOOL_SET='zpool set %s "%s"' + +# +# Strings that should be moved to an i18n file and loaded with f_include_lang() +# +hline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER" +hline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER" +hline_arrows_tab_enter="Press arrows, TAB or ENTER" +msg_an_unknown_error_occurred="An unknown error occurred" +msg_back="Back" +msg_cancel="Cancel" +msg_change_selection="Change Selection" +msg_configure_options="Configure Options:" +msg_detailed_disk_info="gpart(8) show %s:\n%s\n\ncamcontrol(8) inquiry %s:\n%s\n\n\ncamcontrol(8) identify %s:\n%s\n" +msg_disk_info="Disk Info" +msg_disk_info_help="Get detailed information on disk device(s)" +msg_disk_plural="disks" +msg_disk_singular="disk" +msg_encrypt_disks="Encrypt Disks?" +msg_encrypt_disks_help="Use geli(8) to encrypt all data partitions" +msg_error="Error" +msg_force_4k_sectors="Force 4K Sectors?" +msg_force_4k_sectors_help="Align partitions to 4K sector boundaries and set vfs.zfs.vdev.min_auto_ashift=12" +msg_freebsd_installer="$OSNAME Installer" +msg_geli_password="Enter a strong passphrase, used to protect your encryption keys. You will be required to enter this passphrase each time the system is booted" +msg_geli_setup="Initializing encryption on selected disks,\n this will take several seconds per disk" +msg_install="Install" +msg_install_desc="Proceed with Installation" +msg_install_help="Create ZFS boot pool with displayed options" +msg_invalid_boot_pool_size="Invalid boot pool size \`%s'" +msg_invalid_disk_argument="Invalid disk argument \`%s'" +msg_invalid_index_argument="Invalid index argument \`%s'" +msg_invalid_pool_size="Invalid pool size \`%s'" +msg_invalid_swap_size="Invalid swap size \`%s'" +msg_invalid_virtual_device_type="Invalid Virtual Device type \`%s'" +msg_last_chance_are_you_sure="Last Chance! Are you sure you want to destroy\nthe current contents of the following disks:\n\n %s" +msg_last_chance_are_you_sure_color='\\ZrLast Chance!\\ZR Are you \\Z1sure\\Zn you want to \\Zr\\Z1destroy\\Zn\nthe current contents of the following disks:\n\n %s' +msg_mirror_desc="Mirror - n-Way Mirroring" +msg_mirror_help="[2+ Disks] Mirroring provides the best performance, but the least storage" +msg_missing_disk_arguments="missing disk arguments" +msg_missing_one_or_more_scripted_disks="Missing one or more scripted disks!" +msg_no="NO" +msg_no_disks_present_to_configure="No disk(s) present to configure" +msg_no_disks_selected="No disks selected." +msg_not_enough_disks_selected="Not enough disks selected. (%u < %u minimum)" +msg_null_disk_argument="NULL disk argument" +msg_null_index_argument="NULL index argument" +msg_null_poolname="NULL poolname" +msg_odd_disk_selected="An even number of disks must be selected to create a RAID 1+0. (%u selected)" +msg_ok="OK" +msg_partition_scheme="Partition Scheme" +msg_partition_scheme_help="Select partitioning scheme. GPT is recommended." +msg_please_enter_a_name_for_your_pool="Please enter a name for your pool:" +msg_please_enter_amount_of_swap_space="Please enter amount of swap space (SI-Unit suffixes\nrecommended; e.g., \`2g' for 2 Gigabytes):" +msg_please_select_one_or_more_disks="Please select one or more disks to create a pool:" +msg_pool_name="Pool Name" +msg_pool_name_cannot_be_empty="Pool name cannot be empty." +msg_pool_name_help="Customize the name of the pool to be created (Required)" +msg_pool_type_disks="Pool Type/Disks:" +msg_pool_type_disks_help="Choose type of ZFS Virtual Device and disks to use (Required)" +msg_processing_selection="Processing selection..." +msg_raid10_desc="RAID 1+0 - n x 2-Way Mirrors" +msg_raid10_help="[4+ Disks] Striped Mirrors provides the best performance, but the least storage" +msg_raidz1_desc="RAID-Z1 - Single Redundant RAID" +msg_raidz1_help="[3+ Disks] Withstand failure of 1 disk. Recommended for: 3, 5 or 9 disks" +msg_raidz2_desc="RAID-Z2 - Double Redundant RAID" +msg_raidz2_help="[4+ Disks] Withstand failure of 2 disks. Recommended for: 4, 6 or 10 disks" +msg_raidz3_desc="RAID-Z3 - Triple Redundant RAID" +msg_raidz3_help="[5+ Disks] Withstand failure of 3 disks. Recommended for: 5, 7 or 11 disks" +msg_rescan_devices="Rescan Devices" +msg_rescan_devices_help="Scan for device changes" +msg_select="Select" +msg_select_a_disk_device="Select a disk device" +msg_select_virtual_device_type="Select Virtual Device type:" +msg_stripe_desc="Stripe - No Redundancy" +msg_stripe_help="[1+ Disks] Striping provides maximum storage but no redundancy" +msg_swap_encrypt="Encrypt Swap?" +msg_swap_encrypt_help="Encrypt swap partitions with temporary keys, discarded on reboot" +msg_swap_invalid="The selected swap size (%s) is invalid. Enter a number optionally followed by units. Example: 2G" +msg_swap_mirror="Mirror Swap?" +msg_swap_mirror_help="Mirror swap partitions for redundancy, breaks crash dumps" +msg_swap_size="Swap Size" +msg_swap_size_help="Customize how much swap space is allocated to each selected disk" +msg_swap_toosmall="The selected swap size (%s) is too small. Please enter a value greater than 100MB or enter 0 for no swap" +msg_these_disks_are_too_small="These disks are smaller than the amount of requested\nswap (%s) and/or geli(8) (%s) partitions, which would\ntake 100%% or more of each of the following selected disks:\n\n %s\n\nRecommend changing partition size(s) and/or selecting a\ndifferent set of disks." +msg_unable_to_get_disk_capacity="Unable to get disk capacity of \`%s'" +msg_unsupported_partition_scheme="%s is an unsupported partition scheme" +msg_user_cancelled="User Cancelled." +msg_yes="YES" +msg_zfs_configuration="ZFS Configuration" +msg_please_enter_options_for_your_pool="Please enter options for your pool" +msg_zfs_options_name="ZFS Pool Options" +msg_zfs_options_name_help="Customize ZFS options for the pool to be created" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local title="$DIALOG_TITLE" + local btitle="$DIALOG_BACKTITLE" + local prompt="$msg_configure_options" + local force4k="$msg_no" + local usegeli="$msg_no" + local swapgeli="$msg_no" + local swapmirror="$msg_no" + [ "$ZFSBOOT_FORCE_4K_SECTORS" ] && force4k="$msg_yes" + [ "$ZFSBOOT_GELI_ENCRYPTION" ] && usegeli="$msg_yes" + [ "$ZFSBOOT_SWAP_ENCRYPTION" ] && swapgeli="$msg_yes" + [ "$ZFSBOOT_SWAP_MIRROR" ] && swapmirror="$msg_yes" + local disks n disks_grammar + f_count n $ZFSBOOT_DISKS + { [ $n -eq 1 ] && disks_grammar=$msg_disk_singular; } || + disks_grammar=$msg_disk_plural # grammar + local menu_list=" + '>>> $msg_install' '$msg_install_desc' + '$msg_install_help' + 'T $msg_pool_type_disks' + '$ZFSBOOT_VDEV_TYPE: $n $disks_grammar' + '$msg_pool_type_disks_help' + '- $msg_rescan_devices' '*' + '$msg_rescan_devices_help' + '- $msg_disk_info' '*' + '$msg_disk_info_help' + 'N $msg_pool_name' '$ZFSBOOT_POOL_NAME' + '$msg_pool_name_help' + '4 $msg_force_4k_sectors' + '$force4k' + '$msg_force_4k_sectors_help' + 'E $msg_encrypt_disks' '$usegeli' + '$msg_encrypt_disks_help' + 'P $msg_partition_scheme' + '$ZFSBOOT_PARTITION_SCHEME ($ZFSBOOT_BOOT_TYPE)' + '$msg_partition_scheme_help' + 'S $msg_swap_size' '$ZFSBOOT_SWAP_SIZE' + '$msg_swap_size_help' + 'M $msg_swap_mirror' '$swapmirror' + '$msg_swap_mirror_help' + 'W $msg_swap_encrypt' '$swapgeli' + '$msg_swap_encrypt_help' + 'O $msg_zfs_options_name' '$ZFSBOOT_POOL_CREATE_OPTIONS' + '$msg_zfs_options_name_help' + " # END-QUOTE + local defaultitem= # Calculated below + local hline="$hline_alnum_arrows_punc_tab_enter" + + local height width rows + eval f_dialog_menu_with_help_size height width rows \ + \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $menu_list + + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$title\" \ + --backtitle \"\$btitle\" \ + --hline \"\$hline\" \ + --item-help \ + --ok-label \"\$msg_select\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + ${USE_DIALOG:+--} $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_data_sanitize menu_choice + f_dialog_menutag_store "$menu_choice" + + # Only update default-item on success + [ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice" + + return $retval +} + +# dialog_last_chance $disks ... +# +# Display a list of the disks that the user is about to destroy. The default +# action is to return error status unless the user explicitly (non-default) +# selects "Yes" from the noyes dialog. +# +dialog_last_chance() +{ + local title="$DIALOG_TITLE" + local btitle="$DIALOG_BACKTITLE" + local prompt # Calculated below + local hline="$hline_arrows_tab_enter" + + local height=8 width=50 prefix=" " + local plen=${#prefix} list= line= + local max_width=$(( $width - 3 - $plen )) + + local yes no defaultno extra_args format + if [ "$USE_XDIALOG" ]; then + yes=ok no=cancel defaultno=default-no + extra_args="--wrap --left" + format="$msg_last_chance_are_you_sure" + else + yes=yes no=no defaultno=defaultno + extra_args="--colors --cr-wrap" + format="$msg_last_chance_are_you_sure_color" + fi + + local disk line_width + for disk in $*; do + if [ "$line" ]; then + line_width=${#line} + else + line_width=$plen + fi + line_width=$(( $line_width + 1 + ${#disk} )) + # Add newline before disk if it would exceed max_width + if [ $line_width -gt $max_width ]; then + list="$list$line\n" + line="$prefix" + height=$(( $height + 1 )) + fi + # Add the disk to the list + line="$line $disk" + done + # Append the left-overs + if [ "${line#$prefix}" ]; then + list="$list$line" + height=$(( $height + 1 )) + fi + + # Add height for Xdialog(1) + [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) + + prompt=$( printf "$format" "$list" ) + f_dprintf "%s: Last Chance!" "$0" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --hline "$hline" \ + --$defaultno \ + --$yes-label "$msg_yes" \ + --$no-label "$msg_no" \ + $extra_args \ + --yesno "$prompt" $height $width +} + +# dialog_menu_layout +# +# Configure Virtual Device type and disks to use for the ZFS boot pool. User +# must select enough disks to satisfy the chosen vdev type. +# +dialog_menu_layout() +{ + local funcname=dialog_menu_layout + local title="$DIALOG_TITLE" + local btitle="$DIALOG_BACKTITLE" + local vdev_prompt="$msg_select_virtual_device_type" + local disk_prompt="$msg_please_select_one_or_more_disks" + local vdev_menu_list=" + 'stripe' '$msg_stripe_desc' '$msg_stripe_help' + 'mirror' '$msg_mirror_desc' '$msg_mirror_help' + 'raid10' '$msg_raid10_desc' '$msg_raid10_help' + 'raidz1' '$msg_raidz1_desc' '$msg_raidz1_help' + 'raidz2' '$msg_raidz2_desc' '$msg_raidz2_help' + 'raidz3' '$msg_raidz3_desc' '$msg_raidz3_help' + " # END-QUOTE + local disk_check_list= # Calculated below + local vdev_hline="$hline_arrows_tab_enter" + local disk_hline="$hline_arrows_space_tab_enter" + + # Warn the user if vdev type is not valid + case "$ZFSBOOT_VDEV_TYPE" in + stripe|mirror|raid10|raidz1|raidz2|raidz3) : known good ;; + *) + f_dprintf "%s: Invalid virtual device type \`%s'" \ + $funcname "$ZFSBOOT_VDEV_TYPE" + f_show_err "$msg_invalid_virtual_device_type" \ + "$ZFSBOOT_VDEV_TYPE" + f_interactive || return $FAILURE + esac + + # Calculate size of vdev menu once only + local vheight vwidth vrows + eval f_dialog_menu_with_help_size vheight vwidth vrows \ + \"\$title\" \"\$btitle\" \"\$vdev_prompt\" \"\$vdev_hline\" \ + $vdev_menu_list + + # Get a list of probed disk devices + local disks= + debug= f_device_find "" $DEVICE_TYPE_DISK disks + + # Prune out mounted md(4) devices that may be part of the boot process + local disk name new_list= + for disk in $disks; do + debug= $disk get name name + case "$name" in + md[0-9]*) f_mounted -b "/dev/$name" && continue ;; + esac + new_list="$new_list $disk" + done + disks="${new_list# }" + + # Prune out disks that are not available to install to + local avail_disks= + for disk in $disks; do + debug= $disk get name name + geom disk list $name | awk '$1 == "Mode:" && $2 != "r0w0e0" { exit 1 }' + [ $? -eq 0 ] && avail_disks="$avail_disks $disk" + done + disks="${avail_disks# }" + + # Debugging + if [ "$debug" ]; then + local disk_names= + for disk in $disks; do + debug= $disk get name name + disk_names="$disk_names $name" + done + f_dprintf "$funcname: disks=[%s]" "${disk_names# }" + fi + + if [ ! "$disks" ]; then + f_dprintf "No disk(s) present to configure" + f_show_err "$msg_no_disks_present_to_configure" + return $FAILURE + fi + + # Lets sort the disks array to be more user friendly + f_device_sort_by name disks disks + + # + # Operate in a loop so we can (if interactive) repeat if not enough + # disks are selected to satisfy the chosen vdev type or user wants to + # back-up to the previous menu. + # + local vardisk ndisks onoff selections vdev_choice breakout device + local valid_disks all_valid want_disks desc height width rows + while :; do + # + # Confirm the vdev type that was selected + # + if f_interactive && [ "$ZFSBOOT_CONFIRM_LAYOUT" ]; then + vdev_choice=$( eval $DIALOG \ + --title \"\$title\" \ + --backtitle \"\$btitle\" \ + --hline \"\$vdev_hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --item-help \ + --default-item \"\$ZFSBOOT_VDEV_TYPE\" \ + --menu \"\$vdev_prompt\" \ + $vheight $vwidth $vrows \ + $vdev_menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) || return $? + # Exit if user pressed ESC or chose Cancel/No + f_dialog_data_sanitize vdev_choice + + ZFSBOOT_VDEV_TYPE="$vdev_choice" + f_dprintf "$funcname: ZFSBOOT_VDEV_TYPE=[%s]" \ + "$ZFSBOOT_VDEV_TYPE" + fi + + # Determine the number of disks needed for this vdev type + want_disks=0 + case "$ZFSBOOT_VDEV_TYPE" in + stripe) want_disks=1 ;; + mirror) want_disks=2 ;; + raid10) want_disks=4 ;; + raidz1) want_disks=3 ;; + raidz2) want_disks=4 ;; + raidz3) want_disks=5 ;; + esac + + # + # Warn the user if any scripted disks are invalid + # + valid_disks= all_valid=${ZFSBOOT_DISKS:+1} # optimism + for disk in $ZFSBOOT_DISKS; do + if debug= f_device_find -1 \ + $disk $DEVICE_TYPE_DISK device + then + valid_disks="$valid_disks $disk" + continue + fi + f_dprintf "$funcname: \`%s' is not a real disk" "$disk" + all_valid= + done + if [ ! "$all_valid" ]; then + if [ "$ZFSBOOT_DISKS" ]; then + f_show_err \ + "$msg_missing_one_or_more_scripted_disks" + else + f_dprintf "No disks selected." + f_interactive || + f_show_err "$msg_no_disks_selected" + fi + f_interactive || return $FAILURE + fi + ZFSBOOT_DISKS="${valid_disks# }" + + # + # Short-circuit if we're running non-interactively + # + if ! f_interactive || [ ! "$ZFSBOOT_CONFIRM_LAYOUT" ]; then + f_count ndisks $ZFSBOOT_DISKS + [ $ndisks -ge $want_disks ] && break # to success + + # Not enough disks selected + f_dprintf "$funcname: %s: %s (%u < %u minimum)" \ + "$ZFSBOOT_VDEV_TYPE" \ + "Not enough disks selected." \ + $ndisks $want_disks + f_interactive || return $FAILURE + msg_yes="$msg_change_selection" msg_no="$msg_cancel" \ + f_yesno "%s: $msg_not_enough_disks_selected" \ + "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks || + return $FAILURE + fi + + # + # Confirm the disks that were selected + # Loop until the user cancels or selects enough disks + # + breakout= + while :; do + # Loop over list of available disks, resetting state + for disk in $disks; do + f_isset _${disk}_status && setvar _${disk}_status + done + + # Loop over list of selected disks and create temporary + # locals to map statuses onto up-to-date list of disks + for disk in $ZFSBOOT_DISKS; do + debug= f_device_find -1 \ + $disk $DEVICE_TYPE_DISK disk + f_isset _${disk}_status || + local _${disk}_status + setvar _${disk}_status on + done + + # Create the checklist menu of discovered disk devices + disk_check_list= + for disk in $disks; do + desc= + $disk get name name + $disk get desc desc + f_shell_escape "$desc" desc + f_getvar _${disk}_status:-off onoff + disk_check_list="$disk_check_list + $name '$desc' $onoff" + done + + eval f_dialog_checklist_size height width rows \ + \"\$title\" \"\$btitle\" \"\$disk_prompt\" \ + \"\$disk_hline\" $disk_check_list + + selections=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --separate-output \ + --hline \"\$disk_hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_back\" \ + --checklist \"\$disk_prompt\" \ + $height $width $rows \ + $disk_check_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) || break + # Loop if user pressed ESC or chose Cancel/No + f_dialog_data_sanitize selections + + ZFSBOOT_DISKS="$selections" + f_dprintf "$funcname: ZFSBOOT_DISKS=[%s]" \ + "$ZFSBOOT_DISKS" + + f_count ndisks $ZFSBOOT_DISKS + + if [ "$ZFSBOOT_VDEV_TYPE" == "raid10" ] && + [ $(( $ndisks % 2 )) -ne 0 ]; then + f_dprintf "$funcname: %s: %s (%u %% 2 = %u)" \ + "$ZFSBOOT_VDEV_TYPE" \ + "Number of disks not even:" \ + $ndisks $(( $ndisks % 2 )) + msg_yes="$msg_change_selection" \ + msg_no="$msg_cancel" \ + f_yesno "%s: $msg_odd_disk_selected" \ + "$ZFSBOOT_VDEV_TYPE" $ndisks || + break + continue + fi + + [ $ndisks -ge $want_disks ] && + breakout=break && break + + # Not enough disks selected + f_dprintf "$funcname: %s: %s (%u < %u minimum)" \ + "$ZFSBOOT_VDEV_TYPE" \ + "Not enough disks selected." \ + $ndisks $want_disks + msg_yes="$msg_change_selection" msg_no="$msg_cancel" \ + f_yesno "%s: $msg_not_enough_disks_selected" \ + "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks || + break + done + [ "$breakout" = "break" ] && break + [ "$ZFSBOOT_CONFIRM_LAYOUT" ] || return $FAILURE + done + + return $DIALOG_OK +} + +# zfs_create_diskpart $disk $index +# +# For each block device to be used in the pool, rather than just create the +# pool with the raw block devices (e.g., da0, da1, etc.) we create partitions +# so we can have some real swap. This also provides wiggle room incase your +# replacement drivers do not have the exact same sector counts. +# +# NOTE: $swapsize and $bootsize should be defined by the calling function. +# NOTE: Sets $bootpart and $targetpart for the calling function. +# +zfs_create_diskpart() +{ + local funcname=zfs_create_diskpart + local disk="$1" index="$2" + local efibootpart + + # Check arguments + if [ ! "$disk" ]; then + f_dprintf "$funcname: NULL disk argument" + msg_error="$msg_error: $funcname" \ + f_show_err "$msg_null_disk_argument" + return $FAILURE + fi + if [ "${disk#*[$IFS]}" != "$disk" ]; then + f_dprintf "$funcname: Invalid disk argument \`%s'" "$disk" + msg_error="$msg_error: $funcname" \ + f_show_err "$msg_invalid_disk_argument" "$disk" + return $FAILURE + fi + if [ ! "$index" ]; then + f_dprintf "$funcname: NULL index argument" + msg_error="$msg_error: $funcname" \ + f_show_err "$msg_null_index_argument" + return $FAILURE + fi + if ! f_isinteger "$index"; then + f_dprintf "$funcname: Invalid index argument \`%s'" "$index" + msg_error="$msg_error: $funcname" \ + f_show_err "$msg_invalid_index_argument" "$index" + return $FAILURE + fi + f_dprintf "$funcname: disk=[%s] index=[%s]" "$disk" "$index" + + # Check for unknown partition scheme before proceeding further + case "$ZFSBOOT_PARTITION_SCHEME" in + ""|GPT*) : known good ;; + *) + f_dprintf "$funcname: %s is an unsupported partition scheme" \ + "$ZFSBOOT_PARTITION_SCHEME" + msg_error="$msg_error: $funcname" f_show_err \ + "$msg_unsupported_partition_scheme" \ + "$ZFSBOOT_PARTITION_SCHEME" + return $FAILURE + esac + + # + # Destroy whatever partition layout is currently on disk. + # NOTE: `-F' required to destroy if partitions still exist. + # NOTE: Failure is ok here, blank disk will have nothing to destroy. + # + f_dprintf "$funcname: Exporting ZFS pools..." + zpool list -Ho name | while read z_name; do + f_eval_catch -d $funcname zpool "$ZPOOL_EXPORT_F" $z_name + done + f_dprintf "$funcname: Detaching all GELI providers..." + geli status | tail -n +2 | while read g_name g_status g_component; do + f_eval_catch -d $funcname geli "$GELI_DETACH_F" $g_name + done + f_dprintf "$funcname: Destroying all data/layouts on \`%s'..." "$disk" + f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk + f_eval_catch -d $funcname graid "$GRAID_DELETE" $disk + f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" /dev/$disk + + # Make doubly-sure backup GPT is destroyed + f_eval_catch -d $funcname gpart "$GPART_CREATE" gpt $disk + f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk + + # + # Lay down the desired type of partition scheme + # + local setsize align_small align_big + # + # If user has requested 4 K alignment, add these params to the + # gpart add calls. With GPT, we align large partitions to 1 M for + # improved performance on SSDs. + # + if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then + align_small="-a 4k" + align_big="-a 1m" + fi + + case "$ZFSBOOT_PARTITION_SCHEME" in + ""|GPT*) f_dprintf "$funcname: Creating GPT layout..." + # + # 1. Create GPT layout using labels + # + f_eval_catch $funcname gpart "$GPART_CREATE" gpt $disk || + return $FAILURE + + # + # Apply workarounds if requested by the user + # + if [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Lenovo Fix" ]; then + f_eval_catch $funcname gpart "$GPART_SET_LENOVOFIX" \ + $disk || return $FAILURE + elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Active" ]; then + f_eval_catch $funcname gpart "$GPART_SET_PMBR_ACTIVE" \ + $disk || return $FAILURE + fi + + # + # 2. Add small freebsd-boot and/or efi partition + # + if [ "$ZFSBOOT_BOOT_TYPE" = "UEFI" -o \ + "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ] + then + f_eval_catch -k justaddedpart $funcname gpart \ + "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ + "$align_small" efiboot$index efi 260M \ + $disk || return $FAILURE + + # We'll configure the ESP in bootconfig + # Note: This will always be p1 + efibootpart="/dev/gpt/efiboot$index" + f_dprintf "$funcname: configuring ESP at [%s]" \ + "${efibootpart}" + + f_eval_catch $funcname newfs_msdos "$NEWFS_ESP"\ + "$efibootpart" \ + || return $FAILURE + if [ $index -eq 0 ]; then + f_eval_catch $funcname printf "$PRINTF_FSTAB" \ + $efibootpart /boot/efi msdosfs \ + rw 2 2 "$BSDINSTALL_TMPETC/fstab" \ + || return $FAILURE + else + # Record the extra ones + echo "${efibootpart}" >> ${TMPDIR:-"/tmp"}/bsdinstall-esps + fi + fi + + if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS" -o \ + "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ] + then + f_eval_catch $funcname gpart \ + "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ + "$align_small" gptboot$index \ + freebsd-boot 512k $disk || return $FAILURE + if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS" ]; then + f_eval_catch $funcname gpart \ + "$GPART_BOOTCODE_PART" \ + /boot/pmbr /boot/gptzfsboot 1 \ + $disk || return $FAILURE + else + f_eval_catch $funcname gpart \ + "$GPART_BOOTCODE_PART" \ + /boot/pmbr /boot/gptzfsboot 2 \ + $disk || return $FAILURE + fi + fi + + # NB: ZFS pools will use `zfs#' GPT labels + if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ]; then + if [ "$ZFSBOOT_BOOT_POOL" ]; then + bootpart=p3 swappart=p4 targetpart=p4 + [ ${swapsize:-0} -gt 0 ] && targetpart=p5 + else + # Bootpart unused + bootpart=p3 swappart=p3 targetpart=p3 + [ ${swapsize:-0} -gt 0 ] && targetpart=p4 + fi + else + if [ "$ZFSBOOT_BOOT_POOL" ]; then + bootpart=p2 swappart=p3 targetpart=p3 + [ ${swapsize:-0} -gt 0 ] && targetpart=p4 + else + # Bootpart unused + bootpart=p2 swappart=p2 targetpart=p2 + [ ${swapsize:-0} -gt 0 ] && targetpart=p3 + fi + fi + + # + # Prepare boot pool if enabled (e.g., for geli(8)) + # + if [ "$ZFSBOOT_BOOT_POOL" ]; then + f_eval_catch $funcname gpart \ + "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ + "$align_big" boot$index freebsd-zfs \ + ${bootsize}b $disk || return $FAILURE + # Pedantically nuke any old labels + f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ + /dev/$disk$bootpart + if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then + # Pedantically detach targetpart for later + f_eval_catch -d $funcname geli \ + "$GELI_DETACH_F" \ + /dev/$disk$targetpart + fi + fi + + # + # 3. Add freebsd-swap partition labeled `swap#' + # + if [ ${swapsize:-0} -gt 0 ]; then + f_eval_catch $funcname gpart \ + "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ + "$align_big" swap$index freebsd-swap \ + ${swapsize}b $disk || return $FAILURE + # Pedantically nuke any old labels on the swap + f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ + /dev/$disk$swappart + fi + + # + # 4. Add freebsd-zfs partition labeled `zfs#' for zroot + # + if [ "$ZFSBOOT_POOL_SIZE" ]; then + f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ + "$align_big" zfs$index freebsd-zfs $ZFSBOOT_POOL_SIZE $disk || + return $FAILURE + else + f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_LABEL" \ + "$align_big" zfs$index freebsd-zfs $disk || + return $FAILURE + fi + f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ + /dev/$disk$targetpart + ;; + + esac # $ZFSBOOT_PARTITION_SCHEME + + # Update fstab(5) + local swapsize + f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize + if [ "$isswapmirror" ]; then + # This is not the first disk in the mirror, do nothing + elif [ ${swapsize:-0} -eq 0 ]; then + # If swap is 0 sized, don't add it to fstab + elif [ "$ZFSBOOT_SWAP_ENCRYPTION" -a "$ZFSBOOT_SWAP_MIRROR" ]; then + f_eval_catch $funcname printf "$PRINTF_FSTAB" \ + /dev/mirror/swap.eli none swap sw 0 0 \ + $BSDINSTALL_TMPETC/fstab || return $FAILURE + isswapmirror=1 + elif [ "$ZFSBOOT_SWAP_MIRROR" ]; then + f_eval_catch $funcname printf "$PRINTF_FSTAB" \ + /dev/mirror/swap none swap sw 0 0 \ + $BSDINSTALL_TMPETC/fstab || return $FAILURE + isswapmirror=1 + elif [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then + f_eval_catch $funcname printf "$PRINTF_FSTAB" \ + /dev/$disk${swappart}.eli none swap sw 0 0 \ + $BSDINSTALL_TMPETC/fstab || return $FAILURE + else + f_eval_catch $funcname printf "$PRINTF_FSTAB" \ + /dev/$disk$swappart none swap sw 0 0 \ + $BSDINSTALL_TMPETC/fstab || return $FAILURE + fi + + return $SUCCESS +} + +# zfs_create_boot $poolname $vdev_type $disks ... +# +# Creates boot pool and dataset layout. Returns error if something goes wrong. +# Errors are printed to stderr for collection and display. +# +zfs_create_boot() +{ + local funcname=zfs_create_boot + local zroot_name="$1" + local zroot_vdevtype="$2" + local zroot_vdevs= # Calculated below + local swap_devs= # Calculated below + local boot_vdevs= # Used for geli(8) layouts + shift 2 # poolname vdev_type + local disks="$*" disk + local isswapmirror + local bootpart targetpart swappart # Set by zfs_create_diskpart() below + local create_options + + # + # Pedantic checks; should never be seen + # + if [ ! "$zroot_name" ]; then + f_dprintf "$funcname: NULL poolname" + msg_error="$msg_error: $funcname" \ + f_show_err "$msg_null_poolname" + return $FAILURE + fi + if [ $# -lt 1 ]; then + f_dprintf "$funcname: missing disk arguments" + msg_error="$msg_error: $funcname" \ + f_show_err "$msg_missing_disk_arguments" + return $FAILURE + fi + f_dprintf "$funcname: poolname=[%s] vdev_type=[%s]" \ + "$zroot_name" "$zroot_vdevtype" + + # + # Initialize fstab(5) + # + f_dprintf "$funcname: Initializing temporary fstab(5) file..." + f_eval_catch $funcname sh "$SHELL_TRUNCATE" $BSDINSTALL_TMPETC/fstab || + return $FAILURE + f_eval_catch $funcname printf "$PRINTF_FSTAB" \ + "# Device" Mountpoint FStype Options Dump "Pass#" \ + $BSDINSTALL_TMPETC/fstab || return $FAILURE + + # + # Expand SI units in desired sizes + # + f_dprintf "$funcname: Expanding supplied size values..." + local swapsize bootsize poolsize + if ! f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize; then + f_dprintf "$funcname: Invalid swap size \`%s'" \ + "$ZFSBOOT_SWAP_SIZE" + f_show_err "$msg_invalid_swap_size" "$ZFSBOOT_SWAP_SIZE" + return $FAILURE + fi + if ! f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize; then + f_dprintf "$funcname: Invalid boot pool size \`%s'" \ + "$ZFSBOOT_BOOT_POOL_SIZE" + f_show_err "$msg_invalid_boot_pool_size" \ + "$ZFSBOOT_BOOT_POOL_SIZE" + return $FAILURE + fi + if [ "$ZFSBOOT_POOL_SIZE" ]; then + if ! f_expand_number "$ZFSBOOT_POOL_SIZE" poolsize; then + f_dprintf "$funcname: Invalid pool size \`%s'" \ + "$ZFSBOOT_POOL_SIZE" + f_show_err "$msg_invalid_pool_size" \ + "$ZFSBOOT_POOL_SIZE" + fi + f_dprintf "$funcname: ZFSBOOT_POOL_SIZE=[%s] poolsize=[%s]" \ + "$ZFSBOOT_POOL_SIZE" "$poolsize" + fi + f_dprintf "$funcname: ZFSBOOT_SWAP_SIZE=[%s] swapsize=[%s]" \ + "$ZFSBOOT_SWAP_SIZE" "$swapsize" + f_dprintf "$funcname: ZFSBOOT_BOOT_POOL_SIZE=[%s] bootsize=[%s]" \ + "$ZFSBOOT_BOOT_POOL_SIZE" "$bootsize" + + # + # Destroy the pool in-case this is our second time 'round (case of + # failure and installer presented ``Retry'' option to come back). + # + # NB: If we don't destroy the pool, later gpart(8) destroy commands + # that try to clear existing partitions (see zfs_create_diskpart()) + # will fail with a `Device Busy' error, leading to `GEOM exists'. + # + f_eval_catch -d $funcname zpool "$ZPOOL_DESTROY" "$zroot_name" + + # + # Prepare the disks and build pool device list(s) + # + f_dprintf "$funcname: Preparing disk partitions for ZFS pool..." + + # Force 4K sectors using vfs.zfs.vdev.min_auto_ashift=12 + if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then + f_dprintf "$funcname: With 4K sectors..." + f_eval_catch $funcname sysctl "$SYSCTL_ZFS_MIN_ASHIFT_12" \ + || return $FAILURE + fi + local n=0 + for disk in $disks; do + zfs_create_diskpart $disk $n || return $FAILURE + # Now $bootpart, $targetpart, and $swappart are set (suffix + # for $disk) + if [ "$ZFSBOOT_BOOT_POOL" ]; then + boot_vdevs="$boot_vdevs $disk$bootpart" + fi + zroot_vdevs="$zroot_vdevs $disk$targetpart" + if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then + zroot_vdevs="$zroot_vdevs.eli" + fi + + n=$(( $n + 1 )) + done # disks + + # + # If we need/want a boot pool, create it + # + if [ "$ZFSBOOT_BOOT_POOL" ]; then + local bootpool_vdevtype= # Calculated below + local bootpool_options= # Calculated below + local bootpool_name="$ZFSBOOT_BOOT_POOL_NAME" + local bootpool="$BSDINSTALL_CHROOT/$bootpool_name" + local zroot_key="${ZFSBOOT_GELI_KEY_FILE#/}" + + f_dprintf "$funcname: Setting up boot pool..." + [ "$ZFSBOOT_GELI_ENCRYPTION" ] && + f_dprintf "$funcname: For encrypted root disk..." + + # Create parent directory for boot pool + f_eval_catch -d $funcname umount "$UMOUNT" "$BSDINSTALL_CHROOT" + f_eval_catch $funcname mount "$MOUNT_TYPE" tmpfs none \ + $BSDINSTALL_CHROOT || return $FAILURE + + # Create mirror across the boot partition on all disks + local nvdevs + f_count nvdevs $boot_vdevs + [ $nvdevs -gt 1 ] && bootpool_vdevtype=mirror + + create_options="$ZFSBOOT_BOOT_POOL_CREATE_OPTIONS" + bootpool_options="-o altroot=$BSDINSTALL_CHROOT" + bootpool_options="$bootpool_options $create_options" + bootpool_options="$bootpool_options -m \"/$bootpool_name\" -f" + f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ + "$bootpool_options" "$bootpool_name" \ + "$bootpool_vdevtype" "$boot_vdevs" || + return $FAILURE + + f_eval_catch $funcname mkdir "$MKDIR_P" "$bootpool/boot" || + return $FAILURE + + if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then + # Generate an encryption key using random(4) + f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ + /dev/random "$bootpool/$zroot_key" \ + "bs=4096 count=1" || return $FAILURE + f_eval_catch $funcname chmod "$CHMOD_MODE" \ + go-wrx "$bootpool/$zroot_key" || + return $FAILURE + fi + + fi + + # + # Create the geli(8) GEOMS + # + if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then + # + # Load the AES-NI kernel module to accelerate encryption + # + f_eval_catch -d $funcname kldload "$KLDLOAD" "aesni" + # Prompt user for password (twice) + if ! msg_enter_new_password="$msg_geli_password" \ + f_dialog_input_password + then + f_dprintf "$funcname: User cancelled" + f_show_err "$msg_user_cancelled" + return $FAILURE + fi + + # Initialize geli(8) on each of the target partitions + for disk in $disks; do + f_dialog_info "$msg_geli_setup" \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + if [ "$ZFSBOOT_BOOT_POOL" ]; then + if ! echo "$pw_password" | f_eval_catch \ + $funcname geli "$GELI_PASSWORD_INIT" \ + "$bootpool/boot/$disk$targetpart.eli" \ + AES-XTS "$bootpool/$zroot_key" \ + $disk$targetpart + then + f_interactive || f_die + unset pw_password # Sensitive info + return $FAILURE + fi + if ! echo "$pw_password" | f_eval_catch \ + $funcname geli "$GELI_ATTACH" \ + "$bootpool/$zroot_key" $disk$targetpart + then + f_interactive || f_die + unset pw_password # Sensitive info + return $FAILURE + fi + else + # With no bootpool, there is no place to store + # the key files, use only a password + if ! echo "$pw_password" | f_eval_catch \ + $funcname geli \ + "$GELI_PASSWORD_GELIBOOT_INIT" \ + AES-XTS $disk$targetpart + then + f_interactive || f_die + unset pw_password # Sensitive info + return $FAILURE + fi + if ! echo "$pw_password" | f_eval_catch \ + $funcname geli "$GELI_ATTACH_NOKEY" \ + $disk$targetpart + then + f_interactive || f_die + unset pw_password # Sensitive info + return $FAILURE + fi + fi + done + unset pw_password # Sensitive info + fi + + if [ "$ZFSBOOT_BOOT_POOL" ]; then + # Clean up + f_eval_catch $funcname zfs "$ZFS_UNMOUNT" "$bootpool_name" || + return $FAILURE + # tmpfs + f_eval_catch -d $funcname umount "$UMOUNT" "$BSDINSTALL_CHROOT" + fi + + # + # Create the gmirror(8) GEOMS for swap + # + if [ ${swapsize:-0} -gt 0 -a "$ZFSBOOT_SWAP_MIRROR" ]; then + for disk in $disks; do + swap_devs="$swap_devs $disk$swappart" + done + f_eval_catch $funcname gmirror "$SWAP_GMIRROR_LABEL" \ + "$swap_devs" || return $FAILURE + fi + + # + # Create the ZFS root pool with desired type and disk devices + # + f_dprintf "$funcname: Creating root pool..." + create_options="$ZFSBOOT_POOL_CREATE_OPTIONS" + if [ "$zroot_vdevtype" == "raid10" ]; then + raid10_vdevs="" + for vdev in $zroot_vdevs; do + f_count nvdev $raid10_vdevs + if [ $(( $nvdev % 3 )) -eq 0 ]; then + raid10_vdevs="$raid10_vdevs mirror" + fi + raid10_vdevs="$raid10_vdevs $vdev" + done + f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ + "-o altroot=$BSDINSTALL_CHROOT $create_options -m none -f" \ + "$zroot_name" "" "$raid10_vdevs" || return $FAILURE + else + f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ + "-o altroot=$BSDINSTALL_CHROOT $create_options -m none -f" \ + "$zroot_name" "$zroot_vdevtype" "$zroot_vdevs" || + return $FAILURE + fi + + # + # Create ZFS dataset layout within the new root pool + # + f_dprintf "$funcname: Creating ZFS datasets..." + echo "$ZFSBOOT_DATASETS" | while read dataset options; do + # Skip blank lines and comments + case "$dataset" in "#"*|"") continue; esac + # Remove potential inline comments in options + options="${options%%#*}" + # Replace tabs with spaces + f_replaceall "$options" " " " " options + # Reduce contiguous runs of space to one single space + oldoptions= + while [ "$oldoptions" != "$options" ]; do + oldoptions="$options" + f_replaceall "$options" " " " " options + done + # Replace both commas and spaces with ` -o ' + f_replaceall "$options" "[ ,]" " -o " options + # Create the dataset with desired options + f_eval_catch $funcname zfs "$ZFS_CREATE_WITH_OPTIONS" \ + "${options:+-o $options}" "$zroot_name$dataset" || + return $FAILURE + done + + # + # Set a mountpoint for the root of the pool so newly created datasets + # have a mountpoint to inherit + # + f_dprintf "$funcname: Setting mountpoint for root of the pool..." + f_eval_catch $funcname zfs "$ZFS_SET" \ + "mountpoint=/$zroot_name" "$zroot_name" || return $FAILURE + + # Touch up permissions on the tmp directories + f_dprintf "$funcname: Modifying directory permissions..." + local dir + for dir in /tmp /var/tmp; do + f_eval_catch $funcname mkdir "$MKDIR_P" \ + $BSDINSTALL_CHROOT$dir || return $FAILURE + f_eval_catch $funcname chmod "$CHMOD_MODE" 1777 \ + $BSDINSTALL_CHROOT$dir || return $FAILURE + done + + # Set bootfs property + local zroot_bootfs="$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME" + f_dprintf "$funcname: Setting bootfs property..." + f_eval_catch $funcname zpool "$ZPOOL_SET" \ + "bootfs=\"$zroot_name/$zroot_bootfs\"" "$zroot_name" || + return $FAILURE + + # Remount bootpool and create symlink(s) + if [ "$ZFSBOOT_BOOT_POOL" ]; then + f_eval_catch $funcname zfs "$ZFS_MOUNT" "$bootpool_name" || + return $FAILURE + f_dprintf "$funcname: Creating /boot symlink for boot pool..." + f_eval_catch $funcname ln "$LN_SF" "$bootpool_name/boot" \ + $BSDINSTALL_CHROOT/boot || return $FAILURE + fi + + # zpool.cache is required to mount more than one pool at boot time + f_dprintf "$funcname: Configuring zpool.cache for zroot..." + f_eval_catch $funcname mkdir "$MKDIR_P" $BSDINSTALL_CHROOT/boot/zfs || + return $FAILURE + f_eval_catch $funcname zpool "$ZPOOL_SET" \ + "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \ + "$zroot_name" || return $FAILURE + + if [ "$ZFSBOOT_BOOT_POOL" ]; then + f_eval_catch $funcname printf "$PRINTF_CONF" \ + vfs.root.mountfrom \ + "\"zfs:$zroot_name/$zroot_bootfs\"" \ + $BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE + fi + # + # Set canmount=noauto so that the default Boot Environment (BE) does + # not get mounted if a different BE is selected from the beastie menu + # + f_dprintf "$funcname: Set canmount=noauto for any datasets under the BE..." + echo "$ZFSBOOT_DATASETS" | while read dataset options; do + # Skip blank lines and comments + case "$dataset" in "#"*|"") continue; esac + options="${options%%#*}" + # + case "$dataset" in "/$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME"*) + f_eval_catch $funcname zfs "$ZFS_SET" "canmount=noauto" \ + "$zroot_name$dataset" || return $FAILURE ;; + *) continue ;; + esac + done + + # Last, but not least... required lines for rc.conf(5)/loader.conf(5) + # NOTE: We later concatenate these into their destination + f_dprintf "%s: Configuring rc.conf(5)/loader.conf(5) additions..." \ + "$funcname" + f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_enable=\"YES\"' \ + $BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE + f_eval_catch $funcname echo "$ECHO_APPEND" \ + 'kern.geom.label.disk_ident.enable=\"0\"' \ + $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE + f_eval_catch $funcname echo "$ECHO_APPEND" \ + 'kern.geom.label.gptid.enable=\"0\"' \ + $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE + + if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then + f_eval_catch $funcname echo "$ECHO_APPEND" \ + 'vfs.zfs.vdev.min_auto_ashift=12' \ + $BSDINSTALL_TMPETC/sysctl.conf.zfs || return $FAILURE + fi + + if [ "$ZFSBOOT_SWAP_MIRROR" ]; then + f_eval_catch $funcname echo "$ECHO_APPEND" \ + 'geom_mirror_load=\"YES\"' \ + $BSDINSTALL_TMPBOOT/loader.conf.gmirror || + return $FAILURE + fi + + # We're all done unless we should go on to do encryption + [ "$ZFSBOOT_GELI_ENCRYPTION" ] || return $SUCCESS + + # + # Configure geli(8)-based encryption + # + f_dprintf "$funcname: Configuring disk encryption..." + f_eval_catch $funcname echo "$ECHO_APPEND" 'aesni_load=\"YES\"' \ + $BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE + f_eval_catch $funcname echo "$ECHO_APPEND" 'geom_eli_load=\"YES\"' \ + $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE + + # We're all done unless we should go on for boot pool + [ "$ZFSBOOT_BOOT_POOL" ] || return $SUCCESS + + for disk in $disks; do + f_eval_catch $funcname printf "$PRINTF_CONF" \ + geli_%s_keyfile0_load "$disk$targetpart YES" \ + $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || + return $FAILURE + f_eval_catch $funcname printf "$PRINTF_CONF" \ + geli_%s_keyfile0_type \ + "$disk$targetpart $disk$targetpart:geli_keyfile0" \ + $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || + return $FAILURE + f_eval_catch $funcname printf "$PRINTF_CONF" \ + geli_%s_keyfile0_name \ + "$disk$targetpart \"$ZFSBOOT_GELI_KEY_FILE\"" \ + $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || + return $FAILURE + done + + # Set cachefile for boot pool so it auto-imports at system start + f_dprintf "$funcname: Configuring zpool.cache for boot pool..." + f_eval_catch $funcname zpool "$ZPOOL_SET" \ + "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \ + "$bootpool_name" || return $FAILURE + + # Some additional geli(8) requirements for loader.conf(5) + for option in \ + 'zpool_cache_load=\"YES\"' \ + 'zpool_cache_type=\"/boot/zfs/zpool.cache\"' \ + 'zpool_cache_name=\"/boot/zfs/zpool.cache\"' \ + 'geom_eli_passphrase_prompt=\"YES\"' \ + ; do + f_eval_catch $funcname echo "$ECHO_APPEND" "$option" \ + $BSDINSTALL_TMPBOOT/loader.conf.zfs || + return $FAILURE + done + return $SUCCESS +} + +# dialog_menu_diskinfo +# +# Prompt the user to select a disk and then provide detailed info on it. +# +dialog_menu_diskinfo() +{ + local device disk + + # + # Break from loop when user cancels disk selection + # + while :; do + device=$( msg_cancel="$msg_back" f_device_menu \ + "$DIALOG_TITLE" "$msg_select_a_disk_device" "" \ + $DEVICE_TYPE_DISK 2>&1 ) || break + $device get name disk + + # Show gpart(8) `show' and camcontrol(8) `inquiry' data + f_show_msg "$msg_detailed_disk_info" \ + "$disk" "$( gpart show $disk 2> /dev/null )" \ + "$disk" "$( camcontrol inquiry $disk 2> /dev/null )" \ + "$disk" "$( camcontrol identify $disk 2> /dev/null )" + done + + return $SUCCESS +} + +dialog_pool_name() +{ + local prompt="$* is already taken, please enter a name for the ZFS pool \ + (Or confirm using the same name by just pressing enter)" + local hline= + local value="$*" + local height width + + f_dialog_inputbox_size height width \ + "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$prompt" "$value" "$hline" + + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "Ok" \ + --no-cancel \ + --inputbox "$prompt" \ + $height $width "$value" \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD +} + +############################################################ MAIN + +# +# Initialize +# +f_dialog_title "$msg_zfs_configuration" +f_dialog_backtitle "$msg_freebsd_installer" + +# User may have specifically requested ZFS-related operations be interactive +! f_interactive && f_zfsinteractive && unset $VAR_NONINTERACTIVE + +# +# Debugging +# +f_dprintf "BSDINSTALL_CHROOT=[%s]" "$BSDINSTALL_CHROOT" +f_dprintf "BSDINSTALL_TMPETC=[%s]" "$BSDINSTALL_TMPETC" +f_dprintf "FSTAB_FMT=[%s]" "$FSTAB_FMT" + +pools=$(zpool import | awk '$1 == "pool:" { print $2}') +for pool in ${pools}; do + f_dprintf "Checking ${pool} against ${ZFSBOOT_POOL_NAME}" + if [ "${pool}" = "${ZFSBOOT_POOL_NAME}" ]; then + f_dprintf "Pool ${pool} already taken" + ZFSBOOT_POOL_NAME=$(dialog_pool_name "${ZFSBOOT_POOL_NAME}") + break + fi +done + +# +# Determine default boot type +# +case $(uname -m) in +arm64|riscv) + # We support only UEFI boot for arm64 and riscv. + : ${ZFSBOOT_BOOT_TYPE:=UEFI} + : ${ZFSBOOT_PARTITION_SCHEME:=GPT} + ;; +*) + # If the system was booted with UEFI, set the default boot type to UEFI + bootmethod=$( sysctl -n machdep.bootmethod ) + f_dprintf "machdep.bootmethod=[%s]" "$bootmethod" + if [ "$bootmethod" = "UEFI" ]; then + : ${ZFSBOOT_BOOT_TYPE:=BIOS+UEFI} + : ${ZFSBOOT_PARTITION_SCHEME:=GPT} + else + : ${ZFSBOOT_BOOT_TYPE:=BIOS} + : ${ZFSBOOT_PARTITION_SCHEME:=GPT} + fi + ;; +esac + +# +# Loop over the main menu until we've accomplished what we came here to do +# +while :; do + if ! f_interactive; then + retval=$DIALOG_OK + mtag=">>> $msg_install" + else + dialog_menu_main + retval=$? + f_dialog_menutag_fetch mtag + fi + + f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" + [ $retval -eq $DIALOG_OK ] || f_die + + case "$mtag" in + ">>> $msg_install") + # + # First, validate the user's selections + # + + # Make sure they gave us a name for the pool + if [ ! "$ZFSBOOT_POOL_NAME" ]; then + f_dprintf "Pool name cannot be empty." + f_show_err "$msg_pool_name_cannot_be_empty" + continue + fi + + # Validate vdev type against number of disks selected/scripted + # (also validates that ZFSBOOT_DISKS are real [probed] disks) + # NB: dialog_menu_layout supports running non-interactively + dialog_menu_layout || continue + + # Make sure each disk will have room for ZFS + if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize && + f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize && + f_expand_number "1g" zpoolmin + then + minsize=$swapsize teeny_disks= + if [ "$ZFSBOOT_POOL_SIZE" ]; then + f_expand_number "$ZFSBOOT_POOL_SIZE" poolsize + minsize=$(( $minsize + $poolsize )) + fi + [ "$ZFSBOOT_BOOT_POOL" ] && + minsize=$(( $minsize + $bootsize )) + for disk in $ZFSBOOT_DISKS; do + debug= f_device_find -1 \ + $disk $DEVICE_TYPE_DISK device + $device get capacity disksize || continue + [ ${disksize:-0} -ge 0 ] || disksize=0 + [ $disksize -lt $minsize ] && + teeny_disks="$teeny_disks $disk" + done + if [ "$teeny_disks" ]; then + f_dprintf "swapsize=[%s] bootsize[%s] %s" \ + "$ZFSBOOT_SWAP_SIZE" \ + "$ZFSBOOT_BOOT_POOL_SIZE" \ + "minsize=[$minsize]" + f_dprintf "These disks are too small: %s" \ + "$teeny_disks" + f_show_err "$msg_these_disks_are_too_small" \ + "$ZFSBOOT_SWAP_SIZE" \ + "$ZFSBOOT_BOOT_POOL_SIZE" \ + "$teeny_disks" + continue + fi + fi + + # + # Last Chance! + # + if f_interactive; then + dialog_last_chance $ZFSBOOT_DISKS || continue + fi + + # + # Let's do this + # + + vdev_type="$ZFSBOOT_VDEV_TYPE" + + # Blank the vdev type for the default layout + [ "$vdev_type" = "stripe" ] && vdev_type= + + zfs_create_boot "$ZFSBOOT_POOL_NAME" \ + "$vdev_type" $ZFSBOOT_DISKS || continue + + # To be reused by bootconfig + echo "$ZFSBOOT_DISKS" > ${TMPDIR:-"/tmp"}/bsdinstall-zfsboot + + break # to success + ;; + ?" $msg_pool_type_disks") + ZFSBOOT_CONFIRM_LAYOUT=1 + dialog_menu_layout + # User has poked settings, disable later confirmation + ZFSBOOT_CONFIRM_LAYOUT= + ;; + "- $msg_rescan_devices") f_device_rescan ;; + "- $msg_disk_info") dialog_menu_diskinfo ;; + ?" $msg_pool_name") + # Prompt the user to input/change the name for the new pool + f_dialog_input input \ + "$msg_please_enter_a_name_for_your_pool" \ + "$ZFSBOOT_POOL_NAME" && + ZFSBOOT_POOL_NAME="$input" + ;; + ?" $msg_force_4k_sectors") + # Toggle the variable referenced both by the menu and later + if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then + ZFSBOOT_FORCE_4K_SECTORS= + else + ZFSBOOT_FORCE_4K_SECTORS=1 + fi + ;; + ?" $msg_encrypt_disks") + # Toggle the variable referenced both by the menu and later + if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then + ZFSBOOT_GELI_ENCRYPTION= + else + ZFSBOOT_FORCE_4K_SECTORS=1 + ZFSBOOT_GELI_ENCRYPTION=1 + fi + ;; + ?" $msg_partition_scheme") + # Toggle between partition schemes + if [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" -a \ + "$ZFSBOOT_BOOT_TYPE" = "BIOS" ] + then + ZFSBOOT_PARTITION_SCHEME="GPT" + ZFSBOOT_BOOT_TYPE="UEFI" + elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" -a \ + "$ZFSBOOT_BOOT_TYPE" = "UEFI" ] + then + ZFSBOOT_PARTITION_SCHEME="GPT" + ZFSBOOT_BOOT_TYPE="BIOS+UEFI" + elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" ]; then + ZFSBOOT_PARTITION_SCHEME="GPT + Active" + ZFSBOOT_BOOT_TYPE="BIOS" + elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Active" ]; then + ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix" + ZFSBOOT_BOOT_TYPE="BIOS" + else + ZFSBOOT_PARTITION_SCHEME="GPT" + ZFSBOOT_BOOT_TYPE="BIOS" + fi + ;; + ?" $msg_swap_size") + # Prompt the user to input/change the swap size for each disk + while :; do + f_dialog_input input \ + "$msg_please_enter_amount_of_swap_space" \ + "$ZFSBOOT_SWAP_SIZE" && + ZFSBOOT_SWAP_SIZE="${input:-0}" + if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize + then + if [ $swapsize -ne 0 -a $swapsize -lt 104857600 ]; then + f_show_err "$msg_swap_toosmall" \ + "$ZFSBOOT_SWAP_SIZE" + continue + else + break + fi + else + f_show_err "$msg_swap_invalid" \ + "$ZFSBOOT_SWAP_SIZE" + continue + fi + done + ;; + ?" $msg_swap_mirror") + # Toggle the variable referenced both by the menu and later + if [ "$ZFSBOOT_SWAP_MIRROR" ]; then + ZFSBOOT_SWAP_MIRROR= + else + ZFSBOOT_SWAP_MIRROR=1 + fi + ;; + ?" $msg_swap_encrypt") + # Toggle the variable referenced both by the menu and later + if [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then + ZFSBOOT_SWAP_ENCRYPTION= + else + ZFSBOOT_SWAP_ENCRYPTION=1 + fi + ;; + ?" $msg_zfs_options_name") + # Prompt the user to input/change the pool options + f_dialog_input input \ + "$msg_please_enter_options_for_your_pool" \ + "$ZFSBOOT_POOL_CREATE_OPTIONS" && + ZFSBOOT_POOL_CREATE_OPTIONS="$input" + ;; + esac +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ |
