cvs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env bash
  2. # We want to catch any unexpected failure, and exit immediately
  3. set -e
  4. # Download helper for cvs, to be called from the download wrapper script
  5. #
  6. # Options:
  7. # -q Be quiet
  8. # -o FILE Generate archive in FILE.
  9. # -u URI Checkout from repository at URI.
  10. # -c REV Use revision REV.
  11. # -N RAWNAME Use rawname (aka module name) RAWNAME.
  12. # -n NAME Use basename NAME.
  13. #
  14. # Environment:
  15. # CVS : the cvs command to call
  16. quiet=
  17. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  18. case "${OPT}" in
  19. q) quiet=-Q;;
  20. o) output="${OPTARG}";;
  21. u) uri="${OPTARG#*://}";;
  22. c) rev="${OPTARG}";;
  23. N) rawname="${OPTARG}";;
  24. n) basename="${OPTARG}";;
  25. :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
  26. \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
  27. esac
  28. done
  29. shift $((OPTIND-1)) # Get rid of our options
  30. # Caller needs to single-quote its arguments to prevent them from
  31. # being expanded a second time (in case there are spaces in them).
  32. # If the CVS server is deadlocked, the client will never return (cfr.
  33. # http://autobuild.buildroot.net/results/23d/23d1034b33d0354de15de2ec4a8ccd0603e8db78/build-end.log
  34. # ). Since nobody sane will put large code bases in CVS, a timeout of
  35. # 10 minutes should do the trick.
  36. _cvs() {
  37. if [ -z "${quiet}" ]; then
  38. printf '%s ' timeout 10m ${CVS} "${@}"; printf '\n'
  39. fi
  40. _plain_cvs "$@"
  41. }
  42. # Note: please keep command below aligned with what is printed above
  43. _plain_cvs() {
  44. eval timeout 10m ${CVS} "${@}"
  45. }
  46. if [[ ${rev} =~ ^[0-9] ]]; then
  47. # Date, because a tag or a branch cannot begin with a number
  48. select="-D"
  49. else
  50. # Tag or branch
  51. select="-r"
  52. fi
  53. # The absence of an initial : on ${uri} means access method undefined
  54. if [[ ! "${uri}" =~ ^: ]]; then
  55. # defaults to anonymous pserver
  56. uri=":pserver:anonymous@${uri}"
  57. fi
  58. export TZ=UTC
  59. _cvs ${quiet} -z3 -d"'${uri}'" \
  60. co "${@}" -d "'${basename}'" ${select} "'${rev}'" -P "'${rawname}'"
  61. tar czf "${output}" "${basename}"