update.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/bash
  2. set -Eeuo pipefail
  3. cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. helperDir='.template-helpers'
  5. images=( "$@" )
  6. if [ ${#images[@]} -eq 0 ]; then
  7. images=( */ )
  8. fi
  9. images=( "${images[@]%/}" )
  10. replace_field() {
  11. targetFile="$1"
  12. field="$2"
  13. content="$3"
  14. extraSed="${4:-}"
  15. sed_escaped_value="$(echo "$content" | sed 's/[\/&]/\\&/g')"
  16. sed_escaped_value="${sed_escaped_value//$'\n'/\\n}"
  17. sed -ri -e "s/${extraSed}%%${field}%%${extraSed}/$sed_escaped_value/g" "$targetFile"
  18. }
  19. for image in "${images[@]}"; do
  20. repo="${image##*/}"
  21. namespace="${image%$repo}"
  22. namespace="${namespace%/}"
  23. if [ -x "$repo/update.sh" ]; then
  24. ( set -x; "$repo/update.sh" )
  25. fi
  26. if [ -e "$repo/content.md" ]; then
  27. githubRepo="$(cat "$repo/github-repo")"
  28. maintainer="$(cat "$repo/maintainer.md")"
  29. issues="$(cat "$repo/issues.md" 2>/dev/null || cat "$helperDir/issues.md")"
  30. getHelp="$(cat "$repo/get-help.md" 2>/dev/null || cat "$helperDir/get-help.md")"
  31. license="$(cat "$repo/license.md" 2>/dev/null || true)"
  32. if [ "$license" ]; then
  33. license=$'\n\n''# License'$'\n\n'"$license"
  34. fi
  35. logo=
  36. logoFile=
  37. for f in png svg; do
  38. if [ -e "$repo/logo.$f" ]; then
  39. logoFile="$repo/logo.$f"
  40. break
  41. fi
  42. done
  43. if [ "$logoFile" ]; then
  44. logoCommit="$(git log -1 --format='format:%H' -- "$logoFile" 2>/dev/null || true)"
  45. [ "$logoCommit" ] || logoCommit='master'
  46. if [ "${logoFile##*.}" = 'svg' ]; then
  47. logo="![logo](https://rawgit.com/docker-library/docs/$logoCommit/$logoFile)"
  48. else
  49. logo="![logo](https://raw.githubusercontent.com/docker-library/docs/$logoCommit/$logoFile)"
  50. fi
  51. fi
  52. compose=
  53. composeYml=
  54. if [ -f "$repo/docker-compose.yml" ]; then
  55. compose="$(cat "$repo/compose.md" 2>/dev/null || cat "$helperDir/compose.md")"
  56. composeYml=$'```yaml\n'"$(cat "$repo/docker-compose.yml")"$'\n```'
  57. fi
  58. deprecated=
  59. if [ -f "$repo/deprecated.md" ]; then
  60. deprecated=$'# **DEPRECATED**\n\n'
  61. deprecated+="$(cat "$repo/deprecated.md")"
  62. deprecated+=$'\n\n'
  63. fi
  64. targetFile="$repo/README.md"
  65. {
  66. cat "$helperDir/autogenerated-warning.md"
  67. echo
  68. echo -n "$deprecated"
  69. cat "$helperDir/template.md"
  70. } > "$targetFile"
  71. echo ' TAGS => generate-dockerfile-links-partial.sh "'"$repo"'"'
  72. partial="$("$helperDir/generate-dockerfile-links-partial.sh" "$repo")"
  73. [ "$partial" ]
  74. replace_field "$targetFile" 'TAGS' "$partial"
  75. echo ' CONTENT => '"$repo"'/content.md'
  76. replace_field "$targetFile" 'CONTENT' "$(cat "$repo/content.md")"
  77. echo ' VARIANT => variant.sh'
  78. replace_field "$targetFile" 'VARIANT' "$("$helperDir/variant.sh" "$repo")"
  79. # has to be after CONTENT because it's contained in content.md
  80. echo " LOGO => $logo"
  81. replace_field "$targetFile" 'LOGO' "$logo" '\s*'
  82. echo ' COMPOSE => '"$repo"'/compose.md'
  83. replace_field "$targetFile" 'COMPOSE' "$compose"
  84. echo ' COMPOSE-YML => '"$repo"'/docker-compose.yml'
  85. replace_field "$targetFile" 'COMPOSE-YML' "$composeYml"
  86. echo ' LICENSE => '"$repo"'/license.md'
  87. replace_field "$targetFile" 'LICENSE' "$license"
  88. echo ' ISSUES => "'"$issues"'"'
  89. replace_field "$targetFile" 'ISSUES' "$issues"
  90. echo ' GET-HELP => "'"$getHelp"'"'
  91. replace_field "$targetFile" 'GET-HELP' "$getHelp"
  92. echo ' MAINTAINER => "'"$maintainer"'"'
  93. replace_field "$targetFile" 'MAINTAINER' "$maintainer"
  94. echo ' IMAGE => "'"$image"'"'
  95. replace_field "$targetFile" 'IMAGE' "$image"
  96. echo ' REPO => "'"$repo"'"'
  97. replace_field "$targetFile" 'REPO' "$repo"
  98. echo ' GITHUB-REPO => "'"$githubRepo"'"'
  99. replace_field "$targetFile" 'GITHUB-REPO' "$githubRepo"
  100. echo
  101. else
  102. echo >&2 "skipping $repo: missing repo/content.md"
  103. fi
  104. done