Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rpg-unpack writes name of unpack directory to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Mar 22, 2010
1 parent dd99548 commit 64c9edb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion rpg-package-install.sh
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ else rm -rf "$RPGPACKS/$package-$version"
gemfile=$(rpg-fetch "$package" "$version") gemfile=$(rpg-fetch "$package" "$version")
notice "unpacking $gemfile into $RPGPACKS" notice "unpacking $gemfile into $RPGPACKS"
mkdir -p "$RPGPACKS" mkdir -p "$RPGPACKS"
rpg-unpack -p "$RPGPACKS" "$gemfile" rpg-unpack -p "$RPGPACKS" "$gemfile" >/dev/null
rpg-shit-list "$package" "$version" "$RPGPACKS/$package-$version" rpg-shit-list "$package" "$version" "$RPGPACKS/$package-$version"
fi fi


Expand Down
55 changes: 37 additions & 18 deletions rpg-unpack.sh
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@
set -e set -e
. rpg-sh-setup . rpg-sh-setup


USAGE '${PROGNAME} [-p <path>] <gem> USAGE '${PROGNAME} [-p <path>|-P] <package> [<version>]
${PROGNAME} -c [-m] <gem> ${PROGNAME} -c [-m] <package> [<version>]
Unpack a gem file to disk or as a tar stream on stdout. Unpack a gem file to disk or as a tar stream on standard output.
Options Options
-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. -c Write gem data tar stream to stdout. Do not create any files.
-m Change the behavior of the -c option. Write gem metadata -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.'
workdir=. workdir=.
filter=untar filter=untar
segment=data.tar.gz segment=data.tar.gz
while getopts cmp: opt while getopts cmPp: opt
do do
case $opt in case $opt in
p) workdir="$OPTARG";; p) workdir="$OPTARG";;
P) workdir="$RPGCACHE";;
c) filter=cat;; c) filter=cat;;
m) segment=metadata.gz;; m) segment=metadata.gz;;
?) helpthem ?) helpthem
Expand All @@ -47,29 +52,43 @@ then warn "illegal argument: -m must be used with -c"
exit 2 exit 2
fi fi


# Make sure a gem file was given. # Check whether a gem file or package name was given.
name=$(basename "$1" .gem) if expr "$1" : '.*\.gem' >/dev/null
test "$name" || { helpthem; exit 2; } then file="$1"
test -r "$file" || {
warn "gem file can not be read: $file"
exit 1
}
else file=$(rpg-fetch "$1" "${2:->0}")
fi


# Quickly check that the gem file is readable. # Extract the package name and version from the gem file.
test -r "$1" || { basename=$(basename "$file" .gem)
warn "gem file can not be read: $1" package=${basename%-*}
exit 1 version=${basename##*-}
}


# This takes the gem's `data.tar` stream on stdin and untars it into a # 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 # newly created directory after the gem name. When the `-c` option is not
# given, the gem tar stream is piped through here. # given, the gem tar stream is piped through here.
untar () { untar () {
mkdir "$workdir/$name" mkdir "$workdir/$package-$version"
tar -xom -C "$workdir/$name" -f - 2>/dev/null 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 # 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 # 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 # 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 # finally into whatever filter was configured (`cat` with the `-c` option or
# our `untar` function above otherwise). # our `untar` function above otherwise).
tar -xOmf - $segment < "$1" 2>/dev/null | tar -xOmf - $segment < "$file" 2>/dev/null |
gzip -dc | gzip -dc |
$filter $filter

# Write the path to the unpacked package directory on standard output.
if test "$filter" = "untar"
then echo "$workdir/$package-$version"
fi

true

0 comments on commit 64c9edb

Please sign in to comment.