Created
February 5, 2013 21:08
-
-
Save mattkasa/4717663 to your computer and use it in GitHub Desktop.
Gem Validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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