Annotation of pkgsrc/pkgtools/pkg_tarup/files/pkg_tarup, Revision 1.14
1.8 wiz 1: #! @SH@
1.6 hubertf 2: #
1.14 ! erh 3: # $Id: pkg_tarup,v 1.13 2004/07/14 16:08:48 erh Exp $
1.1 hubertf 4: #
5: # Tar up installed package
6: #
1.10 erh 7: # Package names are assumed to not contain spaces.
8: #
1.6 hubertf 9: # (c) Copyright 2000-2002 Hubert Feyrer <hubert@feyrer.de>
1.1 hubertf 10: #
11:
1.8 wiz 12: PREFIX=${PREFIX:-@PREFIX@}
13:
14: PATH=/sbin:/usr/sbin:/bin:/usr/bin:${PREFIX}/sbin:${PREFIX}/bin:@PKG_TOOLS_BIN@
15: export PATH
16:
17: OS=`uname -s`
18:
19: ECHO=${ECHO:-@ECHO@}
1.9 jschauma 20: HEAD=${HEAD:-@HEAD@}
1.8 wiz 21: ID=${ID:-@ID@}
1.13 erh 22: SED=${SED:-@SED@}
1.8 wiz 23: SU=${SU:-@SU@}
1.13 erh 24: GREP=${GREP:-@GREP@}
1.5 agc 25:
1.6 hubertf 26: if [ `${ID} -u` != 0 ]; then
27: ${ECHO} "Becoming root@`/bin/hostname` to create a binary package"
1.13 erh 28: ${ECHO} -n "`${ECHO} ${SU} | ${SED} -e's/[[:space:]].*//'` ";\
29: exec ${SU} root -c "$0 \"\$@\"" "$0" "$@"
1.5 agc 30: fi
31:
1.8 wiz 32: PKG_DBDIR=${PKG_DBDIR:-@PKG_DBDIR@}
33: PKG_SUFX=${PKG_SUFX:-@PKG_SUFX@}
1.6 hubertf 34:
1.1 hubertf 35: PKGREPOSITORY=${PKGREPOSITORY:-/tmp}
36:
1.13 erh 37: # XXX Force pkg_info to ignore .tgz files.
38: export PKG_PATH=
39:
40: # Set to 1 if we also want to tar up dependencies also
41: GETDEPS=0
42:
1.10 erh 43: usage()
44: {
1.13 erh 45: ${ECHO} "Usage: $1 [-a] [-K pkg_dbdir] [-d pkgrepository] [-s pkg_sufx] installed_pkg|pattern [...]"
46: ${ECHO} "The following environment variables are used:"
47: ${ECHO} " (unless overriden by command line parameters)"
48: ${ECHO} " PKGREPOSITORY - A destination directory for packages (/tmp)"
49: ${ECHO} " PKG_DBDIR - The location of the package database directory"
50: ${ECHO} " PKG_SUFX - The suffix to append to the package (.tgz)"
1.10 erh 51: exit 1
52: }
1.1 hubertf 53:
1.10 erh 54: check_and_add()
55: {
1.1 hubertf 56: opt="$1"
57: file="$2"
58:
59: if [ x"$opt" = x"" -o x"$file" = x"" ]; then
1.6 hubertf 60: ${ECHO} Usage: check_and_add -opt +FILE
1.1 hubertf 61: exit 1
62: fi
63:
64: if [ -f "$file" ]
65: then
1.13 erh 66: PKG_ARGS="${PKG_ARGS} \"${opt}\" \"${file}\""
1.1 hubertf 67: fi
68: }
69:
1.10 erh 70: create_package()
71: {
72: PKG="$1"
1.11 erh 73: PKG_ARGS=
1.10 erh 74: ${ECHO} "Creating binary package: $PKG"
75:
1.13 erh 76: check_and_add -c "${PKG_DBDIR}/${PKG}/+COMMENT"
77: check_and_add -d "${PKG_DBDIR}/${PKG}/+DESC"
78: check_and_add -b "${PKG_DBDIR}/${PKG}/+BUILD_VERSION"
79: check_and_add -B "${PKG_DBDIR}/${PKG}/+BUILD_INFO"
80: check_and_add -s "${PKG_DBDIR}/${PKG}/+SIZE_PKG"
81: check_and_add -S "${PKG_DBDIR}/${PKG}/+SIZE_ALL"
82: check_and_add -i "${PKG_DBDIR}/${PKG}/+INSTALL"
83: check_and_add -k "${PKG_DBDIR}/${PKG}/+DEINSTALL"
84: check_and_add -r "${PKG_DBDIR}/${PKG}/+REQUIRE"
85: check_and_add -D "${PKG_DBDIR}/${PKG}/+DISPLAY"
86: check_and_add -m "${PKG_DBDIR}/${PKG}/+MTREE" #NOTYET#
1.10 erh 87:
88: PLIST=/tmp/+CONTENTS.$$
1.13 erh 89: ${SED} -n \
1.10 erh 90: -e '/^@comment MD5:/d' \
91: -e '/^@cwd \.$/,$d' \
92: -e '/\$NetBSD/,$p' \
1.13 erh 93: <"${PKG_DBDIR}/${PKG}/+CONTENTS" >"${PLIST}"
1.10 erh 94:
95: # Duplicate first @cwd (work around pkg_create "feature" ...)
1.13 erh 96: ${GREP} '^@cwd' "${PLIST}" | ${HEAD} -1 >"${PLIST}.1"
97: if [ -s "${PLIST}.1" ]
1.10 erh 98: then
1.13 erh 99: ${SED} \
100: -e "/`cat \"${PLIST}.1\" | ${SED} 's,/,\\\\/,g'`/r${PLIST}.1" \
101: <"${PLIST}" >"${PLIST}.2"
102: mv "${PLIST}.2" "${PLIST}"
1.10 erh 103: fi
1.13 erh 104: rm "${PLIST}.1"
1.10 erh 105:
106: # ${ECHO} -----
107: # cat $PLIST
108: # ${ECHO} -----
109: # exit 0
110:
111: # Just for kicks ...
112: # pkg_admin check "${PKG}"
113:
1.13 erh 114: # It's kind of silly to jump through hoops to get stuff with spaces
115: # here, since we have no way to pass it to pkg_create, but maybe someone
116: # will care enough to fix the rest of this.
117: PKG_PREFIX=`pkg_info -qp "${PKG}" | ${HEAD} -1 | ${SED} -e's/^@cwd[[:space:]]*//'`
118: PKG_DEPS=`pkg_info -qf "${PKG}" | ${GREP} "^@pkgdep" | ${SED} -e's/^@pkgdep[[:space:]]*//'`
119: PKG_CONFLICT=`pkg_info -qf "${PKG}" | ${GREP} "^@pkgcfl" | ${SED} -e's/^@pkgcfl[[:space:]]*//'`
120:
121: PKG_ARGS="${PKG_ARGS} -v"
122: PKG_ARGS="${PKG_ARGS} -f \"${PLIST}\""
123: PKG_ARGS="${PKG_ARGS} -l"
124: PKG_ARGS="${PKG_ARGS} -p \"${PKG_PREFIX}\""
125: PKG_ARGS="${PKG_ARGS} -P \"${PKG_DEPS}\""
126: PKG_ARGS="${PKG_ARGS} -C \"${PKG_CONFLICT}\""
127: PKG_ARGS="${PKG_ARGS} \"${PKGREPOSITORY}/${PKG}${PKG_SUFX}\""
128: eval pkg_create "${PKG_ARGS}"
129:
130: rm -f "${PLIST}"
1.10 erh 131: return 0
132: }
133:
1.13 erh 134: add_to_list()
135: {
1.14 ! erh 136: local added
! 137:
! 138: added=0
! 139:
! 140: oIFS="$IFS"
! 141: IFS="
! 142: "
1.13 erh 143: # Get expanded name, and escape quotes
1.14 ! erh 144: for rPKG in `pkg_info -e "$1" | ${SED} -e's/\"/\\\"/g'` ; do
! 145: if [ -z "$rPKG" -o -f "${PKG_DBDIR}/${rPKG}" ] ; then
! 146: ${ECHO} "Error: package $1 not found"
! 147: usage "$0"
! 148: fi
! 149:
! 150: added=1
! 151: if ! ${ECHO} "${PKGS}" | ${GREP} -q "\"${rPKG}\"" ; then
! 152: PKGS="${PKGS} \"${rPKG}\""
! 153: fi
! 154: done
! 155: IFS="$oIFS"
! 156: if [ $added -eq 0 ] ; then
! 157: ${ECHO} "Warning: no package matching $1 found"
1.13 erh 158: fi
159: }
160:
161:
162: while [ $# -gt 0 ] ; do
163: case "$1" in
164: -a)
165: GETDEPS=1
166: shift
167: ;;
168: -d)
169: PKGREPOSITORY="$2"
170: shift 2
171: ;;
172: -h)
173: usage
174: exit 0
175: ;;
176: -K)
177: PKG_DBDIR="$2"
178: shift 2
179: ;;
180: -s)
181: PKG_SUFX="$2"
182: shift 2
183: ;;
184: *)
185: break
186: ;;
187: esac
188: done
189:
190: while [ $# -gt 0 ] ; do
191: add_to_list "$1"
192: if [ $GETDEPS -eq 1 ] ; then
193: # Make the input separator only a newline so spaces are allowed
194: oIFS="$IFS"
195: IFS="
196: "
197: for f in `pkg_info -qf "$1" | ${GREP} @pkgdep | ${SED} -e's/^@pkgdep[[:space:]]*//' ` ; do
198: add_to_list "$f"
199: done
200: IFS="$oIFS"
201: fi
1.10 erh 202: shift
203: done
1.13 erh 204: if [ -z "${PKGS}" ] ; then
1.14 ! erh 205: ${ECHO} "ERROR: No packages to tarup identified!"
1.10 erh 206: usage "$0"
1.1 hubertf 207: fi
1.13 erh 208: FOR="
209: for xPKG in ${PKGS} ; do
210: create_package \"\${xPKG}\"
211: if [ \$? -ne 0 ] ; then
1.10 erh 212: exit 1
213: fi
1.13 erh 214: done"
215: eval "${FOR}"
1.1 hubertf 216:
217: exit 0
218:
219:
1.8 wiz 220: +REQUIRED_BY:
221:
222: - maybe the squirelling away of +REQUIRED_BY should be done here
223: instead of in the bsd.pkg.mk framework that normally calls this.
1.1 hubertf 224:
1.6 hubertf 225:
1.1 hubertf 226: mtree file considerations:
1.8 wiz 227:
1.4 hubertf 228: - keeping uncompressed mtree file adds ~10% to the size of /var/db/pkg
1.8 wiz 229:
1.1 hubertf 230: - could gzip file, space saving: 5kb->850b (plus some intelligence to
231: uncompress them when needed)
1.8 wiz 232:
1.1 hubertf 233: - not keeping mtree file results in pkgs w/o mtree file (but should work)
234:
235: integration:
1.8 wiz 236:
1.6 hubertf 237: - how/where? I'd prefer not to have yet another pkg_* utility flying
238: around, integration into pkg_admin would be nice. But how merge a
1.8 wiz 239: shell script into a C executable? REWRITE in C of course! ;-)
CVSweb <webmaster@jp.NetBSD.org>