From b75f29b39b10cd94c9e1deb8f163a5bebd7890b2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 1 Jun 2025 23:40:30 +1200 Subject: [PATCH] 'Generic Commit' --- sos/sos | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/sos/sos b/sos/sos index b96fe1c..1145ebd 100755 --- a/sos/sos +++ b/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"