Create a gist now

Instantly share code, notes, and snippets.

@mlen /compare-gem.sh
Last active Dec 11, 2015

What would you like to do?
#!/usr/bin/env bash
#
# Usage
# bash compare-gem.sh GEMNAME GEMVERSION GEMPLATFORM
#
# Return value: 0 when the gem is OK, 1 when there was a mismatch
#
# Note: it requires that the gem being checked is installed on your local system
# in $GEM_HOME
set -e
name="$1"
version="$2"
platform="$3"
gemhome="$(gem env gemhome)"
fail=0
# download .gem file
basename="${name}-${version}"
filename="${name}-${version}.gem"
if [ "x$plaform" == "x" -o "x$platform" == "xruby" ]; then
url="http://production.cf.rubygems.org/gems/${name}-${version}.gem"
else
url="http://production.cf.rubygems.org/gems/${name}-${version}-${platform}.gem"
fi
curl "$url" >"$filename" 2>/dev/null
# extracting gem contents
mkdir data
tar -xf "$filename" -C data
(cd data && mkdir code && tar -xf "data.tar.gz" -C code && gzip -d "metadata.gz")
# comparing contents
diff -r data/code "$gemhome/gems/$basename" || fail=1
# extracting original metadata
mkdir original
tar -xf "$gemhome/cache/$filename" -C original
(cd original && gzip -d "metadata.gz")
# comparing metadata
diff data/metadata original/metadata || fail=1
# cleanup
rm -rf data
rm -rf original
rm "$filename"
if [ $fail -eq 1 ]; then exit 1; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment