pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pkg/59970: pkg_install: top-sort packages and/or (de)install scripts



>Number:         59970
>Category:       pkg
>Synopsis:       pkg_install: top-sort packages and/or (de)install scripts
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 07 19:40:01 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
The NetBSD Inc.stallation
>Environment:
>Description:

	I would like to cross-build an application image that can be
	shipped off to a utility computing service to run.

	The application image needs some packages installed, which I
	can cross-build with pkgsrc, perhaps via build.sh pkg=cat/foo.

	I can install the packages into the image with
	src/distrib/utils/embedded/mkimage using

		pkg_add -I -P "$mnt" foo

	with `-I' to suppress running the installation script.

	Of course, on first boot, I will have to run the installation
	scripts.  How do I do that?

	I can top-sort the packages, and print their install scripts to
	run manually:


		pkg_info -a \
		| awk '{
			pkg = $1
			pipe = "pkg_info -qR " pkg
			while (pipe | getline) {
				if (NF > 0)
					print pkg, $1
			}
			close(pipe)
		' \
		| tsort \
		| while read pkg; do
			pkg_info -i "$pkg" | sh
		done

	That's rather slow to list the dependency graph for tsort(1); a
	much faster approach -- if much uglier and brittler -- is to
	parse the full output of pkg_info -aR:

		pkg_info -aR \
		| awk '
			/^Information for .*:/ {
				sub(/.* /, "", $0)
				sub(/:$/, "", $0)
				pkg = $0
				next
			}
			!/^$/ && !/^Required by:/ && !/MAY NOT BE DELETED/ {
				print pkg, $0
			}
		' \
		| tsort \
		| while read pkg; do
			pkg_info -i "$pkg" | sh
		done

	I suggest pkg_info should have an option to print packages in
	topological order -- or, perhaps, two options, one for
	dependencies first and the other for dependents first.

	Alternatively, it would be nice if pkg_add(1) could run any
	install scripts that haven't yet been run, in the right order.
	It would also be nice if pkg_add(1) and pkg_delete(1)
	maintained a simple intent log of actions to be taken, like
	finishing an interrupted package deletion before trying to add
	a new package, or running installation scripts that haven't yet
	been run.

	It would also be nice if it were documented somewhere, and
	audited, that (de)install scripts must be idempotent, so it is
	safe to rerun them if the process is interrupted partway
	through.

>How-To-Repeat:

	Try to cross-build and ship an application image without
	relying on booting a VM to do everything.

>Fix:

	Yes, please!



Home | Main Index | Thread Index | Old Index