Last active
January 2, 2025 11:32
-
-
Save WietseWind/5ef71f7a26d9588a233f1d034762ac84 to your computer and use it in GitHub Desktop.
DLVR.CLOUD one file upload bash script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Install | |
# sudo curl https://gist.githubusercontent.com/WietseWind/5ef71f7a26d9588a233f1d034762ac84/raw/dlvr.sh > /usr/local/bin/dlvr | |
# sudo chmod +x /usr/local/bin/dlvr | |
# Use: dlvr somefilename | |
DLVR_INIT=$(curl -i -s https://dlvr.cloud/api.php) | |
DLVR_SESSION=$(echo "$DLVR_INIT"|grep session|grep addr|grep domain|jq .session|cut -d '"' -f 2) | |
DLVR_ADDR=$(echo "$DLVR_INIT"|grep session|grep addr|grep domain|jq .addr|cut -d '"' -f 2) | |
DLVR_DOMAIN=$(echo "$DLVR_INIT"|grep session|grep addr|grep domain|jq .domain|cut -d '"' -f 2) | |
# Check for verbose flag | |
if [ "$1" == "-v" ]; then | |
VERBOSE=true | |
DLVR_FILENAME="$2" | |
else | |
VERBOSE=false | |
DLVR_FILENAME="$1" | |
fi | |
# Check if file exists | |
if [ ! -f "$DLVR_FILENAME" ]; then | |
echo "Error: File '$DLVR_FILENAME' not found!" | |
exit 1 | |
fi | |
# Extract just the filename from the path and then sanitize | |
BASENAME=$(basename "$DLVR_FILENAME") | |
DLVR_NAME=$(echo "${BASENAME%.*}" | tr -cd 'A-Za-z0-9._-' | sed -E 's/[._-]+/_/g' | sed -E 's/^_+|_+$//') | |
DLVR_EXT=$(echo "${BASENAME##*.}" | tr -cd 'A-Za-z0-9') | |
DLVR_FILENAME_SAN="${DLVR_NAME}.${DLVR_EXT}" | |
# Get MIME type | |
DLVR_MIME=$(file --mime-type -b "$DLVR_FILENAME") | |
DLVR_UPLOAD=$(curl -i -s \ | |
-H "X-Domain: $DLVR_DOMAIN" \ | |
-H "X-Filename: $(echo -n "$DLVR_FILENAME_SAN" | base64)" \ | |
-H "X-Session: $DLVR_SESSION" \ | |
-H "Content-Type: $DLVR_MIME" \ | |
-X PUT \ | |
--data-binary "@$DLVR_FILENAME" \ | |
https://dlvr.cloud/upload.php) | |
if [ "$VERBOSE" = true ]; then | |
echo "$DLVR_DOMAIN" | |
echo "$DLVR_ADDR" | |
echo "Sanitized filename: $DLVR_FILENAME_SAN" | |
echo "MIME type: $DLVR_MIME" | |
echo "Attempting to upload: $DLVR_FILENAME" | |
echo "---> Upload result:" | |
echo "$DLVR_UPLOAD" | |
fi | |
echo "https://$DLVR_DOMAIN.dlvr.cloud/$DLVR_FILENAME_SAN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment