updatedns.sh 989 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. IP="$(curl ipinfo.io/ip)"
  3. OLDIP="$(more current-ip)"
  4. TOKEN="$(more token)"
  5. DOMAIN="$(more domain)"
  6. RECORD="$(more record)"
  7. NAME="$(more name)"
  8. echo Current IP: $IP
  9. echo Old IP: $OLDIP
  10. # # Lists all the domains using a specific token
  11. # curl -H "Authorization: Bearer $TOKEN" https://api.linode.com/v4/domains
  12. # # List all the records for a specific domain
  13. # curl -H "Authorization: Bearer $TOKEN" \
  14. # https://api.linode.com/v4/domains/$DOMAIN/records
  15. if [ "$IP" != "$OLDIP" ]
  16. then
  17. echo "DNS Requires Updating!"
  18. echo $IP > current-ip
  19. curl -H "Content-Type: application/json" \
  20. -H "Authorization: Bearer $TOKEN" \
  21. -X PUT -d '{
  22. "type": "A",
  23. "name": "'"$NAME"'",
  24. "target": "'"$IP"'",
  25. "priority": 10,
  26. "weight": 5,
  27. "port": 80,
  28. "service": null,
  29. "protocol": null,
  30. "ttl_sec": 0,
  31. "tag": null
  32. }' \
  33. https://api.linode.com/v4/domains/$DOMAIN/records/$RECORD
  34. else
  35. echo "The IPs match, no need to update :)"
  36. fi