svn 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env bash
  2. # NOTE: if the output of this backend has to change (e.g. we change what gets
  3. # included in the archive, or we change the format of the archive (e.g. tar
  4. # options, compression ratio or method)), we MUST update the format version
  5. # in the variable BR_FTM_VERSION_svn, in package/pkg-download.mk.
  6. # We want to catch any unexpected failure, and exit immediately
  7. set -e
  8. # Download helper for svn, to be called from the download wrapper script
  9. #
  10. # Options:
  11. # -q Be quiet.
  12. # -o FILE Generate archive in FILE.
  13. # -u URI Checkout from repository at URI.
  14. # -c REV Use revision REV.
  15. # -n NAME Use basename NAME.
  16. # -r Recursive, i.e. use externals
  17. #
  18. # Environment:
  19. # SVN : the svn command to call
  20. # shellcheck disable=SC1090 # Only provides mk_tar_gz()
  21. # shellcheck disable=SC1091
  22. . "${0%/*}/helpers"
  23. quiet=
  24. externals=--ignore-externals
  25. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  26. case "${OPT}" in
  27. q) quiet=-q;;
  28. o) output="${OPTARG}";;
  29. u) uri="${OPTARG}";;
  30. c) rev="${OPTARG}";;
  31. n) basename="${OPTARG}";;
  32. r) externals=;;
  33. :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
  34. \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
  35. esac
  36. done
  37. shift $((OPTIND-1)) # Get rid of our options
  38. # Caller needs to single-quote its arguments to prevent them from
  39. # being expanded a second time (in case there are spaces in them)
  40. _svn() {
  41. if [ -z "${quiet}" ]; then
  42. printf '%s ' "${SVN}" "${@}"; printf '\n'
  43. fi
  44. _plain_svn "$@"
  45. }
  46. # Note: please keep command below aligned with what is printed above
  47. _plain_svn() {
  48. # shellcheck disable=SC2086 # We want word-splitting for SVN
  49. # shellcheck disable=SC2294
  50. eval ${SVN} "${@}"
  51. }
  52. # shellcheck disable=SC2086 # externals and quiet may be empty
  53. _svn export --ignore-keywords ${quiet} ${externals} "${@}" "'${uri}@${rev}'" "'${basename}'"
  54. # For 'svn info', we only need the credentials, if any; other options
  55. # would be invalid, as they are intended for 'svn export'.
  56. # We can also consume the positional parameters, as we'll no longer
  57. # be calling any other remote-reaching svn command.
  58. creds=
  59. while [ ${#} -gt 0 ]; do
  60. case "${1}" in
  61. --username=*) creds+=" ${1}"; shift;;
  62. --password=*) creds+=" ${1}"; shift;;
  63. --username) creds+=" ${1} ${2}"; shift 2;;
  64. --password) creds+=" ${1} ${2}"; shift 2;;
  65. *) shift;;
  66. esac
  67. done
  68. # Get the date of the revision, to generate reproducible archives.
  69. # The output format is YYYY-MM-DDTHH:MM:SS.mmmuuuZ (i.e. always in the
  70. # UTC timezone), which we can feed as-is to the --mtime option for tar.
  71. # In case there is a redirection (e.g. http -> https), just keep the
  72. # last line (svn outputs everything on stdout)
  73. # shellcheck disable=SC2086 # creds may be empty
  74. date="$( LC_ALL=C _plain_svn info ${creds} "'${uri}@${rev}'" \
  75. |sed -r -e '/^Last Changed Date: /!d; s///'
  76. )"
  77. # Generate the archive.
  78. # We did a 'svn export' above, so it's not a working copy (there is no .svn
  79. # directory or file to ignore).
  80. mk_tar_gz "${basename}" "${basename}" "${date}" "${output}"