paste.sh hinzugefügt
This commit is contained in:
58
paste.sh
Normal file
58
paste.sh
Normal file
@ -0,0 +1,58 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user