#! /bin/bash
## $Id: s3-multipart-etags,v 1.1 2020/02/10 02:15:38 homer Exp $

## Note: this script will alter the aws-cli config profile named below.
##
## Must have a profile named according to $AWS_PROFILE, that can write
## to the bucket and prefix named in $BASE:
export AWS_PROFILE=s3-multipart-etag-test
BASE=s3://multipart-etag-test/test

trap rm-tmp EXIT
rm-tmp() { rm -v "$TMP"; }
TMP=zero.bin.tmp

SIZE=64M
THRE=32MB

echo "Create $SIZE file \`$TMP'..."
head -c "$SIZE" /dev/zero >"$TMP"

put() {
    aws s3 cp "$TMP" "$@"
}

## Disable multi-part upload and push file single-part
aws configure set profile."$AWS_PROFILE".s3.multipart_threshold "5GB"
put "$BASE/test-$SIZE-single-part.bin"

## Push multiple objects with identical contents but various part counts
aws configure set profile."$AWS_PROFILE".s3.multipart_threshold "$THRE"
for megabytes in 8 16 32 64; do
    aws configure set \
        profile."$AWS_PROFILE".s3.multipart_chunksize "$megabytes"MB
    put "$BASE/test-$SIZE-chunk-size=$megabytes"M
done
