Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Jan 2023 19:08:49 +0000
From:      Michael <embhd@posteo.de>
To:        freebsd-embedded@freebsd.org
Subject:   nanoBSD: =?UTF-8?Q?cust=5Fpkgng=28=29=20bootstraps=20pkg=28=38=29?= =?UTF-8?Q?=20regardless=20of=20required=20pkg-X=2EY=2EZ?=
Message-ID:  <447bf50fdf772bc645446bca6d40637f@posteo.de>

index | next in thread | raw e-mail

[-- Attachment #1 --]
Hello,

I noticed that in cust_pkng(), pkg(7) bootstraps to pkg(8) even though 
the function itself requires a pkg-* for bootstrapping. This also seems 
to be the reason why _.cust.cust_pkng notes that "the most recent 
version of pkg-X.Y.Z is already installed" if the function has been run 
with an active internet connection - first, pkg(7) bootstraps to pkg(8), 
which then tries to install pkg(8) once more.
At the same time, I would think that if the nanoBSD-image is for an 
entirely different plattform/architecture, the just bootstrapped pkg(8) 
would not be able to run during operation, since it has been compiled 
for the "host" system.

My current solution is to change the command set in ${PKGCMD} to use the 
host's pkg(8), which chroots itself to ${NANO_WORLDDIR}. This also makes 
the separate calls to chroot(8) by means of CR() and CR0() unnecessary. 
Since the latter does not seem to be used anywhere else and the former 
only once in clean_build(), they can be removed altogether if CR() is 
replaced with a direct call to chroot(8) in clean_build().

Am I missing anything? Otherwise I would go ahead and open a PR.

Regards,
Michael
[-- Attachment #2 --]
diff --git a/tools/tools/nanobsd/defaults.sh b/tools/tools/nanobsd/defaults.sh
index 45d9fe44c650..e5d6cacdb344 100755
--- a/tools/tools/nanobsd/defaults.sh
+++ b/tools/tools/nanobsd/defaults.sh
@@ -277,16 +277,6 @@ tgt_dir2symlink ( ) (
 	fi
 )
 
-# run in the world chroot, errors fatal
-CR ( ) {
-	chroot "${NANO_WORLDDIR}" /bin/sh -exc "$*"
-}
-
-# run in the world chroot, errors not fatal
-CR0 ( ) {
-	chroot "${NANO_WORLDDIR}" /bin/sh -c "$*" || true
-}
-
 clean_build ( ) (
 	pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})"
 
@@ -740,7 +730,7 @@ cust_install_files ( ) (
 	find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)/' | cpio ${CPIO_SYMLINK} -Ldumpv ${NANO_WORLDDIR}
 
 	if [ -n "${NANO_CUST_FILES_MTREE}" -a -f ${NANO_CUST_FILES_MTREE} ]; then
-		CR "mtree -eiU -p /" <${NANO_CUST_FILES_MTREE}
+		chroot "${NANO_WORLDDIR}" /bin/sh -exc "mtree -eiU -p / <${NANO_CUST_FILES_MTREE}"
 	fi
 )
 
@@ -750,7 +740,7 @@ cust_install_files ( ) (
 cust_pkgng ( ) (
 	mkdir -p ${NANO_WORLDDIR}/usr/local/etc
 	local PKG_CONF="${NANO_WORLDDIR}/usr/local/etc/pkg.conf"
-	local PKGCMD="env BATCH=YES ASSUME_ALWAYS_YES=YES PKG_DBDIR=${NANO_PKG_META_BASE}/pkg SIGNATURE_TYPE=none /usr/sbin/pkg"
+	local PKGCMD="env BATCH=YES ASSUME_ALWAYS_YES=YES PKG_DBDIR=${NANO_PKG_META_BASE}/pkg SIGNATURE_TYPE=none pkg -c ${NANO_WORLDDIR}"
 
 	# Ensure pkg.conf points pkg to where the package meta data lives.
 	touch ${PKG_CONF}
@@ -783,7 +773,7 @@ cust_pkgng ( ) (
 	trap "umount ${NANO_WORLDDIR}/dev; umount ${NANO_WORLDDIR}/_.p ; rm -xrf ${NANO_WORLDDIR}/_.p" 1 2 15 EXIT
 
 	# Install pkg-* package
-	CR "${PKGCMD} add /_.p/${_NANO_PKG_PACKAGE}"
+	${PKGCMD} add /_.p/${_NANO_PKG_PACKAGE}
 
 	(
 		# Expand any glob characters in pacakge list
@@ -798,11 +788,11 @@ cust_pkgng ( ) (
 
 		# Install packages
 		for _PKG in $_PKGS; do
-			CR "${PKGCMD} add /_.p/${_PKG}"
+			${PKGCMD} add /_.p/${_PKG}
 		done
 	)
 
-	CR0 "${PKGCMD} info"
+	${PKGCMD} info || true
 
 	trap - 1 2 15 EXIT
 	umount ${NANO_WORLDDIR}/dev
home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?447bf50fdf772bc645446bca6d40637f>