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