added example script to upload and share files
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
2ebe95e9f8
commit
de5d5a2344
39
share.sh
Executable file
39
share.sh
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# This is an example on how i use this to upload and share files.
|
||||||
|
# This is tested with minio.
|
||||||
|
# You may need to change some things in here to fit your needs.
|
||||||
|
|
||||||
|
# Change these variables
|
||||||
|
S3_BUCKET="bucketname"
|
||||||
|
S3_ACCESS_KEY="accesskey"
|
||||||
|
S3_SECRET_KEY="secretkey"
|
||||||
|
S3_ENDPOINT="s3.example.com"
|
||||||
|
ENDPOINT="https://share.example.com"
|
||||||
|
API_USERNAME="admin"
|
||||||
|
API_PASSWORD="hunter2"
|
||||||
|
# Dont touch the things below
|
||||||
|
|
||||||
|
UPLOAD_FILE="$1"
|
||||||
|
|
||||||
|
if test -n "$1"; then
|
||||||
|
UPLOAD_FILE=$1
|
||||||
|
elif test ! -t 0; then
|
||||||
|
read -r UPLOAD_FILE
|
||||||
|
else
|
||||||
|
>&2 echo "Provide a file"
|
||||||
|
echo "Usage: $0 <file>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
UPLOAD_FILENAME=$(basename "$UPLOAD_FILE")
|
||||||
|
|
||||||
|
s3cmd -q -s --host "$S3_ENDPOINT" --host-bucket "$S3_ENDPOINT" --access_key "$S3_ACCESS_KEY" --secret_key "$S3_SECRET_KEY" put "$UPLOAD_FILE" s3://$S3_BUCKET/
|
||||||
|
|
||||||
|
SLUG=$(curl -s -u "$API_USERNAME:$API_PASSWORD" -X POST --header "Content-Type: application/json" \
|
||||||
|
--data "{\"key\":\"$UPLOAD_FILENAME\"}" \
|
||||||
|
"$ENDPOINT/api/share" | jq -r ".slug")
|
||||||
|
|
||||||
|
printf "%s/%s\n" "$ENDPOINT" "$SLUG"
|
Loading…
Reference in New Issue
Block a user