Files
paste_senden_holen/paste.sh
2026-05-11 13:37:55 +00:00

58 lines
1.5 KiB
Bash

#!/bin/bash
# All-in-one
HOST="${PASTEBIN_HOST:-http://100.87.87.103:8184}"
USAGE="Verwendung: $0 [-s <datei>] [-g <paste-id>] [-h <host>]"
while getopts ":s:g:h:" opt; do
case $opt in
s) FILE="$OPTARG" ;;
g) PASTE_ID="$OPTARG" ;;
h) HOST="$OPTARG" ;;
:) echo "Option -$OPTARG erfordert ein Argument."; echo "$USAGE"; exit 1 ;;
\?) echo "Unbekannte Option: -$OPTARG"; echo "$USAGE"; exit 1 ;;
esac
done
if [ -z "$FILE" ] && [ -z "$PASTE_ID" ]; then
echo "$USAGE"
exit 1
fi
if [ -n "$FILE" ] && [ -n "$PASTE_ID" ]; then
echo "Fehler: -s und -g schließen sich gegenseitig aus."
echo "$USAGE"
exit 1
fi
# --- Senden ---
if [ -n "$FILE" ]; then
if [ ! -f "$FILE" ]; then
echo "Datei nicht gefunden: $FILE"
exit 1
fi
FILENAME=$(basename "$FILE")
RESPONSE=$(curl -s -X POST "$HOST/api/v1/paste" \
-H "Content-Type: application/json" \
-d "{
\"expiry\": \"1day\",
\"files\": [{
\"name\": \"$FILENAME\",
\"lexer\": \"text\",
\"content\": $(python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))' < "$FILE")
}]
}")
LINK=$(echo "$RESPONSE" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read())["link"])' 2>/dev/null)
if [ -z "$LINK" ]; then
echo "Fehler: $RESPONSE"
exit 1
fi
echo "Paste URL: $LINK"
echo "Paste-ID: $(basename "$LINK")"
fi
# --- Empfangen ---
if [ -n "$PASTE_ID" ]; then
curl -s "$HOST/api/v1/paste/$PASTE_ID" | \
python3 -c 'import json,sys; print(json.loads(sys.stdin.read())["files"][0]["content"])'
fi