Path: blob/main/release/scripts/pkgbase-stage.lua
101566 views
#!/usr/libexec/flua12-- SPDX-License-Identifier: BSD-2-Clause3--4-- Copyright(c) 2025 The FreeBSD Foundation.5--6-- This software was developed by Isaac Freund <[email protected]>7-- under sponsorship from the FreeBSD Foundation.89-- Run a command using the OS shell and capture the stdout10-- Strips exactly one trailing newline if present, does not strip any other whitespace.11-- Asserts that the command exits cleanly12local function capture(command)13local p = io.popen(command)14local output = p:read("*a")15assert(p:close())16-- Strip exactly one trailing newline from the output, if there is one17return output:match("(.-)\n$") or output18end1920-- Returns a list of packages to be included in the given media21local function select_packages(pkg, media, all_libcompats)22-- Note: if you update this list, you must also update the list in23-- usr.sbin/bsdinstall/scripts/pkgbase.in.24local kernel_packages = {25-- Most architectures use this26["FreeBSD-kernel-generic"] = true,27-- PowerPC uses either of these, depending on platform28["FreeBSD-kernel-generic64"] = true,29["FreeBSD-kernel-generic64le"] = true,30}3132local components = {}33local rquery = capture(pkg .. "rquery -U -r FreeBSD-base %n")34for package in rquery:gmatch("[^\n]+") do35local set = package:match("^FreeBSD%-set%-(.*)$")36if set then37components[set] = package38elseif kernel_packages[package] then39components["kernel"] = package40elseif kernel_packages[package:match("(.*)%-dbg$")] then41components["kernel-dbg"] = package42elseif package == "pkg" then43components["pkg"] = package44end45end46assert(components["kernel"])47assert(components["base"])48assert(components["pkg"])4950local selected = {}51if media == "disc" then52table.insert(selected, components["pkg"])53table.insert(selected, components["base"])54table.insert(selected, components["base-jail"])55table.insert(selected, components["kernel"])56table.insert(selected, components["kernel-dbg"])57table.insert(selected, components["src"])58table.insert(selected, components["tests"])59for compat in all_libcompats:gmatch("%S+") do60table.insert(selected, components["lib" .. compat])61end62else63assert(media == "dvd")64table.insert(selected, components["pkg"])65table.insert(selected, components["base"])66table.insert(selected, components["base-dbg"])67table.insert(selected, components["base-jail"])68table.insert(selected, components["base-jail-dbg"])69table.insert(selected, components["kernel"])70table.insert(selected, components["kernel-dbg"])71table.insert(selected, components["src"])72table.insert(selected, components["tests"])73for compat in all_libcompats:gmatch("%S+") do74table.insert(selected, components["lib" .. compat])75table.insert(selected, components["lib" .. compat .. "-dbg"])76end77end7879return selected80end8182local function main()83-- Determines package subset selected84local media = assert(arg[1])85assert(media == "disc" or media == "dvd")86-- Directory containing FreeBSD-base repository config87local repo_dir = assert(arg[2])88-- Directory to create new repository89local target = assert(arg[3])90-- Whitespace separated list of all libcompat names (e.g. "32")91local all_libcompats = assert(arg[4])92-- ABI of repository93local ABI = assert(arg[5])94-- pkgdb to use95local PKGDB = assert(arg[6])9697local pkg = "pkg -o ASSUME_ALWAYS_YES=yes -o IGNORE_OSVERSION=yes " ..98"-o ABI=" .. ABI .. " " ..99"-o INSTALL_AS_USER=1 -o PKG_DBDIR=" .. PKGDB .. " -R " .. repo_dir .. " "100101assert(os.execute(pkg .. "update"))102103local packages = select_packages(pkg, media, all_libcompats)104105assert(os.execute(pkg .. "fetch -d -o " .. target .. " " .. table.concat(packages, " ")))106assert(os.execute(pkg .. "repo " .. target))107end108109main()110111112