svn 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. . "${0%/*}/helpers"
  22. quiet=
  23. externals=--ignore-externals
  24. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  25. case "${OPT}" in
  26. q) quiet=-q;;
  27. o) output="${OPTARG}";;
  28. u) uri="${OPTARG}";;
  29. c) rev="${OPTARG}";;
  30. n) basename="${OPTARG}";;
  31. r) externals=;;
  32. :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
  33. \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
  34. esac
  35. done
  36. shift $((OPTIND-1)) # Get rid of our options
  37. # Caller needs to single-quote its arguments to prevent them from
  38. # being expanded a second time (in case there are spaces in them)
  39. _svn() {
  40. if [ -z "${quiet}" ]; then
  41. printf '%s ' "${SVN}" "${@}"; printf '\n'
  42. fi
  43. _plain_svn "$@"
  44. }
  45. # Note: please keep command below aligned with what is printed above
  46. _plain_svn() {
  47. # shellcheck disable=SC2086 # We want word-splitting for SVN
  48. eval ${SVN} "${@}"
  49. }
  50. # shellcheck disable=SC2086 # externals and quiet may be empty
  51. _svn export --ignore-keywords ${quiet} ${externals} "${@}" "'${uri}@${rev}'" "'${basename}'"
  52. # For 'svn info', we only need the credentials, if any; other options
  53. # would be invalid, as they are intended for 'svn export'.
  54. # We can also consume the positional parameters, as we'll no longer
  55. # be calling any other remote-reaching svn command.
  56. creds=
  57. while [ ${#} -gt 0 ]; do
  58. case "${1}" in
  59. --username=*) creds+=" ${1}"; shift;;
  60. --password=*) creds+=" ${1}"; shift;;
  61. --username) creds+=" ${1} ${2}"; shift 2;;
  62. --password) creds+=" ${1} ${2}"; shift 2;;
  63. *) shift;;
  64. esac
  65. done
  66. # Get the date of the revision, to generate reproducible archives.
  67. # The output format is YYYY-MM-DDTHH:MM:SS.mmmuuuZ (i.e. always in the
  68. # UTC timezone), which we can feed as-is to the --mtime option for tar.
  69. # In case there is a redirection (e.g. http -> https), just keep the
  70. # last line (svn outputs everything on stdout)
  71. # shellcheck disable=SC2086 # creds may be empty
  72. date="$( LC_ALL=C _plain_svn info ${creds} "'${uri}@${rev}'" \
  73. |sed -r -e '/^Last Changed Date: /!d; s///'
  74. )"
  75. # Generate the archive.
  76. # We did a 'svn export' above, so it's not a working copy (there is no .svn
  77. # directory or file to ignore).
  78. mk_tar_gz "${basename}" "${basename}" "${date}" "${output}"