diff --git a/get_sources.sh b/get_sources.sh index 890cc35..3ed0466 100755 --- a/get_sources.sh +++ b/get_sources.sh @@ -77,7 +77,7 @@ while [[ 0 -eq 0 ]]; do shift ;; -b ) - # Check this particular branch + # Check this particular branch BRANCH=$2 shift shift @@ -173,9 +173,19 @@ if [[ -s sources ]]; then for br in "${branches[@]}" do br=$(echo ${br}| sed -e s'|remotes/origin/||') + # Try the branch-specific lookaside structure url="${SURL}/$pkgname/${br}/$hash" echo "Retrieving ${url}" - curl -L ${QUIET} -f "${url}" -o "$tarball" && break + HTTP_CODE=$(curl -L ${QUIET} -H Pragma: -o "./$tarball" -R -S --fail --retry 5 "${url}" --write-out "%{http_code}" || true) + echo "Returned ${HTTP_CODE}" + if [[ ${HTTP_CODE} -gt 199 && ${HTTP_CODE} -lt 300 ]] ; then + echo "bailing" + break + fi + # Try the hash-specific lookaside structure + url="${SURL}/$pkgname/$tarball/$hashtype/$hash/$tarball" + echo "Retrieving ${url}" + curl -L ${QUIET} -H Pragma: -o "./$tarball" -R -S --fail --retry 5 "${url}" && break done else echo "$filename exists. skipping" @@ -231,21 +241,22 @@ else # zero byte file touch ${fname} else + hashType=$(weakHashDetection ${fsha}) + if [ "${hashType}" == "unknown" ]; then + echo 'Failure: Hash type unknown.' >&2 + exit 1; + fi + hashName=$(echo ${hashType}| sed -e s'|sum||') + if [ ${CHECK} -eq 1 ]; then - hashType=$(weakHashDetection ${fsha}) - if [ "${hashType}" == "unknown" ]; then - echo 'Failure: Hash type unknown.' >&2 + which ${hashType} >/dev/null 2>&1 + if [[ $? -ne 0 ]]; then + echo "Failure: You need ${hashType} in PATH." >&2 exit 1; - else - which ${hashType} >/dev/null 2>&1 - if [[ $? -ne 0 ]]; then - echo "Failure: You need ${hashType} in PATH." >&2 - exit 1; - fi fi fi if [ -e ${fname} -a ${CHECK} -eq 1 ]; then - # check hash sum and force download if wrong + # check hash sum and force download if wrong downsum=$(${hashType} ${fname} | awk '{print $1}') if [ "${fsha}" != "${downsum}" ]; then rm -f ${fname} @@ -255,9 +266,19 @@ else for br in "${branches[@]}" do br=$(echo ${br}| sed -e s'|remotes/origin/||') + # Try the branch-specific lookaside structure url="${SURL}/${pn}/${br}/${fsha}" echo "Retrieving ${url}" - curl -L ${QUIET} -f "${url}" -o "${fname}" && break + HTTP_CODE=$(curl -L ${QUIET} -H Pragma: -o "${fname}" -R -S --fail --retry 5 "${url}" --write-out "%{http_code}" || true) + echo "Returned ${HTTP_CODE}" + if [[ ${HTTP_CODE} -gt 199 && ${HTTP_CODE} -lt 300 ]] ; then + echo "bailing" + break + fi + # Try the hash-specific lookaside structure + url="${SURL}/$pn/$fname/${hashName}/$fsha/$fname" + echo "Retrieving ${url}" + curl -L ${QUIET} -H Pragma: -o "${fname}" -R -S --fail --retry 5 "${url}" && break done else echo "${fname} exists. skipping"