From nobody Mon Apr 28 16:14:07 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ZmT682y9Hz5vXd1; Mon, 28 Apr 2025 16:14:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZmT6773yXz3NMx; Mon, 28 Apr 2025 16:14:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745856848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZrJ+cAgpNwa3mcPGzXEAXJI5LEiFY6/oqVCmmtRho5w=; b=cEE61u4C6xTSwvqTxSfWjK50PWCtDjZ7rUOJFzvlcnJlpQNZ14kgs3B0OPFjzM08oAToMv weAlDlW7bCVS+GnHq4KQtU1SQVymzI/YwId8+rE5n3WA7MCZMxOkcfpO1+VA62bpaiazrI ruGsl9OBSxsWSNfwxzuHsBBk0eskFK5YsDRsnlOZdU26XN2W+E+xcJXH8Ba5TPZtuuJ8fY OEmARi84isSXZRRp80SyG2ZteLDsHv3Tmgqdo8WSwRhjQw1ANjO/2NkbYa7P+JS2gT1jTs 0lNsMakT7/uWs32gGhBSPSnYbAAjZAhsXKv/ipYjYzW8zPrTwAsvTgs9DGH1Lg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745856848; a=rsa-sha256; cv=none; b=Jlhaahhj73b03RbCQLjGv14+eML2SgiZQmtUnTnmcOinvov8IFpCN9XP+/kMUh8xnFcS/0 dLdDdHwm+cf57Yf7qDS1ofnvKgVxxiigclDLxrloFivYSSz5W4nwZ2NiY6jEMMxMyHkRRh Pu5h6LlZxbO1I8qg6Q4kfXd2aBTbR9ZnIAfsad9TmK46t2EEjXtmHstPKInXNsTedOtNcK B9Zfz6RVAbZ95X9yfSdoUp27NAGR3kQwhxg9xtvCx4F2I6sGtVzmRpKfERrkqMEMiAZcmV hmFx3Ww7q+AVD3DOVVgF1WoXsVBjG6diutmvuezWjKyK5GhHmBLCOwa0OL6kBA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745856848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZrJ+cAgpNwa3mcPGzXEAXJI5LEiFY6/oqVCmmtRho5w=; b=VbOdmU8W1BTMHXgPcuOpfh+7lQu8GM0UDIi1eIIGkXPd9pRU7u7MgoTiFdhOElpah+PpiG h/oFkiFdmhQMgJ8RR+SUuiEIzrIJrNRtf4L8GkVTsnEdKWfqviaMxg3TZ+TKJNjfwHkV1m 3b8DIiSBpLt+HOiaGo7dvJoxyw72ZpwBh/1Hx7Y4tYzAfBg3F+rdfyR36NASFBi9LXMg8P qd3udOkUsbBN3cvjmrr3VWEhhMvMcOD7Azae9xswKhb8NNIgG2bEhhJNzf3oMlXrsVTG4/ LwUCVEag6lCZ9rJy9DOfPiQimoTVrMUPxjnfdujMF/YtMbihP5W7gjzuFD9elQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ZmT676TFzzhyb; Mon, 28 Apr 2025 16:14:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53SGE7sq057520; Mon, 28 Apr 2025 16:14:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53SGE7HH057518; Mon, 28 Apr 2025 16:14:07 GMT (envelope-from git) Date: Mon, 28 Apr 2025 16:14:07 GMT Message-Id: <202504281614.53SGE7HH057518@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: ee9cfd727578 - main - bsdinstall: add pkgbase target List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ee9cfd7275784b61b030beb242df588bb35b21f0 Auto-Submitted: auto-generated The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=ee9cfd7275784b61b030beb242df588bb35b21f0 commit ee9cfd7275784b61b030beb242df588bb35b21f0 Author: Isaac Freund AuthorDate: 2025-04-01 23:25:49 +0000 Commit: Ed Maste CommitDate: 2025-04-28 16:12:27 +0000 bsdinstall: add pkgbase target Reviewed by: ziaee (manpages), kevans (lua), emaste Relnotes: Yes Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D49822 --- usr.sbin/bsdinstall/FreeBSD-base.conf.in | 7 ++ usr.sbin/bsdinstall/Makefile | 17 +++ usr.sbin/bsdinstall/bsdinstall.8 | 22 ++++ usr.sbin/bsdinstall/scripts/Makefile | 6 ++ usr.sbin/bsdinstall/scripts/pkgbase.in | 172 +++++++++++++++++++++++++++++++ 5 files changed, 224 insertions(+) diff --git a/usr.sbin/bsdinstall/FreeBSD-base.conf.in b/usr.sbin/bsdinstall/FreeBSD-base.conf.in new file mode 100644 index 000000000000..792c290facdf --- /dev/null +++ b/usr.sbin/bsdinstall/FreeBSD-base.conf.in @@ -0,0 +1,7 @@ +FreeBSD-base: { + url: "pkg+https://pkg.FreeBSD.org/${ABI}/%%SUBURL%%", + mirror_type: "srv", + signature_type: "fingerprints", + fingerprints: "/usr/share/keys/pkg", + enabled: yes +} diff --git a/usr.sbin/bsdinstall/Makefile b/usr.sbin/bsdinstall/Makefile index c9ba7cb52cd6..75db149b814b 100644 --- a/usr.sbin/bsdinstall/Makefile +++ b/usr.sbin/bsdinstall/Makefile @@ -12,4 +12,21 @@ SCRIPTSDIR_startbsdinstall= ${LIBEXECDIR}/bsdinstall UPDATE_DEPENDFILE= no +FILESDIR= ${SHAREDIR}/bsdinstall +FILES= FreeBSD-base.conf + +_BRANCH!= ${MAKE} -C ${SRCTOP}/release -V BRANCH +BRANCH?= ${_BRANCH} +_REVISION!= ${MAKE} -C ${SRCTOP}/release -V REVISION +REVISION?= ${_REVISION} + +.if ${BRANCH} == CURRENT || ${BRANCH} == STABLE +SUBURL= base_latest +.else +SUBURL= base_release_${REVISION:C/[0-9]+\.//} +.endif + +FreeBSD-base.conf: FreeBSD-base.conf.in + sed "s|%%SUBURL%%|${SUBURL}|" < ${.ALLSRC} > ${.TARGET} + .include diff --git a/usr.sbin/bsdinstall/bsdinstall.8 b/usr.sbin/bsdinstall/bsdinstall.8 index 50c8948a7989..8fadacab9189 100644 --- a/usr.sbin/bsdinstall/bsdinstall.8 +++ b/usr.sbin/bsdinstall/bsdinstall.8 @@ -244,6 +244,17 @@ Extracts the distributions listed in .Ev DISTRIBUTIONS into .Ev BSDINSTALL_CHROOT . +.It Cm pkgbase Op Fl --no-kernel +Fetch and install base system packages to +.Ev BSDINSTALL_CHROOT . +Packages are fetched according to repository configuration in +.Ev BSDINSTALL_PKG_REPOS_DIR +if set, or +.Lk pkg.freebsd.org +otherwise. +If the +.Fl --no-kernel +option is passed, no kernel is installed. .It Cm firmware executes .Xr fwget 8 @@ -324,6 +335,17 @@ Example: .Pa https://download.freebsd.org/ftp/releases/powerpc/powerpc64/13.1-RELEASE/ or .Pa http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/amd64/12.2-RELEASE/ . +.It Ev BSDINSTALL_PKG_REPOS_DIR +Directory containing +.Xr pkg 8 +repository configuration files used by the +.Cm pkgbase +target. +See +.Sx REPOSITORY CONFIGURATION +in +.Xr pkg.conf 5 . +Default: unset .It Ev BSDINSTALL_CHROOT The directory into which the distribution files should be unpacked and the directory at which the root file system of the new system should be mounted. diff --git a/usr.sbin/bsdinstall/scripts/Makefile b/usr.sbin/bsdinstall/scripts/Makefile index f3b9f07ed376..4fd59e49d506 100644 --- a/usr.sbin/bsdinstall/scripts/Makefile +++ b/usr.sbin/bsdinstall/scripts/Makefile @@ -1,3 +1,5 @@ +.include + SCRIPTS=auto \ adduser \ bootconfig \ @@ -17,6 +19,7 @@ SCRIPTS=auto \ netconfig \ netconfig_ipv4 \ netconfig_ipv6 \ + pkgbase \ rootpass \ script \ services \ @@ -29,4 +32,7 @@ BINDIR= ${LIBEXECDIR}/bsdinstall MAN= +pkgbase: pkgbase.in + sed "s|%%_ALL_libcompats%%|${_ALL_libcompats}|" < ${.ALLSRC} > ${.TARGET} + .include diff --git a/usr.sbin/bsdinstall/scripts/pkgbase.in b/usr.sbin/bsdinstall/scripts/pkgbase.in new file mode 100755 index 000000000000..7faeee40647b --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/pkgbase.in @@ -0,0 +1,172 @@ +#!/usr/libexec/flua + +-- SPDX-License-Identifier: BSD-2-Clause +-- +-- Copyright(c) 2025 The FreeBSD Foundation. +-- +-- This software was developed by Isaac Freund +-- under sponsorship from the FreeBSD Foundation. + +local all_libcompats = "%%_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 prompt_yn(question) + while true do + io.write(question .. " (y/n) ") + local input = io.read() + if input == "y" or input == "Y" then + return true + elseif input == "n" or input == "N" then + return false + end + end +end + +local function append_list(list, other) + for _, item in ipairs(other) do + table.insert(list, item) + end +end + +-- Returns a list of pkgbase packages equivalent to the default base.txz and kernel.txz +local function select_packages(pkg, options) + local components = { + ["kernel"] = {}, + ["kernel-dbg"] = {}, + ["base"] = {}, + ["base-dbg"] = {}, + ["src"] = {}, + ["tests"] = {}, + } + + for compat in all_libcompats:gmatch("%S+") do + components["lib" .. compat] = {} + components["lib" .. compat .. "-dbg"] = {} + end + + local rquery = capture(pkg .. "rquery -U -r FreeBSD-base %n") + for package in rquery:gmatch("[^\n]+") do + if package == "FreeBSD-src" or package:match("^FreeBSD%-src%-.*") then + table.insert(components["src"], package) + elseif package == "FreeBSD-tests" or package:match("^FreeBSD%-tests%-.*") then + table.insert(components["tests"], package) + elseif package:match("^FreeBSD%-kernel%-.*") then + -- Kernels other than FreeBSD-kernel-generic are ignored + if package == "FreeBSD-kernel-generic" then + table.insert(components["kernel"], package) + elseif package == "FreeBSD-kernel-generic-dbg" then + table.insert(components["kernel-dbg"], package) + end + elseif package:match(".*%-dbg$") then + table.insert(components["base-dbg"], package) + else + local found = false + for compat in all_libcompats:gmatch("%S+") do + if package:match(".*%-dbg%-lib" .. compat .. "$") then + table.insert(components["lib" .. compat .. "-dbg"], package) + found = true + break + elseif package:match(".*%-lib" .. compat .. "$") then + table.insert(components["lib" .. compat], package) + found = true + break + end + end + if not found then + table.insert(components["base"], package) + end + end + end + -- Don't assert the existence of dbg, tests, and src packages here. If using + -- a custom local repository with BSDINSTALL_PKG_REPOS_DIR we shouldn't + -- require it to have all packages. + assert(#components["kernel"] == 1) + assert(#components["base"] > 0) + + local selected = {} + append_list(selected, components["base"]) + if not options.no_kernel then + append_list(selected, components["kernel"]) + end + + return selected +end + +local function parse_options() + local options = {} + for _, a in ipairs(arg) do + if a == "--no-kernel" then + options.no_kernel = 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)) + + local repos_dir = os.getenv("BSDINSTALL_PKG_REPOS_DIR") + if not repos_dir then + repos_dir = chroot .. "/usr/local/etc/pkg/repos/" + assert(os.execute("mkdir -p " .. repos_dir)) + assert(os.execute("cp /usr/share/bsdinstall/FreeBSD-base.conf " .. 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 + print("Canceled") + 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 + print("Canceled") + os.exit(1) + end + end + + if not os.execute(pkg .. "install -U -y -r FreeBSD-base " .. packages) then + os.exit(1) + end +end + +pkgbase()