variant.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. set -eo pipefail
  3. repo="$1"
  4. if [ -z "$repo" ]; then
  5. echo >&2 "usage: $0 repo"
  6. echo >&2 " ie: $0 hylang"
  7. exit 1
  8. fi
  9. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  10. url='https://raw.githubusercontent.com/docker-library/official-images/master/library/'"$repo"
  11. IFS=$'\n'
  12. tags=( $(curl -fsSL "$url" | grep -vE '^$|^#' | cut -d':' -f1 | sort -u) )
  13. unset IFS
  14. text=
  15. for tag in "${tags[@]}"; do
  16. if [ -f "$dir/variant-${tag}.md" ]; then
  17. text+=$'\n' # give a little space
  18. # because parameter expansion eats the trailing newline
  19. text+="$(<"$dir/variant-${tag}.md")"$'\n'
  20. fi
  21. done
  22. if [ "$text" ]; then
  23. latest=($(curl -fsSL "$url" | grep "latest.*github.com" | sed -e 's!git://github.com/!!' -e 's/@/ /' -))
  24. if [ -z "latest" ]; then
  25. exit 0 # If not github or no latest tag, we are done here
  26. fi
  27. dockerfile='https://raw.githubusercontent.com/'"${latest[1]}"'/'"${latest[2]}"'/'"${latest[3]}"'/Dockerfile'
  28. baseImage=$(curl -fsSL "$dockerfile" | awk -F '[:[:space:]]+' '$1 == "FROM" { print $2 }')
  29. # give a little space
  30. echo
  31. echo
  32. if [ "$baseImage" = "buildpack-deps" ]; then
  33. cat "$dir/variant-buildpacks.md"
  34. else
  35. cat "$dir/variant.md"
  36. fi
  37. echo "$text"
  38. fi