xref: /OK3568_Linux_fs/buildroot/support/download/file (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/usr/bin/env bash
2
3# We want to catch any unexpected failure, and exit immediately
4set -e
5
6# Download helper for cp, to be called from the download wrapper script
7#
8# Options:
9#   -q          Be quiet.
10#   -o FILE     Copy to file FILE.
11#   -f FILE     Copy from basename file FILE.
12#   -u DIR      Copy from FILE in DIR.
13#
14# Environment:
15#   LOCALFILES: the cp command to call
16
17# 'cp' usually does not print anything on its stdout, whereas the
18# other download backends, even if not verbose, at least print some
19# progress information.
20# Make 'cp' verbose by default, so it behaves a bit like the others.
21verbose=-v
22
23while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
24    case "${OPT}" in
25    q)  verbose=;;
26    o)  output="${OPTARG}";;
27    f)  file="${OPTARG}";;
28    u)  dir="${OPTARG}";;
29    :)  printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
30    \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
31    esac
32done
33
34shift $((OPTIND-1)) # Get rid of our options
35
36# Caller needs to single-quote its arguments to prevent them from
37# being expanded a second time (in case there are spaces in them)
38_localfiles() {
39    if [ -n "${verbose}" ]; then
40        printf '%s ' ${LOCALFILES} "${@}"; printf '\n'
41    fi
42    _plain_localfiles "$@"
43}
44# Note: please keep command below aligned with what is printed above
45_plain_localfiles() {
46    eval ${LOCALFILES} "${@}"
47}
48
49_localfiles ${verbose} "'${dir##file://}/${file}'" "'${output}'"
50