Date: Sun, 24 Oct 2010 22:11:35 +0400 (MSD) From: Lev Serebryakov <lev@FreeBSD.org> To: FreeBSD-gnats-submit@FreeBSD.org Subject: misc/151695: [nanobsd] [patch] Enhance tools/nanobsd/fill_pkg.sh Message-ID: <20101024181135.E40EF13DF46@ftp.translate.ru> Resent-Message-ID: <201010241830.o9OIUBMe019815@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 151695 >Category: misc >Synopsis: [nanobsd] [patch] Enhance tools/nanobsd/fill_pkg.sh >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Oct 24 18:30:11 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Lev Serebryakov >Release: FreeBSD 8.1-STABLE i386 >Organization: >Environment: System: FreeBSD vmware-8-32.home.serebryakov.spb.ru 8.1-STABLE FreeBSD 8.1-STABLE #1: Wed Oct 20 18:55:10 MSD 2010 root@vmware-8-32.home.serebryakov.spb.ru:/usr/obj/usr/src/sys/GENERIC i386 >Description: NanoBSD has helper script "fill_pkg.sh" which links all packages and ther dependencies from "package dump" (like /usr/ports/packages/All) to specified directory. But "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. As changes are massive, I attach new version of script iteslf, not patch/diff output. >How-To-Repeat: >Fix: #!/bin/sh # # Copyright (c) 2010 Lev Serebryakov. # Copyright (c) 2009 Poul-Henning Kamp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: src/tools/tools/nanobsd/fill_pkg.sh,v 1.1.2.1 2009/08/03 08:13:06 kensmith Exp $ # # Usage: # $0 PACKAGE_DUMP NANO_PACKAGE_DIR /usr/ports/foo/bar [package.tbz]... # # Will symlink 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 exit 2 } msg () { local l=$1 shift [ "$l" -le "$VERBOSE" ] && echo $* } ports_recurse() ( local outputfile=$1 shift local dumpdir=$1 shift local type local fullpath 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%.tbz}" != "$p" -a -f "$p" ] && pkg_info "$p" > /dev/null 2>&1 ; then msg 3 "$p: full package file name" PKGNAME=`basename "$p" | sed 's/\.tbz$//I'` type=pkg fullpath=$p elif [ "${p%.tbz}" != "$p" -a -f "$dumpdir/$p" ] && pkg_info "$dumpdir/$p" > /dev/null 2>&1 ; then msg 3 "$p: package file name relative to $dumpdir" PKGNAME=`basename "$p" | sed 's/\.tbz$//I'` type=pkg fullpath=$dumpdir/$p elif [ -f "$dumpdir/$p.tbz" ] && pkg_info "$dumpdir/$p.tbz" > /dev/null 2>&1 ; then msg 3 "$p: package name relative to $dumpdir" PKGNAME=`basename "$p"` type=pkg fullpath=$dumpdir/$p.tbz else echo "Missing port or package $p" 1>&2 exit 2 fi if grep -q "^$PKGNAME\$" "$outputfile" ; then msg 3 "$PKGNAME was added already" true elif [ "$type" = "port" ] ; then ( cd "$fullpath" rd=`make -V RUN_DEPENDS` ld=`make -V LIB_DEPENDS` for dep in $rd $ld do arg=`echo $dep | sed 's/^[^:]*:\([^:]*\).*$/\1/'` msg 2 "Check $arg as requirement for $PKGNAME" ports_recurse "$outputfile" "$dumpdir" "$arg" done ) 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 -r "$fullpath" | grep "Dependency:" | cut -d " " -f 2-` for dep in $deps do arg=`echo $dep | sed -e "s|^|$dir|" -e 's/$/.tbz/'` msg 2 "Check $arg as requirement for $PKGNAME" ports_recurse "$outputfile" "$dumpdir" "$arg" done msg 1 "Add $PKGNAME" echo "$PKGNAME" >> "$outputfile" fi done ) VERBOSE=0 args=`getopt v $*` if [ $? -ne 0 ] ; then usage exit 2 fi set -- $args for i do case "$i" in -v) VERBOSE=$(($VERBOSE + 1)) shift ;; --) shift break esac done NANO_PKG_DUMP=$1 shift; if [ ! -d "$NANO_PKG_DUMP" ] ; then echo "$NANO_PKG_DUMP is not a directory" 1>&2 usage fi NANO_PACKAGE_DIR=$1 shift; if [ -e "$NANO_PKG_DIR" -a ! -d "$NANO_PKG_DIR" ] ; then echo "$NANO_PKG_DIR is not a directory" 1>&2 usage fi case "$NANO_PKG_DIR" in /*) true ;; *) NANO_PKG_DIR=`pwd`/$NANO_PKG_DIR ;; esac rm -rf "$NANO_PACKAGE_DIR" mkdir -p "$NANO_PACKAGE_DIR" PL=$NANO_PACKAGE_DIR/_list true > "$PL" for p do ports_recurse "$PL" "$NANO_PKG_DUMP" "$p" done for i in `cat "$PL"` do if [ -f "$NANO_PKG_DUMP/$i.tbz" ] ; then ln -s "$NANO_PKG_DUMP/$i.tbz" "$NANO_PACKAGE_DIR" else echo "Package $i misssing in $NANO_PKG_DUMP" 1>&2 exit 1 fi done rm -f "$PL" exit 0 >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101024181135.E40EF13DF46>