1#!/usr/bin/env bash 2 3# We want to catch any unexpected failure, and exit immediately 4set -e 5 6# Download helper for scp, to be called from the download wrapper script 7# 8# Options: 9# -q Be quiet. 10# -o FILE Copy to local file FILE. 11# -f FILE Copy from remote file FILE. 12# -u URI Download file at URI. 13# 14# Environment: 15# SCP : the scp command to call 16 17quiet= 18while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do 19 case "${OPT}" in 20 q) quiet=-q;; 21 o) output="${OPTARG}";; 22 f) filename="${OPTARG}";; 23 u) uri="${OPTARG}";; 24 :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;; 25 \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; 26 esac 27done 28 29shift $((OPTIND-1)) # Get rid of our options 30 31# Caller needs to single-quote its arguments to prevent them from 32# being expanded a second time (in case there are spaces in them) 33_scp() { 34 if [ -z "${quiet}" ]; then 35 printf '%s ' ${SCP} "${@}"; printf '\n' 36 fi 37 _plain_scp "$@" 38} 39# Note: please keep command below aligned with what is printed above 40_plain_scp() { 41 eval ${SCP} "${@}" 42} 43 44# Remove any scheme prefix 45uri="${uri##scp://}" 46 47_scp ${quiet} "${@}" "'${uri}/${filename}'" "'${output}'" 48