git: 4db04f5e3a9b - main - nanobsd: Update fill_pkg.sh

From: Jose Luis Duran <jlduran_at_FreeBSD.org>
Date: Sat, 16 Nov 2024 07:23:47 UTC
The branch main has been updated by jlduran:

URL: https://cgit.FreeBSD.org/src/commit/?id=4db04f5e3a9bd927ba1173bf8d3b6a70178eab5f

commit 4db04f5e3a9bd927ba1173bf8d3b6a70178eab5f
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2024-11-12 07:33:12 +0000
Commit:     Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2024-11-16 07:01:27 +0000

    nanobsd: Update fill_pkg.sh
    
    fill_pkg.sh is a script that links a package and its dependencies from a
    "package dump" directory (like /usr/ports/packages/All) to a specified
    directory (NANO_PACKAGE_DIR), for cust_pkgng()[*].
    
    Update the script by:
    
    - Using `make package-name` instead of `make -V pkgname`
    - Looking for package files with *.pkg instead of *.txz
    - Adding a -c option that copies the files instead of linking them[*]
    
    [*] After 9af130ae8c03 cust_pkgng() cannot be used with a directory
    populated by fill_pkg.sh, because it uses a nullfs mount, which doesn't
    follow symlinks, therefore the links inside NANO_PACKAGE_DIR will not
    work.
    
    PR:             269884
    Reviewed by:    imp
    Approved by:    emaste (mentor)
    MFC after:      1 month
    Differential Revision:  https://reviews.freebsd.org/D47531
---
 tools/tools/nanobsd/fill_pkg.sh | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/tools/tools/nanobsd/fill_pkg.sh b/tools/tools/nanobsd/fill_pkg.sh
index 2869122c5fbf..6734498350a9 100644
--- a/tools/tools/nanobsd/fill_pkg.sh
+++ b/tools/tools/nanobsd/fill_pkg.sh
@@ -27,16 +27,16 @@
 #
 #
 # Usage:
-# 	$0 PACKAGE_DUMP NANO_PACKAGE_DIR /usr/ports/foo/bar [package.txz]...
+# 	$0 [-cv] PACKAGE_DUMP NANO_PACKAGE_DIR /usr/ports/foo/bar [package.pkg]...
 #
-# Will symlink the packages listed, including their runtime dependencies,
+# Will symlink/copy the packages listed, including their runtime dependencies,
 # from the PACKAGE_DUMP to the NANO_PACKAGE_DIR.
 #
 
 : ${PORTSDIR:=/usr/ports}
 
 usage () {
-	echo "Usage: $0 [-v] package-dump-dir nano-package-dir port-dir-or-pkg ..." 1>&2
+	echo "Usage: $0 [-cv] package-dump-dir nano-package-dir port-dir-or-pkg ..." 1>&2
 	exit 2
 }
 
@@ -53,29 +53,29 @@ ports_recurse() (
 	for p do
 		if [ -d "$p" -a -f "$p/Makefile" ] ; then
 			msg 3 "$p: full path to port"
-			pkgname=`cd "$p" && make -V pkgname`
+			pkgname=`cd "$p" && make package-name`
 			type=port
 			fullpath=$p
 		elif [ -d "${PORTSDIR}/$p" -a -f "${PORTSDIR}/$p/Makefile" ] ; then
 			msg 3 "$p: path to port relative to ${PORTSDIR}}"
-			pkgname=`cd "${PORTSDIR}/$p" && make -V pkgname`
+			pkgname=`cd "${PORTSDIR}/$p" && make package-name`
 			type=port
 			fullpath=${PORTSDIR}/$p
-		elif [ "${p%.txz}" != "$p" -a -f "$p" ] && pkg info -F "$p" > /dev/null 2>&1 ; then
+		elif [ "${p%.pkg}" != "$p" -a -f "$p" ] && pkg info -F "$p" > /dev/null 2>&1 ; then
 			msg 3 "$p: full package file name"
-			pkgname=`basename "$p" | sed 's/\.txz$//I'`
+			pkgname=`basename "$p" | sed 's/\.pkg$//I'`
 			type=pkg
 			fullpath=$p
-		elif [ "${p%.txz}" != "$p" -a -f "$dumpdir/$p" ] && pkg info -F "$dumpdir/$p" > /dev/null 2>&1 ; then
+		elif [ "${p%.pkg}" != "$p" -a -f "$dumpdir/$p" ] && pkg info -F "$dumpdir/$p" > /dev/null 2>&1 ; then
 			msg 3 "$p: package file name relative to $dumpdir"
-			pkgname=`basename "$p" | sed 's/\.txz$//I'`
+			pkgname=`basename "$p" | sed 's/\.pkg$//I'`
 			type=pkg
 			fullpath=$dumpdir/$p
-		elif [ -f "$dumpdir/$p.txz" ] && pkg info -F "$dumpdir/$p.txz" > /dev/null 2>&1 ; then
+		elif [ -f "$dumpdir/$p.pkg" ] && pkg info -F "$dumpdir/$p.pkg" > /dev/null 2>&1 ; then
 			msg 3 "$p: package name relative to $dumpdir"
 			pkgname=`basename "$p"`
 			type=pkg
-			fullpath=$dumpdir/$p.txz
+			fullpath=$dumpdir/$p.pkg
 		else
 			echo "Missing port or package $p" 1>&2
 			exit 2
@@ -106,7 +106,7 @@ ports_recurse() (
 			fi
 			deps=`pkg info -dF "$fullpath" | grep -v "$pkgname:"`
 			for dep in $deps ; do
-				arg=`echo $dep | sed -e "s|^|$dir|" -e 's/$/.txz/'`
+				arg=`echo $dep | sed -e "s|^|$dir|" -e 's/$/.pkg/'`
 				msg 2 "Check $arg as requirement for package $pkgname"
 				ports_recurse "$outputfile" "$dumpdir" "$arg"
 			done
@@ -116,10 +116,12 @@ ports_recurse() (
 	done
 )
 
+COPY="ln -s"
 VERBOSE=0
 
-while getopts v opt ; do
+while getopts cv opt ; do
 	case "$opt" in
+	  c) COPY="cp -p"              ;;
 	  v) VERBOSE=$(($VERBOSE + 1)) ;;
 	[?]) usage                     ;;
 	esac
@@ -155,8 +157,8 @@ for p do
 done
 
 for i in `cat "$PL"` ; do
-	if [ -f "$NANO_PKG_DUMP/$i.txz" ] ; then
-		ln -s "$NANO_PKG_DUMP/$i.txz" "$NANO_PKG_DIR"
+	if [ -f "$NANO_PKG_DUMP/$i.pkg" ] ; then
+		$COPY "$NANO_PKG_DUMP/$i.pkg" "$NANO_PKG_DIR"
 	else
 		echo "Package $i misssing in $NANO_PKG_DUMP" 1>&2
 		exit 1