s3-put: Implement bandwidth limit via -b argument.
authormwolson_admin <mwolson_admin@deleuze.hcoop.net>
Sun, 22 Jun 2008 23:57:51 +0000 (19:57 -0400)
committermwolson_admin <mwolson_admin@deleuze.hcoop.net>
Sun, 22 Jun 2008 23:57:51 +0000 (19:57 -0400)
s3-put

diff --git a/s3-put b/s3-put
index 87af77b..e96a108 100755 (executable)
--- a/s3-put
+++ b/s3-put
@@ -25,7 +25,7 @@ function printHelpAndExit
        printf "%s: version %s\n" "$weAreKnownAs" "$version"
        printf "Part of s3-bash. Latest version is at %s\n" 'http://code.google.com/p/s3-bash/'
        printf "Usage %s: -h\n" "$weAreKnownAs"
-       printf "Usage %s: [-vS] [-H file] [-a file] -k key -s file -T file url\n" "$weAreKnownAs"
+       printf "Usage %s: [-vS] [-H file] [-a file] [-b speed] -k key -s file -T file url\n" "$weAreKnownAs"
        printf " Option\tType\tRequirement\tDescription\n"
        printf " -h\t\tprecedent\tprint this help\n"
        printf " -v\t\toptional\tverbose output\n"
@@ -35,6 +35,7 @@ function printHelpAndExit
        printf " -S\t\toptional\tUse https\n"
        printf " -H\tfile\toptional\tFile to write response headers to\n"
        printf " -a\tfile\toptional\tFile to read Amazon custom headers from (X-Amz-Date is not allowed)\n"
+       printf " -b\tspeed\toptional\tBandwidth limit in units/sec\n"
        printf " -c\tMIME\toptional\tMIME Content type. Default is text/plain\n"
        printf " \turl\tmandatory\trelative url including bucket name and leading slash, eg /bucket/path/to/object?acl. Assumed to be already encoded\n"
        printf "\n"
@@ -54,6 +55,7 @@ function parseOptions
        fileToUpload=""
        dumpHeaderFile="/dev/null"
        amazonHeaderFile="/dev/null"
+        bwlimit=""
        contentType="text/plain"
        while getopts "hvk:s:SH:T:a:c:" optionName; do          
                case "$optionName" in
@@ -68,6 +70,7 @@ function parseOptions
                        H)      dumpHeaderFile="$OPTARG";;
                        T)      fileToUpload="$OPTARG";;
                        a)      amazonHeaderFile="$OPTARG";;
+                       b)      bwlimit="--limit-rate $OPTARG";;
                        c)      contentType="$OPTARG";;
                        [?])    printErrorHelpAndExit "Option not recognised" $userSpecifiedDataErrorExitCode;;
                esac
@@ -97,10 +100,10 @@ function prepareToRunCurl
        readonly verb="PUT"
        if [ ! "-" = "$fileToUpload" ]; then
                readonly contentMD5="$(base64EncodedMD5 "$fileToUpload")"
-               readonly verbToPass="-T \"$fileToUpload\""
+               readonly verbToPass="-T \"$fileToUpload\" $bwlimit"
        else
                readonly contentMD5=""
-               readonly verbToPass="-T -"
+               readonly verbToPass="-T - $bwlimit"
        fi
 }