Skip to content

Instantly share code, notes, and snippets.

@mattkasa
Created February 5, 2013 21:08
Show Gist options
  • Save mattkasa/4717663 to your computer and use it in GitHub Desktop.
Save mattkasa/4717663 to your computer and use it in GitHub Desktop.
Gem Validator
#!/bin/bash
# Validate your project's gems from your gem cache against rightscale's mirror.
gem query --local --details --all | \
sed -e ':a;N;$!ba' -e 's/\n/#/g' | \
sed -e 's/##/\n/g' | \
sed -ne '/^[^[:space:]]\+ ([^)]\+)#/p' | \
while read line; do
name="${line%% *}"
platform="$(echo "${line}" | sed -ne '/Platform:/{s/^.*Platform: \([^#[:space:]]\+\).*$/-\1/;p}')"
versions=( $(echo "${line}" | sed -e 's/#/\n/g' | sed -ne "/^.*\(Installed at\|([^)]\+)\): /{s/Installed at (\([^)]\+\)): /\1:/g;s/Installed at: /$(echo "${line%%#*}" | sed -e 's/^.*(\([^)]\+\)).*$/\1/'):/;s/(\([^)]\+\)): /\1:/g;p}") )
for version in "${versions[@]}"; do
path="${version#*:}/cache/${name}-${version%%:*}${platform}.gem"
if [ -f "${path}" ]; then
local="$(sha512sum "${path}" | sed -e 's/[[:space:]].*$//')"
remote="$(curl -s "http://mirror.rightscale.com/rubygems/archive/latest/gems/${path##*/}" | sha512sum | sed -e 's/[[:space:]].*$//')"
echo -n "${path}: "
if [ "${local}" = "${remote}" ]; then
echo "OK"
else
echo "BAD"
exit 1
fi
else
echo "NOT FOUND: ${path}" >&2
exit 1
fi
done
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment