2
1

svn 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env bash
  2. # We want to catch any unexpected failure, and exit immediately
  3. set -e
  4. # Download helper for svn, to be called from the download wrapper script
  5. #
  6. # Options:
  7. # -q Be quiet.
  8. # -o FILE Generate archive in FILE.
  9. # -u URI Checkout from repository at URI.
  10. # -c REV Use revision REV.
  11. # -n NAME Use basename NAME.
  12. #
  13. # Environment:
  14. # SVN : the svn command to call
  15. verbose=
  16. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  17. case "${OPT}" in
  18. q) verbose=-q;;
  19. o) output="${OPTARG}";;
  20. u) uri="${OPTARG}";;
  21. c) rev="${OPTARG}";;
  22. n) basename="${OPTARG}";;
  23. :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
  24. \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
  25. esac
  26. done
  27. shift $((OPTIND-1)) # Get rid of our options
  28. # Caller needs to single-quote its arguments to prevent them from
  29. # being expanded a second time (in case there are spaces in them)
  30. _svn() {
  31. eval ${SVN} "${@}"
  32. }
  33. _svn export ${verbose} "${@}" "'${uri}@${rev}'" "'${basename}'"
  34. # Get the date of the revision, to generate reproducible archives.
  35. # The output format is YYYY-MM-DDTHH:MM:SS.mmmuuuZ (i.e. always in the
  36. # UTC timezone), which we can feed as-is to the --mtime option for tar.
  37. # In case there is a redirection (e.g. http -> https), just keep the
  38. # last line (svn outputs everything on stdout)
  39. date="$( _svn info --show-item last-changed-date "'${uri}@${rev}'" |tail -n 1 )"
  40. # Generate the archive, sort with the C locale so that it is reproducible.
  41. # We do not want the .svn dir; we keep other .svn files, in case they are the
  42. # only files in their directory.
  43. find "${basename}" -not -type d \
  44. -and -not -path "./.svn/*" >"${output}.list"
  45. LC_ALL=C sort <"${output}.list" >"${output}.list.sorted"
  46. # Create GNU-format tarballs, since that's the format of the tarballs on
  47. # sources.buildroot.org and used in the *.hash files
  48. tar cf - --transform="s#^\./#${basename}/#" \
  49. --numeric-owner --owner=0 --group=0 --mtime="${date}" --format=gnu \
  50. -T "${output}.list.sorted" >"${output}.tar"
  51. gzip -6 -n <"${output}.tar" >"${output}"
  52. rm -f "${output}.list"
  53. rm -f "${output}.list.sorted"