git: dc14ae4217a0 - main - bsdinstall: do pkgbase installations with the "script" command

From: Alan Somers <asomers_at_FreeBSD.org>
Date: Tue, 12 May 2026 14:13:55 UTC
The branch main has been updated by asomers:

URL: https://cgit.FreeBSD.org/src/commit/?id=dc14ae4217a0babb1240f813b642edc2d7b955a6

commit dc14ae4217a0babb1240f813b642edc2d7b955a6
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2026-04-28 17:27:17 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2026-05-12 14:13:16 +0000

    bsdinstall: do pkgbase installations with the "script" command
    
    "bsdinstall script" will now do a pkgbase installation by default.  The
    system components to install can be specified in the COMPONENTS
    variable, and have the same names as those used in the interactive
    installer.  bsdinstall will still do a legacy distset installation if
    DISTRIBUTIONS is defined in the installerconfig file.
    
    MFC:            1 week
    PR:             290375
    Sponsored by:   ConnectWise
    Reviewed by:    ziaee, ivy, jduran
    Differential Revision: https://reviews.freebsd.org/D56717
---
 UPDATING                               |  5 +++
 usr.sbin/bsdinstall/bsdinstall.8       | 45 ++++++++++++++++-----
 usr.sbin/bsdinstall/scripts/pkgbase.in | 15 ++++++-
 usr.sbin/bsdinstall/scripts/script     | 71 ++++++++++++++++++++--------------
 4 files changed, 95 insertions(+), 41 deletions(-)

diff --git a/UPDATING b/UPDATING
index c60143c6184e..58d12856c581 100644
--- a/UPDATING
+++ b/UPDATING
@@ -27,6 +27,11 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 16.x IS SLOW:
 	world, or to merely disable the most expensive debugging functionality
 	at runtime, run "ln -s 'abort:false,junk:false' /etc/malloc.conf".)
 
+20260512:
+	"bsdinstall script" will now do a pkgbase installation by default.  To
+	revert to the legacy distset installation, set "DISTRIBUTIONS" in
+	your installerconfig.
+
 20260412:
 	The /etc/rc.d/NETWORKING script no longer provides the legacy
 	NETWORK alias. Third-party or local RC scripts that still use
diff --git a/usr.sbin/bsdinstall/bsdinstall.8 b/usr.sbin/bsdinstall/bsdinstall.8
index 282b88328e99..a35c8f56ada7 100644
--- a/usr.sbin/bsdinstall/bsdinstall.8
+++ b/usr.sbin/bsdinstall/bsdinstall.8
@@ -29,7 +29,7 @@
 .\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 20, 2026
+.Dd May 12, 2026
 .Dt BSDINSTALL 8
 .Os
 .Sh NAME
@@ -109,9 +109,12 @@ for more information on this target.
 .Pp
 The
 .Ev DISTRIBUTIONS
-environment variable is set to
-.Dq base.txz kernel.txz
-by default for this target.
+environment variable is unset by default for this target.
+Instead, the
+.Ev COMPONENTS
+environment variable is effectively set to
+.Dq base kernel kernel-dbg
+for this target.
 .It Cm keymap
 If the current controlling TTY is a
 .Xr syscons 4
@@ -321,8 +324,17 @@ overridden when making scripted or customized installers.
 The directory to use for temporary files.
 Default:
 .Dq Pa /tmp
+.It Ev COMPONENTS
+The set of components to install for scripted installations using
+base system packages, e.g.,
+.Dq base lib32 kernel-dbg tests .
+Default: "base kernel-dbg"
 .It Ev DISTRIBUTIONS
-The set of distributions to install, e.g., "base.txz kernel.txz ports.txz".
+The set of distributions to install for traditional installations, e.g.,
+.Dq base.txz kernel.txz ports.txz .
+If unset, then
+.Nm
+will install using base system packages.
 Default: unset unless noted otherwise in the
 .Sx TARGETS
 section.
@@ -609,18 +621,18 @@ A typical bsdinstall script, using the default filesystem layout and the UFS
 filesystem, looks like this:
 .Bd -literal -offset indent
 PARTITIONS=DEFAULT
-DISTRIBUTIONS="kernel.txz base.txz"
+COMPONENTS="base debug"
 
 #!/bin/sh
 sysrc ifconfig_DEFAULT=DHCP
 sysrc sshd_enable=YES
-pkg install puppet
+pkg install -y puppet
 .Ed
 .Pp
 For a scripted installation involving a ZFS pool spanning multiple disks,
 the script instead looks like this:
 .Bd -literal -offset indent
-DISTRIBUTIONS="kernel.txz base.txz"
+COMPONENTS="base debug"
 export ZFSBOOT_VDEV_TYPE=stripe
 export ZFSBOOT_DISKS="ada0 ada1"
 export nonInteractive="YES"
@@ -628,7 +640,20 @@ export nonInteractive="YES"
 #!/bin/sh
 echo "ifconfig_DEFAULT=DHCP" >> /etc/rc.conf
 echo "sshd_enable=YES" >> /etc/rc.conf
-pkg install puppet
+pkg install -y puppet
+.Ed
+.Pp
+To install using traditional distributions sets instead of packages, set
+.Ev DISTRIBUTIONS
+to the list of distribution sets to install, like this:
+.Bd -literal -offset indent
+PARTITIONS=DEFAULT
+DISTRIBUTIONS="kernel.txz base.txz"
+
+#!/bin/sh
+sysrc ifconfig_DEFAULT=DHCP
+sysrc sshd_enable=YES
+pkg install -y puppet
 .Ed
 .Pp
 On
@@ -653,7 +678,7 @@ arbitrary commands can be run here to extend the installer.
 In addition to the variables in
 .Sx ENVIRONMENT VARIABLES ,
 in particular
-.Ev DISTRIBUTIONS ,
+.Ev COMPONENTS ,
 the preamble can contain a variable
 .Ev PARTITIONS
 which is passed to the
diff --git a/usr.sbin/bsdinstall/scripts/pkgbase.in b/usr.sbin/bsdinstall/scripts/pkgbase.in
index 89ddc244171e..2c7d6bcae904 100755
--- a/usr.sbin/bsdinstall/scripts/pkgbase.in
+++ b/usr.sbin/bsdinstall/scripts/pkgbase.in
@@ -180,7 +180,18 @@ local function select_components(components, options)
 	}
 	append_list(bsddialog_args, checklist_items)
 
-	local exit_code, output = bsddialog(bsddialog_args)
+	local exit_code = 0
+	local output = ""
+	if options.non_interactive then
+		local env_components = os.getenv("COMPONENTS")
+		if env_components then
+			output = env_components:gsub(" ", "\n")
+		else
+			output = "base\nkernel-dbg"
+		end
+	else
+		exit_code, output = bsddialog(bsddialog_args)
+	end
 	-- 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
@@ -300,6 +311,8 @@ local function parse_options()
 	for _, a in ipairs(arg) do
 		if a == "--jail" then
 			options.jail = true
+		elseif a == "--non-interactive" then
+			options.non_interactive = true
 		else
 			io.stderr:write("Error: unknown option " .. a .. "\n")
 			os.exit(1)
diff --git a/usr.sbin/bsdinstall/scripts/script b/usr.sbin/bsdinstall/scripts/script
index 21da2ea7c366..93d07c7899c3 100755
--- a/usr.sbin/bsdinstall/scripts/script
+++ b/usr.sbin/bsdinstall/scripts/script
@@ -40,6 +40,7 @@ f_include $BSDCFG_SHARE/variable.subr
 # PARTITIONS
 # DISTRIBUTIONS
 # BSDINSTALL_DISTDIR
+# COMPONENTS
 
 #
 # Default name of the ZFS boot-pool
@@ -97,7 +98,6 @@ awk 'BEGIN {pathb=ARGV[2]; ARGV[2]=""} /^#!/{b=1} {
     >$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
@@ -118,37 +118,48 @@ else
 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>&-
+if [ -n "$COMPONENTS" -a -n "$DISTRIBUTIONS" ]; then
+	error "Cannot set both COMPONENTS and DISTRIBUTIONS"
+elif [ -z "$DISTRIBUTIONS" ]; then
+	# If COMPONENTS is set, or neither is, install with pkgbase
+	bsdinstall pkgbase --non-interactive
+else
+	# Otherwise, unpack distsets
 
-[ $FETCH_RESULT -ne 0 ] && error "Could not fetch remote distributions"
+	# Fetch missing distribution files, if any
+	exec 5>&1
+	export BSDINSTALL_DISTDIR=$(`dirname $0`/fetchmissingdists 2>&1 1>&5)
+	FETCH_RESULT=$?
+	exec 5>&-
 
-# 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
+	[ $FETCH_RESULT -ne 0 ] && error "Could not fetch remote 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
 fi
 
 # Configure bootloader if needed