Lines Matching +full:local +full:- +full:pid
3 -- SPDX-License-Identifier: BSD-2-Clause
4 --
5 -- Copyright(c) 2025 The FreeBSD Foundation.
6 --
7 -- This software was developed by Isaac Freund <ifreund@freebsdfoundation.org>
8 -- under sponsorship from the FreeBSD Foundation.
10 local sys_wait = require("posix.sys.wait")
11 local unistd = require("posix.unistd")
13 local all_libcompats <const> = "%%_ALL_libcompats%%"
15 -- Run a command using the OS shell and capture the stdout
16 -- Strips exactly one trailing newline if present, does not strip any other whitespace.
17 -- Asserts that the command exits cleanly
18 local function capture(command)
19 local p = io.popen(command)
20 local output = p:read("*a")
22 -- Strip exactly one trailing newline from the output, if there is one
23 return output:match("(.-)\n$") or output
26 local function append_list(list, other)
32 -- Read from the given fd until EOF
33 -- Returns all the data read as a single string
34 local function read_all(fd)
35 local ret = ""
37 local buffer = assert(unistd.read(fd, 1024))
43 -- Run bsddialog with the given argument list
44 -- Returns the exit code and stderr output of bsddialog
45 local function bsddialog(args)
46 local r, w = assert(unistd.pipe())
48 local pid = assert(unistd.fork())
49 if pid == 0 then
57 local output = read_all(r)
60 local _, _, exit_code = assert(sys_wait.wait(pid))
64 -- Prompts the user for a yes/no answer to the given question using bsddialog
65 -- Returns true if the user answers yes and false if the user answers no.
66 local function prompt_yn(question)
67 local exit_code = bsddialog({
68 "--yesno",
69 "--disable-esc",
71 0, 0, -- autosize
76 -- Creates a dialog for component selection mirroring the
77 -- traditional tarball component selection dialog.
78 local function select_components(components, options)
79 local descriptions = {
84 lib32 = "32-bit compatibility libraries",
85 lib32_dbg = "32-bit compatibility libraries debug info",
87 local defaults = {
96 -- Sorting the components is necessary to ensure that the ordering is
97 -- consistent in the UI.
98 local sorted_components = {}
104 local checklist_items = {}
109 local description = descriptions[component] or "''"
110 local default = defaults[component] or "off"
117 local bsddialog_args = {
118 "--backtitle", "FreeBSD Installer",
119 "--title", "Select System Components",
120 "--nocancel",
121 "--disable-esc",
122 "--separate-output",
123 "--checklist", "Choose optional system components to install:",
124 "0", "0", "0", -- autosize
128 local exit_code, output = bsddialog(bsddialog_args)
129 -- This should only be possible if bsddialog is killed by a signal
130 -- or buggy, we disable the cancel option and esc key.
131 -- If this does happen, there's not much we can do except exit with a
132 -- hopefully useful stack trace.
135 local selected = {"base"}
146 -- Returns a list of pkgbase packages selected by the user
147 local function select_packages(pkg, options)
148 local components = {
162 local rquery = capture(pkg .. "rquery -U -r FreeBSD-base %n")
164 if package == "FreeBSD-src" or package:match("^FreeBSD%-src%-.*") then
166 elseif package == "FreeBSD-tests" or package:match("^FreeBSD%-tests%-.*") then
168 elseif package:match("^FreeBSD%-kernel%-.*") then
169 -- Kernels other than FreeBSD-kernel-generic are ignored
170 if package == "FreeBSD-kernel-generic" then
172 elseif package == "FreeBSD-kernel-generic-dbg" then
175 elseif package:match(".*%-dbg$") then
178 local found = false
180 if package:match(".*%-dbg%-lib" .. compat .. "$") then
184 elseif package:match(".*%-lib" .. compat .. "$") then
195 -- Don't assert the existence of dbg, tests, and src packages here. If using
196 -- a custom local repository with BSDINSTALL_PKG_REPOS_DIR we shouldn't
197 -- require it to have all packages.
201 local selected = {}
209 local function parse_options()
210 local options = {}
212 if a == "--no-kernel" then
222 -- Fetch and install pkgbase packages to BSDINSTALL_CHROOT.
223 -- Respect BSDINSTALL_PKG_REPOS_DIR if set, otherwise use pkg.freebsd.org.
224 local function pkgbase()
225 local options = parse_options()
227 -- TODO Support fully offline pkgbase installation by taking a new enough
228 -- version of pkg.pkg as input.
229 if not os.execute("pkg -N > /dev/null 2>&1") then
231 assert(os.execute("pkg bootstrap -y"))
234 local chroot = assert(os.getenv("BSDINSTALL_CHROOT"))
235 assert(os.execute("mkdir -p " .. chroot))
237 local repos_dir = os.getenv("BSDINSTALL_PKG_REPOS_DIR")
239 repos_dir = chroot .. "/usr/local/etc/pkg/repos/"
240 assert(os.execute("mkdir -p " .. repos_dir))
241 assert(os.execute("cp /usr/share/bsdinstall/FreeBSD-base.conf " .. repos_dir))
243 -- Since pkg always interprets fingerprints paths as relative to
244 -- the --rootdir we must copy the key from the host.
245 assert(os.execute("mkdir -p " .. chroot .. "/usr/share/keys"))
246 assert(os.execute("cp -R /usr/share/keys/pkg " .. chroot .. "/usr/share/keys/"))
249 -- We must use --repo-conf-dir rather than -o REPOS_DIR here as the latter
250 -- is interpreted relative to the --rootdir. BSDINSTALL_PKG_REPOS_DIR must
251 -- be allowed to point to a path outside the chroot.
252 local pkg = "pkg --rootdir " .. chroot ..
253 " --repo-conf-dir " .. repos_dir .. " -o IGNORE_OSVERSION=yes "
261 local packages = table.concat(select_packages(pkg, options), " ")
263 while not os.execute(pkg .. "install -U -F -y -r FreeBSD-base " .. packages) do
269 if not os.execute(pkg .. "install -U -y -r FreeBSD-base " .. packages) then