#!/bin/sh
|
|
IP="$(curl ipinfo.io/ip)"
|
|
OLDIP="$(more current-ip)"
|
|
TOKEN="$(more token)"
|
|
DOMAIN="$(more domain)"
|
|
RECORD="$(more record)"
|
|
NAME="$(more name)"
|
|
|
|
echo Current IP: $IP
|
|
echo Old IP: $OLDIP
|
|
|
|
# # Lists all the domains using a specific token
|
|
# curl -H "Authorization: Bearer $TOKEN" https://api.linode.com/v4/domains
|
|
|
|
# # List all the records for a specific domain
|
|
# curl -H "Authorization: Bearer $TOKEN" \
|
|
# https://api.linode.com/v4/domains/$DOMAIN/records
|
|
|
|
if [ "$IP" != "$OLDIP" ]
|
|
then
|
|
echo "DNS Requires Updating!"
|
|
echo $IP > current-ip
|
|
curl -H "Content-Type: application/json" \
|
|
-H "Authorization: Bearer $TOKEN" \
|
|
-X PUT -d '{
|
|
"type": "A",
|
|
"name": "'"$NAME"'",
|
|
"target": "'"$IP"'",
|
|
"priority": 10,
|
|
"weight": 5,
|
|
"port": 80,
|
|
"service": null,
|
|
"protocol": null,
|
|
"ttl_sec": 0,
|
|
"tag": null
|
|
}' \
|
|
https://api.linode.com/v4/domains/$DOMAIN/records/$RECORD
|
|
else
|
|
echo "The IPs match, no need to update :)"
|
|
fi
|