diff --git a/arch_delete_aws4.sh b/arch_delete_aws4.sh index 3508f46..6e42aba 100755 --- a/arch_delete_aws4.sh +++ b/arch_delete_aws4.sh @@ -28,18 +28,21 @@ if [ -z "$ARCH_S3_BUCKET_URL" ]; then exit 1 fi -BUCKET_NAME=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f1 ) -SERVICE=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f2 ) -REGION=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f3 ) -ACCESS_KEY=$( echo -n $ARCH_S3_AUTH | cut -d':' -f1 ) -SECRET_KEY=$( echo -n $ARCH_S3_AUTH | cut -d':' -f2 ) +function _str { printf "%s" $@; } +function _stre { printf $@; } + +BUCKET_NAME=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f1 ) +SERVICE=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f2 ) +REGION=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f3 ) +ACCESS_KEY=$( _str $ARCH_S3_AUTH | cut -d':' -f1 ) +SECRET_KEY=$( _str $ARCH_S3_AUTH | cut -d':' -f2 ) BUCKET_URL=$ARCH_S3_BUCKET_URL _DATE=$( date -u +"%Y%m%d" ) _DTIME=$( date -u +"%Y%m%dT%H%M%SZ" ) _HEADERS="host;x-amz-content-sha256;x-amz-date" -_SHA=$( echo -n "" | sha256sum | cut -d' ' -f1 ) +_SHA=$( _str "" | sha256sum | cut -d' ' -f1 ) # Canon Request _C="DELETE" @@ -56,9 +59,9 @@ _C="$_C\n$_SHA" _S="AWS4-HMAC-SHA256" _S="$_S\n$_DTIME" _S="$_S\n$_DATE/$REGION/$SERVICE/aws4_request" -_S="$_S\n$( echo -ne "$_C" | sha256sum | cut -d' ' -f1 )" +_S="$_S\n$( _stre "$_C" | sha256sum | cut -d' ' -f1 )" -function _HMAC { echo -ne "$2" | openssl dgst -sha256 -hex -mac HMAC -macopt "$1" | cut -d' ' -f2; } +function _HMAC { _stre "$2" | openssl dgst -sha256 -hex -mac HMAC -macopt "$1" | cut -d' ' -f2; } SIG=$( _HMAC "key:AWS4$SECRET_KEY" "$_DATE" ) SIG=$( _HMAC "hexkey:$SIG" "$REGION" ) diff --git a/arch_delete_many_aws4.sh b/arch_delete_many_aws4.sh index 4ad3235..328b191 100755 --- a/arch_delete_many_aws4.sh +++ b/arch_delete_many_aws4.sh @@ -29,22 +29,25 @@ if [ -z "$ARCH_S3_BUCKET_URL" ]; then exit 1 fi +function _str { printf "%s" $@; } +function _stre { printf $@; } + _TEMP=$( mktemp ) function __clean_up { rm $_TEMP; } trap __clean_up EXIT -echo -n "" > $_TEMP +_str "" > $_TEMP sed "s/.\+/\0<\/Key><\/Object>/g" $_LIST_SRC | tr -d '\n' >> $_TEMP if [ $? -ne 0 ]; then exit 1 fi -echo -n "" >> $_TEMP +_str "" >> $_TEMP -BUCKET_NAME=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f1 ) -SERVICE=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f2 ) -REGION=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f3 ) -ACCESS_KEY=$( echo -n $ARCH_S3_AUTH | cut -d':' -f1 ) -SECRET_KEY=$( echo -n $ARCH_S3_AUTH | cut -d':' -f2 ) +BUCKET_NAME=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f1 ) +SERVICE=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f2 ) +REGION=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f3 ) +ACCESS_KEY=$( _str $ARCH_S3_AUTH | cut -d':' -f1 ) +SECRET_KEY=$( _str $ARCH_S3_AUTH | cut -d':' -f2 ) BUCKET_URL=$ARCH_S3_BUCKET_URL @@ -71,9 +74,9 @@ _C="$_C\n$_SHA" _S="AWS4-HMAC-SHA256" _S="$_S\n$_DTIME" _S="$_S\n$_DATE/$REGION/$SERVICE/aws4_request" -_S="$_S\n$( echo -ne "$_C" | sha256sum | cut -d' ' -f1 )" +_S="$_S\n$( _stre "$_C" | sha256sum | cut -d' ' -f1 )" -function _HMAC { echo -ne "$2" | openssl dgst -sha256 -hex -mac HMAC -macopt "$1" | cut -d' ' -f2; } +function _HMAC { _stre "$2" | openssl dgst -sha256 -hex -mac HMAC -macopt "$1" | cut -d' ' -f2; } SIG=$( _HMAC "key:AWS4$SECRET_KEY" "$_DATE" ) SIG=$( _HMAC "hexkey:$SIG" "$REGION" ) diff --git a/arch_download_aws4.sh b/arch_download_aws4.sh index 2c39004..760d582 100755 --- a/arch_download_aws4.sh +++ b/arch_download_aws4.sh @@ -27,18 +27,21 @@ if [ -z "$ARCH_S3_BUCKET_URL" ]; then exit 1 fi -BUCKET_NAME=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f1 ) -SERVICE=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f2 ) -REGION=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f3 ) -ACCESS_KEY=$( echo -n $ARCH_S3_AUTH | cut -d':' -f1 ) -SECRET_KEY=$( echo -n $ARCH_S3_AUTH | cut -d':' -f2 ) +function _str { printf "%s" $@; } +function _stre { printf $@; } + +BUCKET_NAME=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f1 ) +SERVICE=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f2 ) +REGION=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f3 ) +ACCESS_KEY=$( _str $ARCH_S3_AUTH | cut -d':' -f1 ) +SECRET_KEY=$( _str $ARCH_S3_AUTH | cut -d':' -f2 ) BUCKET_URL=$ARCH_S3_BUCKET_URL _DATE=$( date -u +"%Y%m%d" ) _DTIME=$( date -u +"%Y%m%dT%H%M%SZ" ) _HEADERS="host;x-amz-content-sha256;x-amz-date" -_SHA=$( echo -n "" | sha256sum | cut -d' ' -f1 ) +_SHA=$( _str "" | sha256sum | cut -d' ' -f1 ) # Canon Request _C="GET" @@ -55,9 +58,9 @@ _C="$_C\n$_SHA" _S="AWS4-HMAC-SHA256" _S="$_S\n$_DTIME" _S="$_S\n$_DATE/$REGION/$SERVICE/aws4_request" -_S="$_S\n$( echo -ne "$_C" | sha256sum | cut -d' ' -f1 )" +_S="$_S\n$( _stre "$_C" | sha256sum | cut -d' ' -f1 )" -function _HMAC { echo -ne "$2" | openssl dgst -sha256 -hex -mac HMAC -macopt "$1" | cut -d' ' -f2; } +function _HMAC { _stre "$2" | openssl dgst -sha256 -hex -mac HMAC -macopt "$1" | cut -d' ' -f2; } SIG=$( _HMAC "key:AWS4$SECRET_KEY" "$_DATE" ) SIG=$( _HMAC "hexkey:$SIG" "$REGION" ) diff --git a/arch_getacl_aws4.sh b/arch_getacl_aws4.sh index 2e2068e..50f966b 100755 --- a/arch_getacl_aws4.sh +++ b/arch_getacl_aws4.sh @@ -27,18 +27,21 @@ if [ -z "$ARCH_S3_BUCKET_URL" ]; then exit 1 fi -BUCKET_NAME=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f1 ) -SERVICE=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f2 ) -REGION=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f3 ) -ACCESS_KEY=$( echo -n $ARCH_S3_AUTH | cut -d':' -f1 ) -SECRET_KEY=$( echo -n $ARCH_S3_AUTH | cut -d':' -f2 ) +function _str { printf "%s" $@; } +function _stre { printf $@; } + +BUCKET_NAME=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f1 ) +SERVICE=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f2 ) +REGION=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f3 ) +ACCESS_KEY=$( _str $ARCH_S3_AUTH | cut -d':' -f1 ) +SECRET_KEY=$( _str $ARCH_S3_AUTH | cut -d':' -f2 ) BUCKET_URL=$ARCH_S3_BUCKET_URL _DATE=$( date -u +"%Y%m%d" ) _DTIME=$( date -u +"%Y%m%dT%H%M%SZ" ) _HEADERS="host;x-amz-content-sha256;x-amz-date" -_SHA=$( echo -n "" | sha256sum | cut -d' ' -f1 ) +_SHA=$( _str "" | sha256sum | cut -d' ' -f1 ) # Keys should be sorted QPARAMS=( @@ -46,7 +49,7 @@ QPARAMS=( ) function _urlencode { - echo -n $1 | sed "s/\//%2F/g" + _str $1 | sed "s/\//%2F/g" } _L=${#QPARAMS[@]} @@ -78,9 +81,9 @@ _C="$_C\n$_SHA" _S="AWS4-HMAC-SHA256" _S="$_S\n$_DTIME" _S="$_S\n$_DATE/$REGION/$SERVICE/aws4_request" -_S="$_S\n$( echo -ne "$_C" | sha256sum | cut -d' ' -f1 )" +_S="$_S\n$( _stre "$_C" | sha256sum | cut -d' ' -f1 )" -function _HMAC { echo -ne "$2" | openssl dgst -sha256 -hex -mac HMAC -macopt "$1" | cut -d' ' -f2; } +function _HMAC { _stre "$2" | openssl dgst -sha256 -hex -mac HMAC -macopt "$1" | cut -d' ' -f2; } SIG=$( _HMAC "key:AWS4$SECRET_KEY" "$_DATE" ) SIG=$( _HMAC "hexkey:$SIG" "$REGION" ) diff --git a/arch_list_aws4.sh b/arch_list_aws4.sh index 5567b35..1320bf2 100755 --- a/arch_list_aws4.sh +++ b/arch_list_aws4.sh @@ -24,18 +24,21 @@ if [ -z "$ARCH_S3_BUCKET_URL" ]; then exit 1 fi -BUCKET_NAME=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f1 ) -SERVICE=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f2 ) -REGION=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f3 ) -ACCESS_KEY=$( echo -n $ARCH_S3_AUTH | cut -d':' -f1 ) -SECRET_KEY=$( echo -n $ARCH_S3_AUTH | cut -d':' -f2 ) +function _str { printf "%s" $@; } +function _stre { printf $@; } + +BUCKET_NAME=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f1 ) +SERVICE=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f2 ) +REGION=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f3 ) +ACCESS_KEY=$( _str $ARCH_S3_AUTH | cut -d':' -f1 ) +SECRET_KEY=$( _str $ARCH_S3_AUTH | cut -d':' -f2 ) BUCKET_URL=$ARCH_S3_BUCKET_URL _DATE=$( date -u +"%Y%m%d" ) _DTIME=$( date -u +"%Y%m%dT%H%M%SZ" ) _HEADERS="host;x-amz-content-sha256;x-amz-date" -_SHA=$( echo -n "" | sha256sum | cut -d' ' -f1 ) +_SHA=$( _str "" | sha256sum | cut -d' ' -f1 ) _PATH="" # Keys should be sorted @@ -51,7 +54,7 @@ QPARAMS=( ) function _urlencode { - echo -n $1 | sed "s/\//%2F/g" + _str $1 | sed "s/\//%2F/g" } _L=${#QPARAMS[@]} @@ -88,9 +91,9 @@ _C="$_C\n$_SHA" _S="AWS4-HMAC-SHA256" _S="$_S\n$_DTIME" _S="$_S\n$_DATE/$REGION/$SERVICE/aws4_request" -_S="$_S\n$( echo -ne "$_C" | sha256sum | cut -d' ' -f1 )" +_S="$_S\n$( _stre "$_C" | sha256sum | cut -d' ' -f1 )" -function _HMAC { echo -ne "$2" | openssl dgst -sha256 -hex -mac HMAC -macopt "$1" | cut -d' ' -f2; } +function _HMAC { _stre "$2" | openssl dgst -sha256 -hex -mac HMAC -macopt "$1" | cut -d' ' -f2; } SIG=$( _HMAC "key:AWS4$SECRET_KEY" "$_DATE" ) SIG=$( _HMAC "hexkey:$SIG" "$REGION" ) diff --git a/arch_upload_aws4.sh b/arch_upload_aws4.sh index 7236301..5abd020 100755 --- a/arch_upload_aws4.sh +++ b/arch_upload_aws4.sh @@ -36,11 +36,14 @@ if [ -z "$ARCH_S3_BUCKET_URL" ]; then exit 1 fi -BUCKET_NAME=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f1 ) -SERVICE=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f2 ) -REGION=$( echo -n $ARCH_S3_BUCKET_URL | cut -d'.' -f3 ) -ACCESS_KEY=$( echo -n $ARCH_S3_AUTH | cut -d':' -f1 ) -SECRET_KEY=$( echo -n $ARCH_S3_AUTH | cut -d':' -f2 ) +function _str { printf "%s" $@; } +function _stre { printf $@; } + +BUCKET_NAME=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f1 ) +SERVICE=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f2 ) +REGION=$( _str $ARCH_S3_BUCKET_URL | cut -d'.' -f3 ) +ACCESS_KEY=$( _str $ARCH_S3_AUTH | cut -d':' -f1 ) +SECRET_KEY=$( _str $ARCH_S3_AUTH | cut -d':' -f2 ) BUCKET_URL=$ARCH_S3_BUCKET_URL @@ -72,9 +75,9 @@ _C="$_C\n$_FILE_SHA" _S="AWS4-HMAC-SHA256" _S="$_S\n$_DTIME" _S="$_S\n$_DATE/$REGION/$SERVICE/aws4_request" -_S="$_S\n$( echo -ne "$_C" | sha256sum | cut -d' ' -f1 )" +_S="$_S\n$( _stre "$_C" | sha256sum | cut -d' ' -f1 )" -function _HMAC { echo -ne "$2" | openssl dgst -sha256 -hex -mac HMAC -macopt "$1" | cut -d' ' -f2; } +function _HMAC { _stre "$2" | openssl dgst -sha256 -hex -mac HMAC -macopt "$1" | cut -d' ' -f2; } SIG=$( _HMAC "key:AWS4$SECRET_KEY" "$_DATE" ) SIG=$( _HMAC "hexkey:$SIG" "$REGION" )