generate-repo-stub-readme.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. set -e
  3. cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. repo="$1"
  5. if [ -z "$repo" ]; then
  6. echo >&2 'error: no repo specified'
  7. cat >&2 <<EOUSAGE
  8. usage: $0 repo [> README.md]
  9. ie: $0 php > ../php/README.md
  10. This script generates a stub README to standard out for the specified repo.
  11. EOUSAGE
  12. exit 1
  13. fi
  14. gitRepo='https://github.com/docker-library/docs'
  15. hubPage="https://registry.hub.docker.com/_/$repo/"
  16. canonicalRepo="https://github.com/docker-library/$repo"
  17. if [ -s "$repo/github-repo" ]; then
  18. canonicalRepo="$(< "$repo/github-repo")"
  19. fi
  20. canonicalRepo="$(curl -fsSLI -o /dev/null -w '%{url_effective}\n' "$canonicalRepo")" # follow redirects (http://stackoverflow.com/a/3077316/433558)
  21. travisRepo="${canonicalRepo#*://github.com/}"
  22. if [ -f "$repo/deprecated.md" ]; then
  23. echo '# DEPRECATED'
  24. echo
  25. cat "$repo/deprecated.md"
  26. echo
  27. fi
  28. cat <<EOREADME
  29. # About this Repo
  30. This is the Git repo of the Docker [official image](https://docs.docker.com/docker-hub/official_repos/) for [$repo]($hubPage). See [the Docker Hub page]($hubPage) for the full readme on how to use this Docker image and for information regarding contributing and issues.
  31. The full readme is generated over in [docker-library/docs]($gitRepo), specifically in [docker-library/docs/$repo]($gitRepo/tree/master/$repo).
  32. See a change merged here that doesn't show up on the Docker Hub yet? Check [the "library/$repo" manifest file in the docker-library/official-images repo](https://github.com/docker-library/official-images/blob/master/library/$repo), especially [PRs with the "library/$repo" label on that repo](https://github.com/docker-library/official-images/labels/library%2F$repo). For more information about the official images process, see the [docker-library/official-images readme](https://github.com/docker-library/official-images/blob/master/README.md).
  33. EOREADME
  34. badges=()
  35. n=$'\n'
  36. t=$'\t'
  37. travisImage="https://img.shields.io/travis/$travisRepo/master.svg"
  38. if svg="$(wget -qO- "$travisImage" 2>/dev/null)" && [[ "$svg" != *unknown* ]]; then
  39. travisLink="https://travis-ci.org/$travisRepo/branches"
  40. badges+=( "-${t}[Travis CI: ${n}${t}![build status badge]($travisImage)]($travisLink)" )
  41. fi
  42. # https://www.appveyor.com/docs/status-badges/#badges-for-projects-with-public-repositories-on-github-and-bitbucket
  43. appveyorImage="https://ci.appveyor.com/api/projects/status/github/docker-library/$repo?branch=master&svg=true"
  44. if svg="$(wget -qO- "$appveyorImage" 2>/dev/null)" && [[ "$svg" != *unknown* ]]; then
  45. appveyorLink="https://ci.appveyor.com/project/docker-library/$repo"
  46. badges+=( "-${t}[AppVeyor (Windows): ${n}${t}![build status badge]($appveyorImage)]($appveyorLink)" )
  47. fi
  48. jenkinsImage="https://doi-janky.infosiftr.net/job/update.sh/job/$repo/badge/icon"
  49. if wget -q --spider "$jenkinsImage" &> /dev/null; then
  50. jenkinsLink="https://doi-janky.infosiftr.net/job/update.sh/job/$repo"
  51. badges+=( "-${t}[Automated \`update.sh\`: ${n}${t}![build status badge]($jenkinsImage)]($jenkinsLink)" )
  52. fi
  53. if [ "${#badges[@]}" -gt 0 ]; then
  54. IFS=$'\n'
  55. cat <<-EOREADME
  56. ---
  57. ${badges[*]}
  58. EOREADME
  59. unset IFS
  60. fi
  61. cat <<EOREADME
  62. <!-- THIS FILE IS GENERATED BY $gitRepo/blob/master/generate-repo-stub-readme.sh -->
  63. EOREADME