Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

53 lines (43 sloc) 1.488 kB
#!/bin/sh
set -e
. rpg-sh-setup
[ "$*" ] || set -- "--help"; ARGV="$@"
USAGE '${PROGNAME} <package> [<version>]
Fetch a package into the cache, writing the filename to stdout.
No network operations are performed when a package exists in the cache
that satisfies the version spec.'
package="$1"
version="${2:->=0}"
# Find the best (most recent) version of the package matching the
# supplied version spec. Bail out with a failure status if nothing is
# found satisfying the requested version.
#
# When a concrete version is given (e.g. `=0.5.3` or `1.2`), the version is
# not resolved against the index.
if expr "$version" : '.*[><~]' >/dev/null
then bestver=$(rpg-resolve -n 1 "$package" "$version") || {
warn "$package $version not found."
exit 1
}
else bestver="${version#=}"
fi
gemfile="${package}-${bestver}.gem"
if test -f "$RPGCACHE/$gemfile"
then notice "$package $version [cached: $bestver]"
else
# We're going to need to pull the gem off the server.
mkdir -p "$RPGCACHE"
cd "$RPGCACHE"
if test "$bestver" != "$version"
then heed "$package $version [resolved: $bestver]"
else heed "$package $version"
fi
# Grab the gem with `curl(1)` and write to a temporary file just
# in case something goes wrong during transfer.
if ! curl --fail -s -L "$RPGGEMURL/${gemfile}" > "${gemfile}+"
then warn "$package $version not found."
exit 1
fi
mv "${gemfile}+" "$gemfile"
fi
echo "$RPGCACHE/$gemfile"
Jump to Line
Something went wrong with that request. Please try again.