support/misc: Adding Vagrant file for provisioning
[buildroot-gz.git] / support / download / bzr
blobe18b01f39c9c1da54054233b64b84717aef453f0
1 #!/usr/bin/env bash
3 # We want to catch any unexpected failure, and exit immediately
4 set -e
6 # Download helper for bzr, to be called from the download wrapper script
8 # Call it as:
9 # .../bzr [-q] OUT_FILE REPO_URL REV BASENAME
11 # Environment:
12 # BZR : the bzr command to call
15 verbose=
16 while getopts :q OPT; do
17 case "${OPT}" in
18 q) verbose=-q;;
19 \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
20 esac
21 done
22 shift $((OPTIND-1))
24 output="${1}"
25 repo="${2}"
26 rev="${3}"
27 basename="${4}"
29 # Caller needs to single-quote its arguments to prevent them from
30 # being expanded a second time (in case there are spaces in them)
31 _bzr() {
32 eval ${BZR} "${@}"
35 # --per-file-timestamps comes with bzr-2.2 (released August 2010),
36 # so only pass it if bzr is recent enough. We compute versions as:
37 # major*1000 + minor
38 bzr_min_version=2002
39 bzr_version=$(($(bzr --version |
40 sed -r -n 's/^Bazaar \(bzr\) ([[:digit:]]+)\.([[:digit:]]+)\..*$/\1*1000+\2/p')
43 # If the version is recent enough, we can generate reproducible
44 # archives; otherwise, we just hope for the best (as it would
45 # be downloaded from the BR mirror if what we generate here does
46 # not match the hash we have for it).
47 if [ ${bzr_version} -ge ${bzr_min_version} ]; then
48 timestamp_opt="--per-file-timestamps"
51 _bzr export ${verbose} --root="'${basename}/'" --format=tgz \
52 ${timestamp_opt} - "'${repo}'" -r "'${rev}'" \
53 >"${output}"