From owner-dev-commits-src-branches@freebsd.org Fri Jul 16 18:30:48 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 31A11665BFB; Fri, 16 Jul 2021 18:30:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GRKYg4vPbz3vD9; Fri, 16 Jul 2021 18:30:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 75C0721BCB; Fri, 16 Jul 2021 18:30:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 16GIUl6q047475; Fri, 16 Jul 2021 18:30:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16GIUltV047474; Fri, 16 Jul 2021 18:30:47 GMT (envelope-from git) Date: Fri, 16 Jul 2021 18:30:47 GMT Message-Id: <202107161830.16GIUltV047474@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 1405d761ba36 - stable/13 - nanobsd: enhance fill_pkg.sh MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1405d761ba36f6adc59986999befddaf1bedee3f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Jul 2021 18:30:48 -0000 The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=1405d761ba36f6adc59986999befddaf1bedee3f commit 1405d761ba36f6adc59986999befddaf1bedee3f Author: Lev A. Serebryakov AuthorDate: 2021-07-11 15:04:39 +0000 Commit: Warner Losh CommitDate: 2021-07-16 18:28:44 +0000 nanobsd: enhance fill_pkg.sh NanoBSD has helper script "fill_pkg.sh" which links all packages and ther dependencies from "package dump" (like /usr/ports/packages/All) to specified director. fill_pkg.sh has some limitations: 1) It needs ports tree, which should have exactly same versions as "package dump". 2) It requires full paths to needed ports, including "/usr/ports" part. 3) It has assumptions about Nano Package Dir (it assumes, that it specified rtelative to current directory). 4) It does not have any diagnostics (almost). This PR enhances "fill_pkg.sh" script in several ways: 1) Nano package dir could be absolute path. 2) Script understands four ways to specify "root" ports/packages: (a) Absolute directory with port (old one) (b) Relative directory with port, relative to ${PORTSDIR} or /usr/ports (c) Absolute path to file with package (with .tbz suffix) (d) Name of package in dump dir, with or without .tbz suffix These ways can be mixed in one call. Dependencies for packages are obtained with 'pkg_info -r' call, and are searched for in same directory as "parent" package. Dependencies for ports are obtained in old way from port's Makefile. 3) Three levels of diagnostic (and -v option, could be repeated) are added. 4) All path variables are enclosed in quotes, to make script work with paths, containing spaces. Note: imp merged in the changes to fill_pkg.sh since this has been a PR. PR: 151695 Reviewed by: imp@ MFC After: 3 days Differential Revision: https://reviews.freebsd.org/D31101 (cherry picked from commit 36cfb5d50f8e8856695780a6792fb7e81816e9ee) --- tools/tools/nanobsd/fill_pkg.sh | 154 +++++++++++++++++++++++++++++----------- 1 file changed, 113 insertions(+), 41 deletions(-) diff --git a/tools/tools/nanobsd/fill_pkg.sh b/tools/tools/nanobsd/fill_pkg.sh index be240a3bf66f..80f61429ee8f 100644 --- a/tools/tools/nanobsd/fill_pkg.sh +++ b/tools/tools/nanobsd/fill_pkg.sh @@ -1,5 +1,6 @@ #!/bin/sh # +# Copyright (c) 2014 Lev Serebryakov. # Copyright (c) 2009 Poul-Henning Kamp. # All rights reserved. # @@ -27,70 +28,141 @@ # $FreeBSD$ # # Usage: -# $0 PACKAGE_DUMP NANO_PACKAGE_DIR /usr/ports/foo/bar ... +# $0 PACKAGE_DUMP NANO_PACKAGE_DIR /usr/ports/foo/bar [package.txz]... # # Will symlink the packages listed, including their runtime dependencies, # from the PACKAGE_DUMP to the NANO_PACKAGE_DIR. # -NANO_PKG_DUMP=$1 -shift; -if [ ! -d $NANO_PKG_DUMP ] ; then - echo "$NANO_PKG_DUMP not a directory" 1>&2 - exit 1 -fi +: ${PORTSDIR:=/usr/ports} -NANO_PACKAGE_DIR=$1 -shift; +usage () { + echo "Usage: $0 [-v] package-dump-dir nano-package-dir port-dir-or-pkg ..." 1>&2 + exit 2 +} + +msg () { + local l + l=$1 ; shift + [ "$l" -le "$VERBOSE" ] && echo $* +} ports_recurse() ( - of=$1 - shift - for d - do - if [ ! -d $d ] ; then - echo "Missing port $d" 1>&2 + local outputfile dumpdir type fullpath pkgname p + outputfile=$1 ; shift + dumpdir=$1 ; shift + for p do + if [ -d "$p" -a -f "$p/Makefile" ] ; then + msg 3 "$p: full path to port" + pkgname=`cd "$p" && make -V pkgname` + 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` + type=port + fullpath=${PORTSDIR}/$p + elif [ "${p%.txz}" != "$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'` + type=pkg + fullpath=$p + elif [ "${p%.txz}" != "$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'` + type=pkg + fullpath=$dumpdir/$p + elif [ -f "$dumpdir/$p.txz" ] && pkg info -F "$dumpdir/$p.txz" > /dev/null 2>&1 ; then + msg 3 "$p: package name relative to $dumpdir" + pkgname=`basename "$p"` + type=pkg + fullpath=$dumpdir/$p.txz + else + echo "Missing port or package $p" 1>&2 exit 2 fi - if grep -q "^$d\$" $of ; then + if grep -q "^$pkgname\$" "$outputfile" ; then + msg 3 "$pkgname was added already" true - else + elif [ "$type" = "port" ] ; then ( - cd $d - rd=`make -V RUN_DEPENDS ${PORTS_OPTS}` - ld=`make -V LIB_DEPENDS ${PORTS_OPTS}` - - for x in $rd $ld - do - ports_recurse $of `echo $x | - sed 's/^[^:]*:\([^:]*\).*$/\1/'` - done + cd "$fullpath" + rd=`make -V RUN_DEPENDS ${PORTS_OPTS}` + ld=`make -V LIB_DEPENDS ${PORTS_OPTS}` + + for dep in $rd $ld ; do + arg=`echo $dep | sed 's/^[^:]*:\([^:]*\).*$/\1/'` + msg 2 "Check $arg as requirement for port $pkgname" + ports_recurse "$outputfile" "$dumpdir" "$arg" + done ) - echo $d >> $of + msg 1 "Add $pkgname" + echo "$pkgname" >> "$outputfile" + else + dir=`dirname "$p"` # Get directory from SPECIFIED path, not from full path + if [ "$dir" = "." ] ; then + dir="" + else + dir=${dir}/ + fi + deps=`pkg info -dF "$fullpath" | grep -v "$pkgname:"` + for dep in $deps ; do + arg=`echo $dep | sed -e "s|^|$dir|" -e 's/$/.txz/'` + msg 2 "Check $arg as requirement for package $pkgname" + ports_recurse "$outputfile" "$dumpdir" "$arg" + done + msg 1 "Add $pkgname" + echo "$pkgname" >> "$outputfile" fi done ) -rm -rf $NANO_PACKAGE_DIR -mkdir -p $NANO_PACKAGE_DIR +VERBOSE=0 + +while getopts v opt ; do + case "$opt" in + v) VERBOSE=$(($VERBOSE + 1)) ;; + [?]) usage ;; + esac +done +shift $(( ${OPTIND} - 1 )) + +if [ "$#" -lt 3 ] ; then + usage +fi + +NANO_PKG_DUMP=`realpath $1` +shift; +if [ ! -d "$NANO_PKG_DUMP" ] ; then + echo "$NANO_PKG_DUMP is not a directory" 1>&2 + usage +fi + +NANO_PKG_DIR=`realpath $1` +shift; +if [ ! -d "$NANO_PKG_DIR" ] ; then + echo "$NANO_PKG_DIR is not a directory" 1>&2 + usage +fi + +# Cleanup +rm -rf "$NANO_PKG_DIR/"* + +PL=$NANO_PKG_DIR/_list +true > "$PL" -PL=$NANO_PACKAGE_DIR/_list -true > $PL -for i -do - ports_recurse `pwd`/$PL $i +for p do + ports_recurse "$PL" "$NANO_PKG_DUMP" "$p" done -for i in `cat $PL` -do - p=`(cd $i && make -V PKGNAME)` - if [ -f $NANO_PKG_DUMP/$p.t[bx]z ] ; then - ln -s $NANO_PKG_DUMP/$p.t[bx]z $NANO_PACKAGE_DIR +for i in `cat "$PL"` ; do + if [ -f "$NANO_PKG_DUMP/$i.txz" ] ; then + ln -s "$NANO_PKG_DUMP/$i.txz" "$NANO_PKG_DIR" else - echo "Package $p misssing in $NANO_PKG_DUMP" 1>&2 + echo "Package $i misssing in $NANO_PKG_DUMP" 1>&2 exit 1 fi done -rm -f $PL +rm -f "$PL" exit 0