Initialer Import home/maier/bin

This commit is contained in:
2026-04-22 22:54:21 +02:00
commit 1f923ec33d
3 changed files with 90 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
#!/bin/bash
# --- Konfiguration ---
: "${TOKEN:="DEIN_API_TOKEN"}"
DOMAIN="ma3000.de"
# ---------------------
if [ "$#" -ne 3 ]; then
echo "Nutzung: $0 <subname> <typ> <wert>"
exit 1
fi
SUBNAME=$1
TYPE=$2
NEW_VALUE=$3
[[ "$SUBNAME" == "@" ]] && SUBNAME=""
# Wir nutzen den allgemeinen Endpunkt für die Abfrage UND das Senden
BASE_URL="https://desec.io/api/v1/domains/$DOMAIN/rrsets/"
SPECIFIC_URL="${BASE_URL}${SUBNAME}/${TYPE}/"
# 1. Bestehende Records abfragen
response=$(curl -s -H "Authorization: Token $TOKEN" "$SPECIFIC_URL")
# Prüfen, ob der Record existiert oder neu ist
if echo "$response" | jq -e '.detail' > /dev/null 2>&1; then
existing_records="[]"
echo "Info: Record existiert noch nicht. Erstelle neu..."
else
existing_records=$(echo "$response" | jq -c '.records')
fi
# 2. Prüfen, ob der Wert schon vorhanden ist
if echo "$existing_records" | jq -e ". | contains([\"$NEW_VALUE\"])" > /dev/null; then
echo "Info: Wert '$NEW_VALUE' ist bereits vorhanden. Nichts zu tun."
exit 0
fi
# 3. Den neuen Wert zum Set hinzufügen
updated_records=$(echo "$existing_records" | jq -c ". + [\"$NEW_VALUE\"] | unique")
# 4. Senden an den BASIS-Endpunkt (funktioniert für Erstellung und Update)
# Wichtig: Wir nutzen hier POST gegen den Listen-Endpunkt oder PUT gegen den spezifischen
# Bei deSEC ist POST auf /rrsets/ der universelle Weg für "Upsert" (Update oder Insert)
update_response=$(curl -s -X POST "$BASE_URL" \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-d "[{
\"subname\": \"$SUBNAME\",
\"type\": \"$TYPE\",
\"ttl\": 3600,
\"records\": $updated_records
}]")
# Erfolgsprüfung (Die API gibt bei Erfolg eine Liste zurück)
if echo "$update_response" | jq -e '.[0].records' > /dev/null; then
echo "Erfolg: $TYPE Record für '$SUBNAME' ist jetzt: $updated_records"
else
echo "Fehler beim Update:"
echo "$update_response" | jq .
exit 1
fi