svn 2.2 KB

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