1#!/usr/bin/env bash 2 3# We want to catch any unexpected failure, and exit immediately 4set -e 5 6# Download helper for cvs, 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 Checkout from repository at URI. 12# -c REV Use revision REV. 13# -N RAWNAME Use rawname (aka module name) RAWNAME. 14# -n NAME Use basename NAME. 15# 16# Environment: 17# CVS : the cvs command to call 18 19quiet= 20while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do 21 case "${OPT}" in 22 q) quiet=-Q;; 23 o) output="${OPTARG}";; 24 u) uri="${OPTARG#*://}";; 25 c) rev="${OPTARG}";; 26 N) rawname="${OPTARG}";; 27 n) basename="${OPTARG}";; 28 :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;; 29 \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;; 30 esac 31done 32 33shift $((OPTIND-1)) # Get rid of our options 34 35# Caller needs to single-quote its arguments to prevent them from 36# being expanded a second time (in case there are spaces in them). 37# If the CVS server is deadlocked, the client will never return (cfr. 38# http://autobuild.buildroot.net/results/23d/23d1034b33d0354de15de2ec4a8ccd0603e8db78/build-end.log 39# ). Since nobody sane will put large code bases in CVS, a timeout of 40# 10 minutes should do the trick. 41_cvs() { 42 if [ -z "${quiet}" ]; then 43 printf '%s ' timeout 10m ${CVS} "${@}"; printf '\n' 44 fi 45 _plain_cvs "$@" 46} 47# Note: please keep command below aligned with what is printed above 48_plain_cvs() { 49 eval timeout 10m ${CVS} "${@}" 50} 51 52if [[ ${rev} =~ ^[0-9] ]]; then 53 # Date, because a tag or a branch cannot begin with a number 54 select="-D" 55else 56 # Tag or branch 57 select="-r" 58fi 59 60# The absence of an initial : on ${uri} means access method undefined 61if [[ ! "${uri}" =~ ^: ]]; then 62 # defaults to anonymous pserver 63 uri=":pserver:anonymous@${uri}" 64fi 65 66export TZ=UTC 67_cvs ${quiet} -z3 -d"'${uri}'" \ 68 co "${@}" -d "'${basename}'" ${select} "'${rev}'" -P "'${rawname}'" 69 70tar czf "${output}" "${basename}" 71