X-Git-Url: http://git.hcoop.net/clinton/scripts.git/blobdiff_plain/f8c2d5c6fcd9dc3b1e003cde9a87dc0af9338737..8862af6d48b78cf6cf055dec506e02704dbf141c:/s3 diff --git a/s3 b/s3 index 9132845..9601162 100755 --- a/s3 +++ b/s3 @@ -3,7 +3,10 @@ # 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=7 +ATTEMPT_WAIT=10 # print a message and bail die() { @@ -46,7 +49,7 @@ check_hmac() { } check_deps() { - check_dep openssl date cat grep curl + check_dep openssl date cat grep check_hmac check_s3 } @@ -123,7 +126,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,16 +159,24 @@ 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 $ATTEMPTS; 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; + sleep $ATTEMPT_WAIT + echo "Retrying ..." + done + return $ret } s3_put() { # $1 = remote bucket to put it into # $2 = remote name to put # $3 = file to put. This must be present if $2 is. - $ $4 = bandwidth limit. + # $4 = bandwidth limit. s3_curl PUT "${1}" "${2}" "${3:-${2}}" "${4}" return $? } @@ -175,7 +186,7 @@ s3_get() { # $2 = remote file to get # $3 = local file to get into. Will be overwritten if it exists. # If this contains a path, that path must exist before calling this. - $ $4 = bandwidth limit. + # $4 = bandwidth limit. s3_curl GET "${1}" "${2}" "${3:-${2}}" "${4}" return $? }