Last active
November 16, 2017 13:34
-
-
Save rezen/964afdf73c7334e8a1b3dffa7b0f7bfa to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
set -e | |
format_text=1 | |
if [[ "$@" == *"--nofmt"* ]]; then | |
format_text=0 | |
fi | |
image="$1" | |
if [[ $image == '' ]] | |
then | |
echo "[!] You need to pass an image name" >&2 | |
exit 2 | |
fi | |
version=$(echo $image | cut -s -d':' -f 2) | |
if [[ $version == '' ]] | |
then | |
version='latest' | |
else | |
image=$(echo $image | cut -s -d':' -f 1) | |
fi | |
user_repo="docker-library/$image" | |
readonly meta=$(curl -s https://raw.githubusercontent.com/docker-library/official-images/master/library/$image ) | |
readonly info=$(echo "$meta" | grep "Tags:.* ${version}" -A3) | |
readonly commit=$(echo "$info" | grep Commit | cut -d' ' -f2) | |
readonly directory=$(echo "$info" | grep Directory | cut -d' ' -f2) | |
tmp=$(echo "$meta" | grep GitRepo | cut -d' ' -f2) | |
# If a git repo is specifified use that! | |
if [ ! -z $tmp ] | |
then | |
tmp="${tmp/https:\/\/github.com\//}" | |
user_repo="${tmp/\.git/}" | |
fi | |
readonly spec=$(curl -s https://raw.githubusercontent.com/$user_repo/$commit/$directory/Dockerfile) | |
if (echo "$spec" | grep -q 404) | |
then | |
echo "[!] Could not find the Dockerfile for that image! [$image:$version]($commit/$directory)" >&2 | |
exit 3 | |
fi | |
if (which pygmentize &> /dev/null) && [ $format_text == 1 ] | |
then | |
echo "# @source github.com/$user_repo" | |
echo "$spec" | pygmentize -l docker | |
else | |
echo "# @source github.com/$user_repo" | |
echo "$spec" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment