svn 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #
  17. # Environment:
  18. # SVN : the svn command to call
  19. # shellcheck disable=SC1090 # Only provides mk_tar_gz()
  20. . "${0%/*}/helpers"
  21. quiet=
  22. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  23. case "${OPT}" in
  24. q) quiet=-q;;
  25. o) output="${OPTARG}";;
  26. u) uri="${OPTARG}";;
  27. c) rev="${OPTARG}";;
  28. n) basename="${OPTARG}";;
  29. :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
  30. \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
  31. esac
  32. done
  33. shift $((OPTIND-1)) # Get rid of our options
  34. # Caller needs to single-quote its arguments to prevent them from
  35. # being expanded a second time (in case there are spaces in them)
  36. _svn() {
  37. if [ -z "${quiet}" ]; then
  38. printf '%s ' "${SVN}" "${@}"; printf '\n'
  39. fi
  40. _plain_svn "$@"
  41. }
  42. # Note: please keep command below aligned with what is printed above
  43. _plain_svn() {
  44. # shellcheck disable=SC2086 # We want word-splitting for SVN
  45. eval ${SVN} "${@}"
  46. }
  47. _svn export --ignore-keywords ${quiet} "${@}" "'${uri}@${rev}'" "'${basename}'"
  48. # Get the date of the revision, to generate reproducible archives.
  49. # The output format is YYYY-MM-DDTHH:MM:SS.mmmuuuZ (i.e. always in the
  50. # UTC timezone), which we can feed as-is to the --mtime option for tar.
  51. # In case there is a redirection (e.g. http -> https), just keep the
  52. # last line (svn outputs everything on stdout)
  53. date="$( _plain_svn info "'${uri}@${rev}'" \
  54. |sed -r -e '/^Last Changed Date: /!d; s///'
  55. )"
  56. # Generate the archive.
  57. # We did a 'svn export' above, so it's not a working copy (there is no .svn
  58. # directory or file to ignore).
  59. mk_tar_gz "${basename}" "${basename}" "${date}" "${output}"