diff options
| author | jason | 2023-10-06 17:10:02 -0600 |
|---|---|---|
| committer | jason | 2023-10-06 17:10:02 -0600 |
| commit | 53f807186d90b98645d684dfc681f166e9326ae0 (patch) | |
| tree | bf00603d4b158f77e945ec930b7d2ca9444bfd09 /scripts | |
| parent | 2e1da5dea91c3ccac5e32be77f0c06e27cff727a (diff) | |
| download | dotfiles-53f807186d90b98645d684dfc681f166e9326ae0.tar.gz dotfiles-53f807186d90b98645d684dfc681f166e9326ae0.zip | |
add linode/s3 file upload script
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/bin/linode-uploader | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/bin/linode-uploader b/scripts/bin/linode-uploader new file mode 100755 index 0000000..5ae751e --- /dev/null +++ b/scripts/bin/linode-uploader | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | #!/usr/bin/env /bin/sh | ||
| 2 | file=$1 | ||
| 3 | |||
| 4 | if [[ ! -f $file ]]; then | ||
| 5 | echo "Invalid File: ${file}" | ||
| 6 | exit 1 | ||
| 7 | fi | ||
| 8 | |||
| 9 | extension=$(basename "${file}" | cut -d'.' -f2) | ||
| 10 | filename="$(openssl rand -hex 8).${extension}" | ||
| 11 | |||
| 12 | ACCESS_KEY= | ||
| 13 | SECRET_KEY= | ||
| 14 | BUCKET=c.r8x.net | ||
| 15 | VANITY_URL=https://c.r8x.net | ||
| 16 | |||
| 17 | RESOURCE="/${BUCKET}/${filename}" | ||
| 18 | DATE=$(TZ=UTC date -j "+%a, %d %b %Y %T %z") | ||
| 19 | CONTENT_TYPE=$(file --mime-type -b ${file}) | ||
| 20 | ACL="x-amz-acl:public-read" | ||
| 21 | STRING_TO_SIGN="PUT\n\n${CONTENT_TYPE}\n${DATE}\n${ACL}\n${RESOURCE}" | ||
| 22 | SIGNATURE=$(echo -en ${STRING_TO_SIGN} | openssl sha1 -hmac ${SECRET_KEY} -binary | openssl base64) | ||
| 23 | |||
| 24 | HOST="eu-central-1.linodeobjects.com" | ||
| 25 | |||
| 26 | curl -X PUT -T "${file}" \ | ||
| 27 | -H "Date: ${DATE}" \ | ||
| 28 | -H "Content-Type: ${CONTENT_TYPE}" \ | ||
| 29 | -H "${ACL}" \ | ||
| 30 | -H "Authorization: AWS ${ACCESS_KEY}:${SIGNATURE}" \ | ||
| 31 | https://${HOST}${RESOURCE} | ||
| 32 | echo "${VANITY_URL}/${filename}" | tr -d '\n' | xsel -b | ||
| 33 | |||