Browse files

rpg-unpack writes name of unpack directory to stdout

  • Loading branch information...
1 parent dd99548 commit 64c9edb311d97023d850dfa8f77c3e947de10925 @rtomayko committed Mar 22, 2010
Showing with 38 additions and 19 deletions.
  1. +1 −1
  2. +37 −18
@@ -92,7 +92,7 @@ else rm -rf "$RPGPACKS/$package-$version"
gemfile=$(rpg-fetch "$package" "$version")
notice "unpacking $gemfile into $RPGPACKS"
mkdir -p "$RPGPACKS"
- rpg-unpack -p "$RPGPACKS" "$gemfile"
+ rpg-unpack -p "$RPGPACKS" "$gemfile" >/dev/null
rpg-shit-list "$package" "$version" "$RPGPACKS/$package-$version"
@@ -17,22 +17,27 @@
set -e
. rpg-sh-setup
-USAGE '${PROGNAME} [-p <path>] <gem>
- ${PROGNAME} -c [-m] <gem>
-Unpack a gem file to disk or as a tar stream on stdout.
+USAGE '${PROGNAME} [-p <path>|-P] <package> [<version>]
+ ${PROGNAME} -c [-m] <package> [<version>]
+Unpack a gem file to disk or as a tar stream on standard output.
- -p <path> Unpack under <path> instead of the working directory
+ -p <path> Unpack under <path> instead of the working directory.
+ -P Unpack under RPGPACKS instead of the working directory.
-c Write gem data tar stream to stdout. Do not create any files.
-m Change the behavior of the -c option. Write gem metadata
- segment instead of the data segment.'
+ segment instead of the data segment.
+The <package> may be a package name or path to a gem file on disk. When a
+package name is given, the <version> may also be specified.'
-while getopts cmp: opt
+while getopts cmPp: opt
case $opt in
p) workdir="$OPTARG";;
+ P) workdir="$RPGCACHE";;
c) filter=cat;;
m) segment=metadata.gz;;
?) helpthem
@@ -47,29 +52,43 @@ then warn "illegal argument: -m must be used with -c"
exit 2
-# Make sure a gem file was given.
-name=$(basename "$1" .gem)
-test "$name" || { helpthem; exit 2; }
+# Check whether a gem file or package name was given.
+if expr "$1" : '.*\.gem' >/dev/null
+then file="$1"
+ test -r "$file" || {
+ warn "gem file can not be read: $file"
+ exit 1
+ }
+else file=$(rpg-fetch "$1" "${2:->0}")
-# Quickly check that the gem file is readable.
-test -r "$1" || {
- warn "gem file can not be read: $1"
- exit 1
+# Extract the package name and version from the gem file.
+basename=$(basename "$file" .gem)
# This takes the gem's `data.tar` stream on stdin and untars it into a
# newly created directory after the gem name. When the `-c` option is not
# given, the gem tar stream is piped through here.
untar () {
- mkdir "$workdir/$name"
- tar -xom -C "$workdir/$name" -f - 2>/dev/null
+ mkdir "$workdir/$package-$version"
+ tar -xom -C "$workdir/$package-$version" -f - 2>/dev/null
+notice "$file -> $workdir/$package-$version"
# Pipe the gem directly into `tar` and extract only the file/segment we're
# interested in (the `-O` option causes the file to be written to stdout
# instead of to disk). Next, pipe that thing through gzip to decompress and
# finally into whatever filter was configured (`cat` with the `-c` option or
# our `untar` function above otherwise).
-tar -xOmf - $segment < "$1" 2>/dev/null |
-gzip -dc |
+tar -xOmf - $segment < "$file" 2>/dev/null |
+gzip -dc |
+# Write the path to the unpacked package directory on standard output.
+if test "$filter" = "untar"
+then echo "$workdir/$package-$version"

0 comments on commit 64c9edb

Please sign in to comment.