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 cp, to be called from the download wrapper script 7*4882a593Smuzhiyun# 8*4882a593Smuzhiyun# Options: 9*4882a593Smuzhiyun# -q Be quiet. 10*4882a593Smuzhiyun# -o FILE Copy to file FILE. 11*4882a593Smuzhiyun# -f FILE Copy from basename file FILE. 12*4882a593Smuzhiyun# -u DIR Copy from FILE in DIR. 13*4882a593Smuzhiyun# 14*4882a593Smuzhiyun# Environment: 15*4882a593Smuzhiyun# LOCALFILES: the cp command to call 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun# 'cp' usually does not print anything on its stdout, whereas the 18*4882a593Smuzhiyun# other download backends, even if not verbose, at least print some 19*4882a593Smuzhiyun# progress information. 20*4882a593Smuzhiyun# Make 'cp' verbose by default, so it behaves a bit like the others. 21*4882a593Smuzhiyunverbose=-v 22*4882a593Smuzhiyun 23*4882a593Smuzhiyunwhile getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do 24*4882a593Smuzhiyun case "${OPT}" in 25*4882a593Smuzhiyun q) verbose=;; 26*4882a593Smuzhiyun o) output="${OPTARG}";; 27*4882a593Smuzhiyun f) file="${OPTARG}";; 28*4882a593Smuzhiyun u) dir="${OPTARG}";; 29*4882a593Smuzhiyun :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;; 30*4882a593Smuzhiyun \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; 31*4882a593Smuzhiyun esac 32*4882a593Smuzhiyundone 33*4882a593Smuzhiyun 34*4882a593Smuzhiyunshift $((OPTIND-1)) # Get rid of our options 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun# Caller needs to single-quote its arguments to prevent them from 37*4882a593Smuzhiyun# being expanded a second time (in case there are spaces in them) 38*4882a593Smuzhiyun_localfiles() { 39*4882a593Smuzhiyun if [ -n "${verbose}" ]; then 40*4882a593Smuzhiyun printf '%s ' ${LOCALFILES} "${@}"; printf '\n' 41*4882a593Smuzhiyun fi 42*4882a593Smuzhiyun _plain_localfiles "$@" 43*4882a593Smuzhiyun} 44*4882a593Smuzhiyun# Note: please keep command below aligned with what is printed above 45*4882a593Smuzhiyun_plain_localfiles() { 46*4882a593Smuzhiyun eval ${LOCALFILES} "${@}" 47*4882a593Smuzhiyun} 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun_localfiles ${verbose} "'${dir##file://}/${file}'" "'${output}'" 50