mirror of
https://github.com/aaronriedel/hetzner-ddns.git
synced 2024-11-18 00:56:41 +01:00
several bugfixes
This commit is contained in:
parent
da2172cafd
commit
b311cc6202
2 changed files with 28 additions and 28 deletions
26
ddns4.sh
26
ddns4.sh
|
@ -31,11 +31,11 @@ INFO="${NONE}[${BOLD}INFO${NONE}]"
|
||||||
#############################################
|
#############################################
|
||||||
#HTTP Response Code Echo
|
#HTTP Response Code Echo
|
||||||
response_code() {
|
response_code() {
|
||||||
if [ $1 == "200" ]; then echo "$1 Success";
|
if [[ $1 == "200" ]]; then echo "$1 Success";
|
||||||
elif [ $1 == "401" ]; then echo "$1 Unauthorized" && exit 1;
|
elif [[ $1 == "401" ]]; then echo "$1 Unauthorized" && exit 1;
|
||||||
elif [ $1 == "403" ]; then echo "$1 Forbidden" && exit 1;
|
elif [[ $1 == "403" ]]; then echo "$1 Forbidden" && exit 1;
|
||||||
elif [ $1 == "406" ]; then echo "$1 Not acceptable" && exit 1;
|
elif [[ $1 == "406" ]]; then echo "$1 Not acceptable" && exit 1;
|
||||||
elif [ $1 == "422" ]; then echo "$1 Unprocessable entity" && exit 1;
|
elif [[ $1 == "422" ]]; then echo "$1 Unprocessable entity" && exit 1;
|
||||||
else echo "$1 Unknown Status Code" && exit 1; fi
|
else echo "$1 Unknown Status Code" && exit 1; fi
|
||||||
}
|
}
|
||||||
#############################################
|
#############################################
|
||||||
|
@ -44,7 +44,7 @@ echo -e "${INFO} started $(date)"
|
||||||
echo -e "${INFO} DNS Record will be $SUBDOMAIN_IPV4.$DNSZONE_IPV4"
|
echo -e "${INFO} DNS Record will be $SUBDOMAIN_IPV4.$DNSZONE_IPV4"
|
||||||
echo -e "${PENDING} get IP address"
|
echo -e "${PENDING} get IP address"
|
||||||
IPv4="$(curl -s4 https://ip.hetzner.com)"
|
IPv4="$(curl -s4 https://ip.hetzner.com)"
|
||||||
if [ -z $IPv4 ]; then
|
if [[ -z $IPv4 ]]; then
|
||||||
echo -e "${REPLACE}${FAIL} IPv4 not found"
|
echo -e "${REPLACE}${FAIL} IPv4 not found"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
@ -55,7 +55,7 @@ fi
|
||||||
#############################################
|
#############################################
|
||||||
echo -e "${PENDING} attempt API connection"
|
echo -e "${PENDING} attempt API connection"
|
||||||
API_STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" "https://dns.hetzner.com/api/v1/zones" -H "Auth-API-Token: ${HETZNER_API_TOKEN}")
|
API_STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" "https://dns.hetzner.com/api/v1/zones" -H "Auth-API-Token: ${HETZNER_API_TOKEN}")
|
||||||
if [ $API_STATUS_CODE != "200" ]; then
|
if [[ $API_STATUS_CODE != "200" ]]; then
|
||||||
echo -e "${REPLACE}${FAIL} attempt API connection ($(response_code $API_STATUS_CODE))"
|
echo -e "${REPLACE}${FAIL} attempt API connection ($(response_code $API_STATUS_CODE))"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
@ -65,7 +65,7 @@ fi
|
||||||
#############################################
|
#############################################
|
||||||
echo -e "${PENDING} get Zones"
|
echo -e "${PENDING} get Zones"
|
||||||
HETZNER_API_ZONE=$(curl -s "https://dns.hetzner.com/api/v1/zones" -H "Auth-API-Token: ${HETZNER_API_TOKEN}" | jq -r ".zones[] | select(.name==\"$DNSZONE_IPV4\") | .id")
|
HETZNER_API_ZONE=$(curl -s "https://dns.hetzner.com/api/v1/zones" -H "Auth-API-Token: ${HETZNER_API_TOKEN}" | jq -r ".zones[] | select(.name==\"$DNSZONE_IPV4\") | .id")
|
||||||
if [ -z $HETZNER_API_ZONE ]; then
|
if [[ -z $HETZNER_API_ZONE ]]; then
|
||||||
echo -e "${REPLACE}${FAIL} get DNS Zone"
|
echo -e "${REPLACE}${FAIL} get DNS Zone"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
@ -76,8 +76,8 @@ echo -e "${PENDING} Check DNS Console for existing records"
|
||||||
RECORDS=$(curl -s "https://dns.hetzner.com/api/v1/records?zone_id=${HETZNER_API_ZONE}" \
|
RECORDS=$(curl -s "https://dns.hetzner.com/api/v1/records?zone_id=${HETZNER_API_ZONE}" \
|
||||||
-H "Auth-API-Token: ${HETZNER_API_TOKEN}")
|
-H "Auth-API-Token: ${HETZNER_API_TOKEN}")
|
||||||
echo -e "${REPLACE}${DONE} Check DNS Console for existing records"
|
echo -e "${REPLACE}${DONE} Check DNS Console for existing records"
|
||||||
echo $RECORDS | jq -r '.records[] | select(.type=="A") | .name' | grep -q $SUBDOMAIN_IPV4
|
echo $RECORDS | jq -r '.records[] | select(.type=="A") | .name' | grep -qx $SUBDOMAIN_IPV4
|
||||||
if [ $? -eq 1 ]; then
|
if [[ $? -eq 1 ]]; then
|
||||||
echo -e "${INFO} Record not found"
|
echo -e "${INFO} Record not found"
|
||||||
echo -e "${PENDING} Set new Record"
|
echo -e "${PENDING} Set new Record"
|
||||||
API_STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" -X "POST" "https://dns.hetzner.com/api/v1/records" \
|
API_STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" -X "POST" "https://dns.hetzner.com/api/v1/records" \
|
||||||
|
@ -90,7 +90,7 @@ if [ $? -eq 1 ]; then
|
||||||
\"name\": \"${SUBDOMAIN_IPV4}\",
|
\"name\": \"${SUBDOMAIN_IPV4}\",
|
||||||
\"zone_id\": \"${HETZNER_API_ZONE}\"
|
\"zone_id\": \"${HETZNER_API_ZONE}\"
|
||||||
}")
|
}")
|
||||||
if [ $API_STATUS_CODE != "200" ]; then
|
if [[ $API_STATUS_CODE != "200" ]]; then
|
||||||
echo -e "${REPLACE}${FAIL} Set new Record ($(response_code $API_STATUS_CODE))"
|
echo -e "${REPLACE}${FAIL} Set new Record ($(response_code $API_STATUS_CODE))"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
@ -101,7 +101,7 @@ else
|
||||||
RECORD_ID=$(echo $RECORDS | jq -r '.records[] | select(.type=="A") | select(.name=="'${SUBDOMAIN_IPV4}'") | .id' | head -1)
|
RECORD_ID=$(echo $RECORDS | jq -r '.records[] | select(.type=="A") | select(.name=="'${SUBDOMAIN_IPV4}'") | .id' | head -1)
|
||||||
OLD_IP=$(echo $RECORDS | jq -r '.records[] | select(.type=="A") | select(.name=="'${SUBDOMAIN_IPV4}'") | .value' | head -1)
|
OLD_IP=$(echo $RECORDS | jq -r '.records[] | select(.type=="A") | select(.name=="'${SUBDOMAIN_IPV4}'") | .value' | head -1)
|
||||||
echo -e "${INFO} Current IP from Record: $OLD_IP"
|
echo -e "${INFO} Current IP from Record: $OLD_IP"
|
||||||
if [ $IPv4 != $OLD_IP ]; then
|
if [[ $IPv4 != $OLD_IP ]]; then
|
||||||
echo -e "${INFO} IP has changed"
|
echo -e "${INFO} IP has changed"
|
||||||
echo -e "${PENDING} Updating Record"
|
echo -e "${PENDING} Updating Record"
|
||||||
API_STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" -X "PUT" "https://dns.hetzner.com/api/v1/records/$RECORD_ID" \
|
API_STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" -X "PUT" "https://dns.hetzner.com/api/v1/records/$RECORD_ID" \
|
||||||
|
@ -114,7 +114,7 @@ else
|
||||||
\"name\": \"${SUBDOMAIN_IPV4}\",
|
\"name\": \"${SUBDOMAIN_IPV4}\",
|
||||||
\"zone_id\": \"${HETZNER_API_ZONE}\"
|
\"zone_id\": \"${HETZNER_API_ZONE}\"
|
||||||
}")
|
}")
|
||||||
if [ $API_STATUS_CODE != "200" ]; then
|
if [[ $API_STATUS_CODE != "200" ]]; then
|
||||||
echo -e "${REPLACE}${FAIL} Updating Record ($(response_code $API_STATUS_CODE))"
|
echo -e "${REPLACE}${FAIL} Updating Record ($(response_code $API_STATUS_CODE))"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
|
26
ddns6.sh
26
ddns6.sh
|
@ -31,11 +31,11 @@ INFO="${NONE}[${BOLD}INFO${NONE}]"
|
||||||
#############################################
|
#############################################
|
||||||
#HTTP Response Code Echo
|
#HTTP Response Code Echo
|
||||||
response_code() {
|
response_code() {
|
||||||
if [ $1 == "200" ]; then echo "$1 Success";
|
if [[ $1 == "200" ]]; then echo "$1 Success";
|
||||||
elif [ $1 == "401" ]; then echo "$1 Unauthorized" && exit 1;
|
elif [[ $1 == "401" ]]; then echo "$1 Unauthorized" && exit 1;
|
||||||
elif [ $1 == "403" ]; then echo "$1 Forbidden" && exit 1;
|
elif [[ $1 == "403" ]]; then echo "$1 Forbidden" && exit 1;
|
||||||
elif [ $1 == "406" ]; then echo "$1 Not acceptable" && exit 1;
|
elif [[ $1 == "406" ]]; then echo "$1 Not acceptable" && exit 1;
|
||||||
elif [ $1 == "422" ]; then echo "$1 Unprocessable entity" && exit 1;
|
elif [[ $1 == "422" ]]; then echo "$1 Unprocessable entity" && exit 1;
|
||||||
else echo "$1 Unknown Status Code" && exit 1; fi
|
else echo "$1 Unknown Status Code" && exit 1; fi
|
||||||
}
|
}
|
||||||
#############################################
|
#############################################
|
||||||
|
@ -44,7 +44,7 @@ echo -e "${INFO} started $(date)"
|
||||||
echo -e "${INFO} DNS Record will be $SUBDOMAIN_IPV6.$DNSZONE_IPV6"
|
echo -e "${INFO} DNS Record will be $SUBDOMAIN_IPV6.$DNSZONE_IPV6"
|
||||||
echo -e "${PENDING} get IP address"
|
echo -e "${PENDING} get IP address"
|
||||||
IPv6="$(curl -s6 https://ip.hetzner.com)"
|
IPv6="$(curl -s6 https://ip.hetzner.com)"
|
||||||
if [ -z $IPv6 ]; then
|
if [[ -z $IPv6 ]]; then
|
||||||
echo -e "${REPLACE}${FAIL} IPv6 not found"
|
echo -e "${REPLACE}${FAIL} IPv6 not found"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
@ -55,7 +55,7 @@ fi
|
||||||
#############################################
|
#############################################
|
||||||
echo -e "${PENDING} attempt API connection"
|
echo -e "${PENDING} attempt API connection"
|
||||||
API_STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" "https://dns.hetzner.com/api/v1/zones" -H "Auth-API-Token: ${HETZNER_API_TOKEN}")
|
API_STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" "https://dns.hetzner.com/api/v1/zones" -H "Auth-API-Token: ${HETZNER_API_TOKEN}")
|
||||||
if [ $API_STATUS_CODE != "200" ]; then
|
if [[ $API_STATUS_CODE != "200" ]]; then
|
||||||
echo -e "${REPLACE}${FAIL} attempt API connection ($(response_code $API_STATUS_CODE))"
|
echo -e "${REPLACE}${FAIL} attempt API connection ($(response_code $API_STATUS_CODE))"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
@ -65,7 +65,7 @@ fi
|
||||||
#############################################
|
#############################################
|
||||||
echo -e "${PENDING} get Zones"
|
echo -e "${PENDING} get Zones"
|
||||||
HETZNER_API_ZONE=$(curl -s "https://dns.hetzner.com/api/v1/zones" -H "Auth-API-Token: ${HETZNER_API_TOKEN}" | jq -r ".zones[] | select(.name==\"$DNSZONE_IPV6\") | .id")
|
HETZNER_API_ZONE=$(curl -s "https://dns.hetzner.com/api/v1/zones" -H "Auth-API-Token: ${HETZNER_API_TOKEN}" | jq -r ".zones[] | select(.name==\"$DNSZONE_IPV6\") | .id")
|
||||||
if [ -z $HETZNER_API_ZONE ]; then
|
if [[ -z $HETZNER_API_ZONE ]]; then
|
||||||
echo -e "${REPLACE}${FAIL} get DNS Zone"
|
echo -e "${REPLACE}${FAIL} get DNS Zone"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
@ -76,8 +76,8 @@ echo -e "${PENDING} Check DNS Console for existing records"
|
||||||
RECORDS=$(curl -s "https://dns.hetzner.com/api/v1/records?zone_id=${HETZNER_API_ZONE}" \
|
RECORDS=$(curl -s "https://dns.hetzner.com/api/v1/records?zone_id=${HETZNER_API_ZONE}" \
|
||||||
-H "Auth-API-Token: ${HETZNER_API_TOKEN}")
|
-H "Auth-API-Token: ${HETZNER_API_TOKEN}")
|
||||||
echo -e "${REPLACE}${DONE} Check DNS Console for existing records"
|
echo -e "${REPLACE}${DONE} Check DNS Console for existing records"
|
||||||
echo $RECORDS | jq -r '.records[] | select(.type=="AAAA") | .name' | grep -q $SUBDOMAIN_IPV6
|
echo $RECORDS | jq -r '.records[] | select(.type=="AAAA") | .name' | grep -qx $SUBDOMAIN_IPV6
|
||||||
if [ $? -eq 1 ]; then
|
if [[ $? -eq 1 ]]; then
|
||||||
echo -e "${INFO} Record not found"
|
echo -e "${INFO} Record not found"
|
||||||
echo -e "${PENDING} Set new Record"
|
echo -e "${PENDING} Set new Record"
|
||||||
API_STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" -X "POST" "https://dns.hetzner.com/api/v1/records" \
|
API_STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" -X "POST" "https://dns.hetzner.com/api/v1/records" \
|
||||||
|
@ -90,7 +90,7 @@ if [ $? -eq 1 ]; then
|
||||||
\"name\": \"${SUBDOMAIN_IPV6}\",
|
\"name\": \"${SUBDOMAIN_IPV6}\",
|
||||||
\"zone_id\": \"${HETZNER_API_ZONE}\"
|
\"zone_id\": \"${HETZNER_API_ZONE}\"
|
||||||
}")
|
}")
|
||||||
if [ $API_STATUS_CODE != "200" ]; then
|
if [[ $API_STATUS_CODE != "200" ]]; then
|
||||||
echo -e "${REPLACE}${FAIL} Set new Record ($(response_code $API_STATUS_CODE))"
|
echo -e "${REPLACE}${FAIL} Set new Record ($(response_code $API_STATUS_CODE))"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
@ -101,7 +101,7 @@ else
|
||||||
RECORD_ID=$(echo $RECORDS | jq -r '.records[] | select(.type=="AAAA") | select(.name=="'${SUBDOMAIN_IPV6}'") | .id' | head -1)
|
RECORD_ID=$(echo $RECORDS | jq -r '.records[] | select(.type=="AAAA") | select(.name=="'${SUBDOMAIN_IPV6}'") | .id' | head -1)
|
||||||
OLD_IP=$(echo $RECORDS | jq -r '.records[] | select(.type=="AAAA") | select(.name=="'${SUBDOMAIN_IPV6}'") | .value' | head -1)
|
OLD_IP=$(echo $RECORDS | jq -r '.records[] | select(.type=="AAAA") | select(.name=="'${SUBDOMAIN_IPV6}'") | .value' | head -1)
|
||||||
echo -e "${INFO} Current IP from Record: $OLD_IP"
|
echo -e "${INFO} Current IP from Record: $OLD_IP"
|
||||||
if [ $IPv6 != $OLD_IP ]; then
|
if [[ $IPv6 != $OLD_IP ]]; then
|
||||||
echo -e "${INFO} IP has changed"
|
echo -e "${INFO} IP has changed"
|
||||||
echo -e "${PENDING} Updating Record"
|
echo -e "${PENDING} Updating Record"
|
||||||
API_STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" -X "PUT" "https://dns.hetzner.com/api/v1/records/$RECORD_ID" \
|
API_STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" -X "PUT" "https://dns.hetzner.com/api/v1/records/$RECORD_ID" \
|
||||||
|
@ -114,7 +114,7 @@ else
|
||||||
\"name\": \"${SUBDOMAIN_IPV6}\",
|
\"name\": \"${SUBDOMAIN_IPV6}\",
|
||||||
\"zone_id\": \"${HETZNER_API_ZONE}\"
|
\"zone_id\": \"${HETZNER_API_ZONE}\"
|
||||||
}")
|
}")
|
||||||
if [ $API_STATUS_CODE != "200" ]; then
|
if [[ $API_STATUS_CODE != "200" ]]; then
|
||||||
echo -e "${REPLACE}${FAIL} Updating Record ($(response_code $API_STATUS_CODE))"
|
echo -e "${REPLACE}${FAIL} Updating Record ($(response_code $API_STATUS_CODE))"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue