variant.sh 1.3 KB

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