1#!/usr/bin/env bash 2 3# We want to catch any unexpected failure, and exit immediately 4set -e 5 6# Download helper for hg, to be called from the download wrapper script 7# 8# Options: 9# -q Be quiet. 10# -o FILE Generate archive in FILE. 11# -u URI Clone from repository at URI. 12# -c CSET Use changeset (or revision) CSET. 13# -n NAME Use basename NAME. 14# 15# Environment: 16# HG : the hg command to call 17 18quiet= 19while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do 20 case "${OPT}" in 21 q) quiet=-q;; 22 o) output="${OPTARG}";; 23 u) uri="${OPTARG}";; 24 c) cset="${OPTARG}";; 25 n) basename="${OPTARG}";; 26 :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;; 27 \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; 28 esac 29done 30 31shift $((OPTIND-1)) # Get rid of our options 32 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_hg() { 36 if [ -z "${quiet}" ]; then 37 printf '%s ' ${HG} "${@}"; printf '\n' 38 fi 39 _plain_hg "$@" 40} 41# Note: please keep command below aligned with what is printed above 42_plain_hg() { 43 eval ${HG} "${@}" 44} 45 46_hg clone ${quiet} "${@}" --noupdate "'${uri}'" "'${basename}'" 47 48_plain_hg archive ${quiet} --repository "'${basename}'" --type tgz \ 49 --prefix "'${basename}'" --rev "'${cset}'" \ 50 - >"${output}" 51