Skip to content

Commit

Permalink
Create updater.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Cordtus authored Oct 21, 2023
1 parent a839590 commit 3b3166d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions scripts/updater.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

#################### FILL THESE VARIABLES ####################
NAME_TYPE="<name_type>"
EMAIL="<[email protected]>"
TOKEN="<yourcloudflareapitoken>"
DOMAINS=("<domain1.com>" "<domain2.com>" "<domain3.com>")
RECORD_IDS=("<ID1>" "<ID2>" "<ID3>")
ZONE_IDS=("<ZONE1>" "<ZONE2>" "<ZONE3>")
LOG_FILE="/var/log/IP"
##############################################################

CURRENT_IPV4="$(curl ifconfig.me)"
LAST_IPV4="$(tail -1 $LOG_FILE | awk -F, '{print $2}')"

if [ "$CURRENT_IPV4" = "$LAST_IPV4" ]; then
echo "IP has not changed ($CURRENT_IPV4)"
else
echo "IP has changed: $CURRENT_IPV4"
echo "$(date),$CURRENT_IPV4" >> $LOG_FILE
for I in ${!DOMAINS[@]}
do
DOMAIN=${DOMAINS[$I]}
RECORD_ID=${RECORD_IDS[$I]}
ZONE_ID=${ZONE_IDS[$I]}
curl -X PUT --url https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID -H 'Content-Type: application/json' -H 'X-Auth-Email: "'"$EMAIL"'"' -H 'X-Auth-Key: "'"$TOKEN"'"' -d '{"content":"'"$CURRENT_IPV4"'", "name":"'"$DOMAIN"'", "type":"'"$NAME_TYPE"'"}'
done
fi

0 comments on commit 3b3166d

Please sign in to comment.