xref: /OK3568_Linux_fs/buildroot/support/download/svn (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/usr/bin/env bash
2
3# NOTE: if the output of this backend has to change (e.g. we change what gets
4# included in the archive, or we change the format of the archive (e.g. tar
5# options, compression ratio or method)), we MUST update the format version
6# in the variable BR_FTM_VERSION_svn, in package/pkg-download.mk.
7
8# We want to catch any unexpected failure, and exit immediately
9set -e
10
11# Download helper for svn, to be called from the download wrapper script
12#
13# Options:
14#   -q          Be quiet.
15#   -o FILE     Generate archive in FILE.
16#   -u URI      Checkout from repository at URI.
17#   -c REV      Use revision REV.
18#   -n NAME     Use basename NAME.
19#
20# Environment:
21#   SVN      : the svn command to call
22
23. "${0%/*}/helpers"
24
25quiet=
26while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
27    case "${OPT}" in
28    q)  quiet=-q;;
29    o)  output="${OPTARG}";;
30    u)  uri="${OPTARG}";;
31    c)  rev="${OPTARG}";;
32    n)  basename="${OPTARG}";;
33    :)  printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
34    \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
35    esac
36done
37
38shift $((OPTIND-1)) # Get rid of our options
39
40# Caller needs to single-quote its arguments to prevent them from
41# being expanded a second time (in case there are spaces in them)
42_svn() {
43    if [ -z "${quiet}" ]; then
44        printf '%s ' ${SVN} "${@}"; printf '\n'
45    fi
46    _plain_svn "$@"
47}
48# Note: please keep command below aligned with what is printed above
49_plain_svn() {
50    eval ${SVN} "${@}"
51}
52
53_svn export --ignore-keywords ${quiet} "${@}" "'${uri}@${rev}'" "'${basename}'"
54
55# Get the date of the revision, to generate reproducible archives.
56# The output format is YYYY-MM-DDTHH:MM:SS.mmmuuuZ (i.e. always in the
57# UTC timezone), which we can feed as-is to the --mtime option for tar.
58# In case there is a redirection (e.g. http -> https), just keep the
59# last line (svn outputs everything on stdout)
60date="$( _plain_svn info "'${uri}@${rev}'" \
61        |sed -r -e '/^Last Changed Date: /!d; s///'
62       )"
63
64# Generate the archive.
65# We did a 'svn export' above, so it's not a working copy (there is no .svn
66# directory or file to ignore).
67mk_tar_gz "${basename}" "${basename}" "${date}" "${output}"
68