cvs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. verbose=
  17. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  18. case "${OPT}" in
  19. q) verbose=-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. eval timeout 10m ${CVS} "${@}"
  38. }
  39. if [[ ${rev} =~ ^[0-9] ]]; then
  40. # Date, because a tag or a branch cannot begin with a number
  41. select="-D"
  42. else
  43. # Tag or branch
  44. select="-r"
  45. fi
  46. # The absence of an initial : on ${uri} means access method undefined
  47. if [[ ! "${uri}" =~ ^: ]]; then
  48. # defaults to anonymous pserver
  49. uri=":pserver:anonymous@${uri}"
  50. fi
  51. export TZ=UTC
  52. _cvs ${verbose} -z3 -d"'${uri}'" \
  53. co "${@}" -d "'${basename}'" ${select} "'${rev}'" -P "'${rawname}'"
  54. tar czf "${output}" "${basename}"