This commit is contained in:
parent
da82558722
commit
b75f29b39b
23
sos/sos
23
sos/sos
@ -9,6 +9,14 @@ set -euo pipefail
|
||||
# this will upload the file to the server, and return the download URL
|
||||
|
||||
|
||||
# get dropshell
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
curl -L -s -o "${TEMP_DIR}/dropshell" "https://getbin.xyz/dropshell"
|
||||
chmod +x "${TEMP_DIR}/dropshell"
|
||||
trap 'rm -rf "${TEMP_DIR}"' EXIT
|
||||
DROPSHELL="${TEMP_DIR}/dropshell"
|
||||
|
||||
|
||||
function show_help() {
|
||||
cat << EOF
|
||||
|
||||
@ -93,11 +101,24 @@ EOF
|
||||
WRITE_TOKEN=$(cat "$TOKENPATH")
|
||||
fi
|
||||
|
||||
# trip whitespace from the file path
|
||||
LOCALHASH=$("${DROPSHELL}" hash "${FILEPATH}" | tr -d '[:space:]')
|
||||
echo "Local hash: $LOCALHASH"
|
||||
|
||||
FILELINE="-F \"file=@${file}\""
|
||||
EXISTSJSON=$(eval "curl -s \"https://$server/exists/$LOCALHASH\"")
|
||||
DOESEXIT=$(echo "$EXISTSJSON" | jq -r '.exists')
|
||||
if [ "$DOESEXIT" == "true" ]; then
|
||||
echo "File already exists, skipping upload"
|
||||
FILELINE=""
|
||||
fi
|
||||
|
||||
HASH=""
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
curl --progress-bar -X PUT \
|
||||
-H "Authorization: Bearer ${WRITE_TOKEN}" \
|
||||
-F "file=@${file}" \
|
||||
$FILELINE \
|
||||
-F "metadata=${METADATA_JSON}" \
|
||||
"$TARGET_URL" \
|
||||
|| die "Failed to upload $file to $TARGET_URL"
|
||||
|
Loading…
x
Reference in New Issue
Block a user