From 544425d74e0bcfd435adad4d8c27e0a18f434154 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Thu, 23 Jun 2022 22:48:31 +0100 Subject: [PATCH] Added new Linode updaters --- linode/updateGit.sh | 51 ++++++++++++++++++++++++++++++++++ linode/updatePush.sh | 51 ++++++++++++++++++++++++++++++++++ linode/updateTester.sh | 62 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100755 linode/updateGit.sh create mode 100755 linode/updatePush.sh create mode 100755 linode/updateTester.sh diff --git a/linode/updateGit.sh b/linode/updateGit.sh new file mode 100755 index 0000000..09bd175 --- /dev/null +++ b/linode/updateGit.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +#Variable Declaration - Change These +ACCESS_TOKEN="f16b8a3fe210f45008b8fec192432ca85b2765c2dac7e5bcd214de242272449b" +PINGID="0311e1b0-30eb-4503-88e2-b9e99a0b872a" +DOMAINID="1851003" +RECORDID="21559701" +NAME="push" +TYPE="A" +TTL=300 + +#get current IP address +IP=$(curl http://checkip.amazonaws.com/) + +#validate IP address (makes sure Route 53 doesn't get updated with a malformed payload) +if [[ ! $IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + exit 1 +fi + +curl -H "Authorization: Bearer $ACCESS_TOKEN" https://api.linode.com/v4/domains/$DOMAINID/records/$RECORDID | \ +jq -r 'select (.name="'"tester"'")|(.type="'"A"'")|.target' > /tmp/linode_${NAME}_value + +cat /tmp/linode_${NAME}_value + +#check if IP is different from Route 53 +if grep -Fxq "$IP" /tmp/linode_${NAME}_value; then + echo "IP Has Not Changed, Exiting" + curl -m 10 --retry 5 https://hc-ping.com/${PINGID} + exit 1 +fi + + curl -H "Content-Type: application/json" \ + -H "Authorization: Bearer $ACCESS_TOKEN" \ + -X PUT -d '{ + "type": "'$TYPE'", + "name": "'$NAME'", + "target": "'$IP'", + "priority": 50, + "weight": 50, + "port": 80, + "service": null, + "protocol": null, + "ttl_sec": 300, + "tag": null + }' \ + https://api.linode.com/v4/domains/$DOMAINID/records/$RECORDID + + +# if good + +curl -m 10 --retry 5 https://hc-ping.com/${PINGID}/99 diff --git a/linode/updatePush.sh b/linode/updatePush.sh new file mode 100755 index 0000000..8659fe6 --- /dev/null +++ b/linode/updatePush.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +#Variable Declaration - Change These +ACCESS_TOKEN="f16b8a3fe210f45008b8fec192432ca85b2765c2dac7e5bcd214de242272449b" +PINGID="0311e1b0-30eb-4503-88e2-b9e99a0b872a" +DOMAINID="1851003" +RECORDID="21559687" +NAME="git" +TYPE="A" +TTL=300 + +#get current IP address +IP=$(curl http://checkip.amazonaws.com/) + +#validate IP address (makes sure Route 53 doesn't get updated with a malformed payload) +if [[ ! $IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + exit 1 +fi + +curl -H "Authorization: Bearer $ACCESS_TOKEN" https://api.linode.com/v4/domains/$DOMAINID/records/$RECORDID | \ +jq -r 'select (.name="'"tester"'")|(.type="'"A"'")|.target' > /tmp/linode_${NAME}_value + +cat /tmp/linode_${NAME}_value + +#check if IP is different from Route 53 +if grep -Fxq "$IP" /tmp/linode_${NAME}_value; then + echo "IP Has Not Changed, Exiting" + curl -m 10 --retry 5 https://hc-ping.com/${PINGID} + exit 1 +fi + + curl -H "Content-Type: application/json" \ + -H "Authorization: Bearer $ACCESS_TOKEN" \ + -X PUT -d '{ + "type": "'$TYPE'", + "name": "'$NAME'", + "target": "'$IP'", + "priority": 50, + "weight": 50, + "port": 80, + "service": null, + "protocol": null, + "ttl_sec": 300, + "tag": null + }' \ + https://api.linode.com/v4/domains/$DOMAINID/records/$RECORDID + + +# if good + +curl -m 10 --retry 5 https://hc-ping.com/${PINGID}/99 diff --git a/linode/updateTester.sh b/linode/updateTester.sh new file mode 100755 index 0000000..6736a6e --- /dev/null +++ b/linode/updateTester.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +#Variable Declaration - Change These +ACCESS_TOKEN="f16b8a3fe210f45008b8fec192432ca85b2765c2dac7e5bcd214de242272449b" +PINGID=0311e1b0-30eb-4503-88e2-b9e99a0b872a +DOMAINID="1851003" +RECORDID="21559818" +NAME="tester" +TYPE="A" +TTL=300 + +#get current IP address +IP=$(curl http://checkip.amazonaws.com/) + +#validate IP address (makes sure Route 53 doesn't get updated with a malformed payload) +if [[ ! $IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + exit 1 +fi + +curl -H "Authorization: Bearer $ACCESS_TOKEN" https://api.linode.com/v4/domains/$DOMAINID/records/$RECORDID | \ +jq -r 'select (.name="'"tester"'")|(.type="'"A"'")|.target' > /tmp/linode_${NAME}_value + +cat /tmp/linode_${NAME}_value + +#check if IP is different from Route 53 +if grep -Fxq "$IP" /tmp/linode_${NAME}_value; then + echo "IP Has Not Changed, Exiting" + # curl -m 10 --retry 5 https://hc-ping.com/0311e1b0-30eb-4503-88e2-b9e99a0b872a + exit 1 +fi + + +# | jq -r 'select (.name="'"tester"'")|(.type="'"A"'")|.target' + +# https://api.linode.com/?api_key=f16b8a3fe210f45008b8fec192432ca85b2765c2dac7e5bcd214de242272449b&api_action=domain.list + +# https://api.linode.com/v4/domains/1851003/records/21559818 + +# echo -X PUT -d '{"type": "\'${TYPE}\'","name": "\'${NAME}\'","target": "\'${IP}\'","priority": 50,"weight": 50,"port": 80,"service": null,"protocol": null,"ttl_sec": $TTL,"tag": null}' + + curl -H "Content-Type: application/json" \ + -H "Authorization: Bearer $ACCESS_TOKEN" \ + -X PUT -d '{ + "type": "'$TYPE'", + "name": "'$NAME'", + "target": "'$IP'", + "priority": 50, + "weight": 50, + "port": 80, + "service": null, + "protocol": null, + "ttl_sec": 300, + "tag": null + }' \ + https://api.linode.com/v4/domains/$DOMAINID/records/$RECORDID + +if [ $? -eq 0]; +then + echo "Success" +else: + echo "Fail" +fi \ No newline at end of file