svn 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. verbose=
  21. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  22. case "${OPT}" in
  23. q) verbose=-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. eval ${SVN} "${@}"
  37. }
  38. _svn export --ignore-keywords ${verbose} "${@}" "'${uri}@${rev}'" "'${basename}'"
  39. # Get the date of the revision, to generate reproducible archives.
  40. # The output format is YYYY-MM-DDTHH:MM:SS.mmmuuuZ (i.e. always in the
  41. # UTC timezone), which we can feed as-is to the --mtime option for tar.
  42. # In case there is a redirection (e.g. http -> https), just keep the
  43. # last line (svn outputs everything on stdout)
  44. date="$( _svn info "'${uri}@${rev}'" \
  45. |sed -r -e '/^Last Changed Date: /!d; s///'
  46. )"
  47. # Generate the archive.
  48. # We did a 'svn export' above, so it's not a working copy (there is no .svn
  49. # directory or file to ignore).
  50. mk_tar_gz "${basename}" "${basename}" "${date}" "${output}"