X-Git-Url: https://git.hcoop.net/hcoop/scripts.git/blobdiff_plain/c2b40851a0c6affab67bef42302a3af882491f96..7cc8af5787fcfc12705dfcf541eeea10e325f7dd:/s3?ds=sidebyside diff --git a/s3 b/s3 index 4f26efe..9ca45f8 100755 --- a/s3 +++ b/s3 @@ -3,7 +3,9 @@ # Licensed under the terms of the GNU GPL v2 # Copyright 2007 Victor Lowther +CURL=/home/mwolson_admin/bin/curl HMAC=$(dirname $0)/s3-hmac +ATTEMPTS=3 # print a message and bail die() { @@ -46,7 +48,7 @@ check_hmac() { } check_deps() { - check_dep openssl date cat grep curl + check_dep openssl date cat grep check_hmac check_s3 } @@ -123,7 +125,7 @@ s3_curl() { # $3 = remote name # $4 = local name. # $5 = bandwidth limit. - local bucket remote date sig md5 arg inout headers + local bucket remote date sig md5 arg inout headers tries ret # header handling is kinda fugly, but it works. bucket="${2:+/${2}}/" # slashify the bucket remote="$(urlenc "${3}")" # if you don't, strange things may happen. @@ -156,9 +158,15 @@ s3_curl() { headers[${#headers[@]}]="Authorization: AWS ${S3_ACCESS_KEY_ID}:${sig}" headers[${#headers[@]}]="Date: ${date}" [[ ${md5} ]] && headers[${#headers[@]}]="Content-MD5: ${md5}" - curl ${arg} "${inout}" ${stdopts} -K <(curl_headers "${headers[@]}") \ + tries=0 + while test $tries -lt 3; do + tries=$(expr $tries + 1) + $CURL ${arg} "${inout}" ${stdopts} -K <(curl_headers "${headers[@]}") \ "http://s3.amazonaws.com${bucket}${remote}" - return $? + ret=$? + test $ret -eq 0 && break; + done + return $ret } s3_put() {