1*4882a593Smuzhiyun#!/usr/bin/env bash 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun# We want to catch any unexpected failure, and exit immediately 4*4882a593Smuzhiyunset -e 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun# Download helper for bzr, to be called from the download wrapper script 7*4882a593Smuzhiyun# 8*4882a593Smuzhiyun# Options: 9*4882a593Smuzhiyun# -q Be quiet 10*4882a593Smuzhiyun# -o FILE Generate archive in FILE. 11*4882a593Smuzhiyun# -u URI Clone from repository at URI. 12*4882a593Smuzhiyun# -c CSET Use changeset (or revision) CSET. 13*4882a593Smuzhiyun# -n NAME Use basename NAME. 14*4882a593Smuzhiyun# 15*4882a593Smuzhiyun# Environment: 16*4882a593Smuzhiyun# BZR : the bzr command to call 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun# HACK: Avoid printing logs to output file 20*4882a593Smuzhiyunquiet=-q 21*4882a593Smuzhiyunwhile getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do 22*4882a593Smuzhiyun case "${OPT}" in 23*4882a593Smuzhiyun q) quiet=-q;; 24*4882a593Smuzhiyun o) output="${OPTARG}";; 25*4882a593Smuzhiyun u) uri="${OPTARG}";; 26*4882a593Smuzhiyun c) cset="${OPTARG}";; 27*4882a593Smuzhiyun n) basename="${OPTARG}";; 28*4882a593Smuzhiyun :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;; 29*4882a593Smuzhiyun \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; 30*4882a593Smuzhiyun esac 31*4882a593Smuzhiyundone 32*4882a593Smuzhiyun 33*4882a593Smuzhiyunshift $((OPTIND-1)) # Get rid of our options 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun# Caller needs to single-quote its arguments to prevent them from 36*4882a593Smuzhiyun# being expanded a second time (in case there are spaces in them) 37*4882a593Smuzhiyun_bzr() { 38*4882a593Smuzhiyun if [ -z "${quiet}" ]; then 39*4882a593Smuzhiyun printf '%s ' ${BZR} "${@}"; printf '\n' 40*4882a593Smuzhiyun fi 41*4882a593Smuzhiyun _plain_bzr "$@" 42*4882a593Smuzhiyun} 43*4882a593Smuzhiyun# Note: please keep command below aligned with what is printed above 44*4882a593Smuzhiyun_plain_bzr() { 45*4882a593Smuzhiyun eval ${BZR} "${@}" 46*4882a593Smuzhiyun} 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun# --per-file-timestamps comes with bzr-2.2 (released August 2010), 49*4882a593Smuzhiyun# so only pass it if bzr is recent enough. We compute versions as: 50*4882a593Smuzhiyun# major*1000 + minor 51*4882a593Smuzhiyunbzr_min_version=2002 52*4882a593Smuzhiyunbzr_version=$(($(bzr --version | 53*4882a593Smuzhiyun sed -r -n 's/^Bazaar \(bzr\) ([[:digit:]]+)\.([[:digit:]]+)\..*$/\1*1000+\2/p') 54*4882a593Smuzhiyun )) 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun# If the version is recent enough, we can generate reproducible 57*4882a593Smuzhiyun# archives; otherwise, we just hope for the best (as it would 58*4882a593Smuzhiyun# be downloaded from the BR mirror if what we generate here does 59*4882a593Smuzhiyun# not match the hash we have for it). 60*4882a593Smuzhiyunif [ ${bzr_version} -ge ${bzr_min_version} ]; then 61*4882a593Smuzhiyun timestamp_opt="--per-file-timestamps" 62*4882a593Smuzhiyunfi 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun_bzr export ${quiet} --root="'${basename}/'" --format=tgz \ 65*4882a593Smuzhiyun ${timestamp_opt} - "${@}" "'${uri}'" -r "'${cset}'" \ 66*4882a593Smuzhiyun >"${output}" 67