pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkg_tarup Update pkg_tarup to 1.6.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/0d964bf45400
branches:  trunk
changeset: 478013:0d964bf45400
user:      erh <erh%pkgsrc.org@localhost>
date:      Wed Jul 14 16:08:48 2004 +0000

description:
Update pkg_tarup to 1.6.
Add several command line options to control how and where pkg_tarup creates
 packages.  pkg_tarup is now functional enough that pkg_tarup_all just runs it.
Add various bits of quoting to make packages that contain filenames with
 spaces more likely to work.
Add a man page.

diffstat:

 pkgtools/pkg_tarup/Makefile            |   12 +-
 pkgtools/pkg_tarup/PLIST               |    3 +-
 pkgtools/pkg_tarup/files/pkg_tarup     |  157 +++++++++++++++++++++++---------
 pkgtools/pkg_tarup/files/pkg_tarup.1   |  109 ++++++++++++++++++++++
 pkgtools/pkg_tarup/files/pkg_tarup_all |   30 +-----
 5 files changed, 234 insertions(+), 77 deletions(-)

diffs (truncated from 440 to 300 lines):

diff -r 2b3fc2ec0f36 -r 0d964bf45400 pkgtools/pkg_tarup/Makefile
--- a/pkgtools/pkg_tarup/Makefile       Wed Jul 14 15:19:19 2004 +0000
+++ b/pkgtools/pkg_tarup/Makefile       Wed Jul 14 16:08:48 2004 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.19 2004/04/20 16:26:07 wiz Exp $
+# $NetBSD: Makefile,v 1.20 2004/07/14 16:08:48 erh Exp $
 
-DISTNAME=      pkg_tarup-1.5.2
+DISTNAME=      pkg_tarup-1.6
 CATEGORIES=    pkgtools
 MASTER_SITES=  # empty
 DISTFILES=     # empty
@@ -15,14 +15,16 @@
 NO_MTREE=      yes
 
 # Set SCRIPT_SUBST to substitute "@VARIABLE@" with "value"
-SCRIPT_SUBST+= AWK=${AWK:Q}                            \
+SCRIPT_SUBST+= \
                ECHO=${ECHO:Q}                          \
+               GREP=${GREP:Q}                          \
                HEAD=${HEAD:Q}                          \
                ID=${ID:Q}                              \
                PKG_DBDIR=${PKG_DBDIR:Q}                \
                PKG_SUFX=${PKG_SUFX:Q}                  \
                PREFIX=${PREFIX:Q}                      \
                PKG_TOOLS_BIN=${PKG_TOOLS_BIN:Q}        \
+               SED=${SED:Q}                    \
                SH=${SH:Q}                              \
                SU=${SU:Q}
 
@@ -37,9 +39,13 @@
        ${SED} ${SCRIPT_SUBST_SED}                      \
                        < ${FILESDIR}/pkg_tarup_all     \
                        > ${WRKSRC}/pkg_tarup_all
+       ${SED} ${SCRIPT_SUBST_SED}                      \
+                       < ${FILESDIR}/pkg_tarup.1   \
+                       > ${WRKSRC}/pkg_tarup.1
 
 do-install:
        ${INSTALL_SCRIPT} ${WRKSRC}/pkg_tarup ${PREFIX}/bin
        ${INSTALL_SCRIPT} ${WRKSRC}/pkg_tarup_all ${PREFIX}/bin
+       ${INSTALL_MAN} ${WRKSRC}/pkg_tarup.1 ${PREFIX}/man/man1
 
 .include "../../mk/bsd.pkg.mk"
diff -r 2b3fc2ec0f36 -r 0d964bf45400 pkgtools/pkg_tarup/PLIST
--- a/pkgtools/pkg_tarup/PLIST  Wed Jul 14 15:19:19 2004 +0000
+++ b/pkgtools/pkg_tarup/PLIST  Wed Jul 14 16:08:48 2004 +0000
@@ -1,3 +1,4 @@
-@comment $NetBSD: PLIST,v 1.2 2003/05/28 14:53:43 hubertf Exp $
+@comment $NetBSD: PLIST,v 1.3 2004/07/14 16:08:48 erh Exp $
 bin/pkg_tarup
 bin/pkg_tarup_all
+man/man1/pkg_tarup.1
diff -r 2b3fc2ec0f36 -r 0d964bf45400 pkgtools/pkg_tarup/files/pkg_tarup
--- a/pkgtools/pkg_tarup/files/pkg_tarup        Wed Jul 14 15:19:19 2004 +0000
+++ b/pkgtools/pkg_tarup/files/pkg_tarup        Wed Jul 14 16:08:48 2004 +0000
@@ -1,6 +1,6 @@
 #! @SH@
 #
-# $Id: pkg_tarup,v 1.12 2004/04/20 16:26:07 wiz Exp $
+# $Id: pkg_tarup,v 1.13 2004/07/14 16:08:48 erh Exp $
 #
 # Tar up installed package
 #
@@ -16,16 +16,17 @@
 
 OS=`uname -s`
 
-AWK=${AWK:-@AWK@}
 ECHO=${ECHO:-@ECHO@}
 HEAD=${HEAD:-@HEAD@}
 ID=${ID:-@ID@}
+SED=${SED:-@SED@}
 SU=${SU:-@SU@}
+GREP=${GREP:-@GREP@}
 
 if [ `${ID} -u` != 0 ]; then
        ${ECHO} "Becoming root@`/bin/hostname` to create a binary package"
-       ${ECHO} -n "`${ECHO} ${SU} | ${AWK} '{ print $1 }'` ";\
-       exec ${SU} root -c "$0 $@"
+       ${ECHO} -n "`${ECHO} ${SU} | ${SED} -e's/[[:space:]].*//'` ";\
+       exec ${SU} root -c "$0 \"\$@\"" "$0" "$@"
 fi
 
 PKG_DBDIR=${PKG_DBDIR:-@PKG_DBDIR@}
@@ -33,9 +34,20 @@
 
 PKGREPOSITORY=${PKGREPOSITORY:-/tmp}
 
+# XXX Force pkg_info to ignore .tgz files.
+export PKG_PATH=
+
+# Set to 1 if we also want to tar up dependencies also
+GETDEPS=0
+
 usage()
 {
-       ${ECHO} "Usage: $1 installed_pkg|pattern [...]"
+       ${ECHO} "Usage: $1 [-a] [-K pkg_dbdir] [-d pkgrepository] [-s pkg_sufx] installed_pkg|pattern [...]"
+       ${ECHO} "The following environment variables are used:"
+       ${ECHO} " (unless overriden by command line parameters)"
+       ${ECHO} " PKGREPOSITORY - A destination directory for packages (/tmp)"
+       ${ECHO} " PKG_DBDIR     - The location of the package database directory"
+       ${ECHO} " PKG_SUFX      - The suffix to append to the package (.tgz)"
        exit 1
 }
 
@@ -51,7 +63,7 @@
 
        if [ -f "$file" ]
        then
-           PKG_ARGS="${PKG_ARGS} ${opt} ${file}"
+           PKG_ARGS="${PKG_ARGS} \"${opt}\" \"${file}\""
        fi
 }
 
@@ -61,35 +73,35 @@
        PKG_ARGS=
        ${ECHO} "Creating binary package: $PKG"
 
-       check_and_add -c ${PKG_DBDIR}/${PKG}/+COMMENT
-       check_and_add -d ${PKG_DBDIR}/${PKG}/+DESC
-       check_and_add -b ${PKG_DBDIR}/${PKG}/+BUILD_VERSION
-       check_and_add -B ${PKG_DBDIR}/${PKG}/+BUILD_INFO
-       check_and_add -s ${PKG_DBDIR}/${PKG}/+SIZE_PKG
-       check_and_add -S ${PKG_DBDIR}/${PKG}/+SIZE_ALL
-       check_and_add -i ${PKG_DBDIR}/${PKG}/+INSTALL
-       check_and_add -k ${PKG_DBDIR}/${PKG}/+DEINSTALL
-       check_and_add -r ${PKG_DBDIR}/${PKG}/+REQUIRE
-       check_and_add -D ${PKG_DBDIR}/${PKG}/+DISPLAY
-       check_and_add -m ${PKG_DBDIR}/${PKG}/+MTREE             #NOTYET#
+       check_and_add -c "${PKG_DBDIR}/${PKG}/+COMMENT"
+       check_and_add -d "${PKG_DBDIR}/${PKG}/+DESC"
+       check_and_add -b "${PKG_DBDIR}/${PKG}/+BUILD_VERSION"
+       check_and_add -B "${PKG_DBDIR}/${PKG}/+BUILD_INFO"
+       check_and_add -s "${PKG_DBDIR}/${PKG}/+SIZE_PKG"
+       check_and_add -S "${PKG_DBDIR}/${PKG}/+SIZE_ALL"
+       check_and_add -i "${PKG_DBDIR}/${PKG}/+INSTALL"
+       check_and_add -k "${PKG_DBDIR}/${PKG}/+DEINSTALL"
+       check_and_add -r "${PKG_DBDIR}/${PKG}/+REQUIRE"
+       check_and_add -D "${PKG_DBDIR}/${PKG}/+DISPLAY"
+       check_and_add -m "${PKG_DBDIR}/${PKG}/+MTREE"           #NOTYET#
 
        PLIST=/tmp/+CONTENTS.$$
-       sed -n \
+       ${SED} -n \
                -e '/^@comment MD5:/d' \
                -e '/^@cwd \.$/,$d' \
                -e '/\$NetBSD/,$p' \
-               <${PKG_DBDIR}/${PKG}/+CONTENTS >$PLIST
+               <"${PKG_DBDIR}/${PKG}/+CONTENTS" >"${PLIST}"
 
        # Duplicate first @cwd (work around pkg_create "feature" ...)
-       grep '^@cwd' $PLIST | ${HEAD} -1 >$PLIST.1
-       if [ -s ${PLIST}.1 ]
+       ${GREP} '^@cwd' "${PLIST}" | ${HEAD} -1 >"${PLIST}.1"
+       if [ -s "${PLIST}.1" ]
        then
-               sed \
-                  -e "/`cat ${PLIST}.1 | sed 's,/,\\\\/,g'`/r${PLIST}.1" \
-                  <${PLIST} >${PLIST}.2
-               mv ${PLIST}.2 ${PLIST}
+               ${SED} \
+                  -e "/`cat \"${PLIST}.1\" | ${SED} 's,/,\\\\/,g'`/r${PLIST}.1" \
+                  <"${PLIST}" >"${PLIST}.2"
+               mv "${PLIST}.2" "${PLIST}"
        fi
-       rm ${PLIST}.1
+       rm "${PLIST}.1"
 
        # ${ECHO} -----
        # cat $PLIST
@@ -98,39 +110,94 @@
 
        # Just for kicks ...
        # pkg_admin check "${PKG}"
-         
-       pkg_create \
-                       ${PKG_ARGS} \
-               -v \
-               -f ${PLIST} \
-               -l \
-               -p "`pkg_info -qp ${PKG} | ${AWK} 'NR == 1 { print $2; exit }'`" \
-               -P "`pkg_info -qf ${PKG} | ${AWK} '/^@pkgdep/ { print $2 }'`" \
-               -C "`pkg_info -qf ${PKG} | ${AWK} '/^@pkgcfl/ { print $2 }'`" \
-               ${PKGREPOSITORY}/${PKG}${PKG_SUFX}
+
+       # It's kind of silly to jump through hoops to get stuff with spaces
+       # here, since we have no way to pass it to pkg_create, but maybe someone
+       # will care enough to fix the rest of this.
+       PKG_PREFIX=`pkg_info -qp "${PKG}" | ${HEAD} -1 | ${SED} -e's/^@cwd[[:space:]]*//'`
+       PKG_DEPS=`pkg_info -qf "${PKG}" | ${GREP} "^@pkgdep" | ${SED} -e's/^@pkgdep[[:space:]]*//'`
+       PKG_CONFLICT=`pkg_info -qf "${PKG}" | ${GREP} "^@pkgcfl" | ${SED} -e's/^@pkgcfl[[:space:]]*//'`
 
-       rm -f ${PLIST}
+       PKG_ARGS="${PKG_ARGS} -v"
+       PKG_ARGS="${PKG_ARGS} -f \"${PLIST}\""
+       PKG_ARGS="${PKG_ARGS} -l"
+       PKG_ARGS="${PKG_ARGS} -p \"${PKG_PREFIX}\""
+       PKG_ARGS="${PKG_ARGS} -P \"${PKG_DEPS}\""
+       PKG_ARGS="${PKG_ARGS} -C \"${PKG_CONFLICT}\""
+       PKG_ARGS="${PKG_ARGS} \"${PKGREPOSITORY}/${PKG}${PKG_SUFX}\""
+       eval pkg_create "${PKG_ARGS}"
+
+       rm -f "${PLIST}"
        return 0
 }
 
-while [ $# -gt 0 ] ; do
-       rPKG="`pkg_info -e \"$1\"`"
+add_to_list()
+{
+       # Get expanded name, and escape quotes
+       rPKG=`pkg_info -e "$1" | ${SED} -e's/\"/\\\"/g'`
        if [ -z "$rPKG" -o -f "${PKG_DBDIR}/${rPKG}" ] ; then
                ${ECHO} "Error: package $1 not found"
                usage "$0"
        fi
-       PKGS="$PKGS $rPKG"
+       if ! ${ECHO} "${PKGS}" | ${GREP} -q "\"${rPKG}\"" ; then
+               PKGS="${PKGS} \"${rPKG}\""
+       fi
+}
+
+
+while [ $# -gt 0 ] ; do
+       case "$1" in
+       -a)
+               GETDEPS=1
+               shift
+               ;;
+       -d)
+               PKGREPOSITORY="$2"
+               shift 2
+               ;;
+       -h)
+               usage
+               exit 0
+               ;;
+       -K)
+               PKG_DBDIR="$2"
+               shift 2
+               ;;
+       -s)
+               PKG_SUFX="$2"
+               shift 2
+               ;;
+       *)
+               break
+               ;;
+       esac
+done
+
+while [ $# -gt 0 ] ; do
+       add_to_list "$1"
+       if [ $GETDEPS -eq 1 ] ; then
+               # Make the input separator only a newline so spaces are allowed
+               oIFS="$IFS"
+               IFS="
+"
+               for f in `pkg_info -qf "$1" | ${GREP} @pkgdep | ${SED} -e's/^@pkgdep[[:space:]]*//' ` ; do
+                       add_to_list "$f"
+               done
+               IFS="$oIFS"
+       fi
        shift
 done
-if [ -z "$PKGS" ] ; then
+if [ -z "${PKGS}" ] ; then
        usage "$0"
 fi
-for xPKG in $PKGS ; do
-       create_package "$xPKG"
-       if [ $? -ne 0 ] ; then
+FOR="
+for xPKG in ${PKGS} ; do
+       create_package \"\${xPKG}\"
+       if [ \$? -ne 0 ] ; then 
                exit 1
        fi
-done
+done"
+eval "${FOR}"
 
 exit 0
 
diff -r 2b3fc2ec0f36 -r 0d964bf45400 pkgtools/pkg_tarup/files/pkg_tarup.1
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkg_tarup/files/pkg_tarup.1      Wed Jul 14 16:08:48 2004 +0000
@@ -0,0 +1,109 @@
+.\" $NetBSD: pkg_tarup.1,v 1.1 2004/07/14 16:08:48 erh Exp $
+.Dd July 14, 2004
+.Dt PKG_TARUP 1
+.Os
+.Sh NAME
+.Nm pkg_tarup
+.Nd a utility for tarring up installed software packages
+.Sh SYNOPSIS
+.Nm
+.Op Fl a



Home | Main Index | Thread Index | Old Index