aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorjason2023-10-06 17:10:02 -0600
committerjason2023-10-06 17:10:02 -0600
commit53f807186d90b98645d684dfc681f166e9326ae0 (patch)
treebf00603d4b158f77e945ec930b7d2ca9444bfd09 /scripts
parent2e1da5dea91c3ccac5e32be77f0c06e27cff727a (diff)
downloaddotfiles-53f807186d90b98645d684dfc681f166e9326ae0.tar.gz
dotfiles-53f807186d90b98645d684dfc681f166e9326ae0.zip
add linode/s3 file upload script
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/bin/linode-uploader33
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
2file=$1
3
4if [[ ! -f $file ]]; then
5 echo "Invalid File: ${file}"
6 exit 1
7fi
8
9extension=$(basename "${file}" | cut -d'.' -f2)
10filename="$(openssl rand -hex 8).${extension}"
11
12ACCESS_KEY=
13SECRET_KEY=
14BUCKET=c.r8x.net
15VANITY_URL=https://c.r8x.net
16
17RESOURCE="/${BUCKET}/${filename}"
18DATE=$(TZ=UTC date -j "+%a, %d %b %Y %T %z")
19CONTENT_TYPE=$(file --mime-type -b ${file})
20ACL="x-amz-acl:public-read"
21STRING_TO_SIGN="PUT\n\n${CONTENT_TYPE}\n${DATE}\n${ACL}\n${RESOURCE}"
22SIGNATURE=$(echo -en ${STRING_TO_SIGN} | openssl sha1 -hmac ${SECRET_KEY} -binary | openssl base64)
23
24HOST="eu-central-1.linodeobjects.com"
25
26curl -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}
32echo "${VANITY_URL}/${filename}" | tr -d '\n' | xsel -b
33