generate-dockerfile-links-partial.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. IFS=$'\n'
  10. lines=( $(curl -fsSL 'https://raw.githubusercontent.com/docker-library/official-images/master/library/'"$repo" | grep -vE '^$|^#') )
  11. unset IFS
  12. if [ "${#lines[@]}" -eq 0 ]; then
  13. echo >&2 "Failed to read manifest file for $repo"
  14. exit 1
  15. fi
  16. repoDirs=()
  17. declare -A repoDirTags=()
  18. for line in "${lines[@]}"; do
  19. tag="$(echo "$line" | awk -F ': +' '{ print $1 }')"
  20. repoDir="$(echo "$line" | awk -F ': +' '{ print $2 }')"
  21. if [ -z "${repoDirTags[$repoDir]}" ]; then
  22. repoDirs+=( "$repoDir" )
  23. else
  24. repoDirTags["$repoDir"]+=', '
  25. fi
  26. repoDirTags["$repoDir"]+='`'"$tag"'`'
  27. done
  28. for repoDir in "${repoDirs[@]}"; do
  29. if [[ "$repoDir" != *github.com* ]]; then
  30. # skip non-github.com for now
  31. continue
  32. fi
  33. # split out some data
  34. gitUrl="${repoDir%%@*}"
  35. commitDir="${repoDir#*@}"
  36. commit="${commitDir%% *}"
  37. dir="${commitDir#* }"
  38. if [ "$dir" = "$commitDir" ]; then
  39. dir=''
  40. fi
  41. # sanitize some data
  42. gitUrl="${gitUrl#git://}"
  43. gitUrl="${gitUrl%/}"
  44. gitUrl="${gitUrl%.git}"
  45. dir="${dir#/}"
  46. dir="${dir%/}"
  47. [ -z "$dir" ] || dir="$dir/"
  48. url="https://$gitUrl/blob/$commit/${dir}Dockerfile"
  49. echo $'-\t['"${repoDirTags["$repoDir"]}"' (*'"${dir}Dockerfile"'*)]('"$url"')'
  50. done
  51. echo