mirror of
https://github.com/aaronriedel/hetzner-ddns.git
synced 2024-11-18 00:56:41 +01:00
add .env
This commit is contained in:
parent
3c60b1a02a
commit
92171b2ade
3 changed files with 24 additions and 22 deletions
8
.env
Normal file
8
.env
Normal file
|
@ -0,0 +1,8 @@
|
|||
##########################################################################################
|
||||
# SETTINGS
|
||||
HETZNER_API_TOKEN="" # https://dns.hetzner.com/settings/api-token
|
||||
SUBDOMAIN_IPV4="" # desired subdomain e.g. "server1"
|
||||
DNSZONE_IPV4="" # name of the zone in DNS Console e.g. "example.com"
|
||||
SUBDOMAIN_IPV6="" # desired subdomain e.g. "server1"
|
||||
DNSZONE_IPV6="" # name of the zone in DNS Console e.g. "example.com"
|
||||
##########################################################################################
|
19
ddns4.sh
19
ddns4.sh
|
@ -1,9 +1,6 @@
|
|||
#!/bin/bash
|
||||
##########################################################################################
|
||||
# SETTINGS
|
||||
HETZNER_API_TOKEN="" # https://dns.hetzner.com/settings/api-token
|
||||
SERVERNAME="" # desired subdomain e.g. "server1"
|
||||
DNSZONE="" # name of the zone in DNS Console e.g. "example.com"
|
||||
source .env
|
||||
##########################################################################################
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
|
@ -44,7 +41,7 @@ response_code() {
|
|||
#############################################
|
||||
echo -e "${INFO} DDNS Manager by Aaron"
|
||||
echo -e "${INFO} started $(date)"
|
||||
echo -e "${INFO} DNS Record will be $SERVERNAME.$DNSZONE"
|
||||
echo -e "${INFO} DNS Record will be $SUBDOMAIN_IPV4.$DNSZONE_IPV4"
|
||||
echo -e "${PENDING} get IP address"
|
||||
IPv4="$(curl -s4 https://ip.hetzner.com)"
|
||||
if [ -z $IPv4 ]; then
|
||||
|
@ -67,7 +64,7 @@ fi
|
|||
|
||||
#############################################
|
||||
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\") | .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
|
||||
echo -e "${REPLACE}${FAIL} get DNS Zone"
|
||||
exit 1
|
||||
|
@ -79,7 +76,7 @@ echo -e "${PENDING} Check DNS Console for existing records"
|
|||
RECORDS=$(curl -s "https://dns.hetzner.com/api/v1/records?zone_id=${HETZNER_API_ZONE}" \
|
||||
-H "Auth-API-Token: ${HETZNER_API_TOKEN}")
|
||||
echo -e "${REPLACE}${DONE} Check DNS Console for existing records"
|
||||
echo $RECORDS | jq -r '.records[] | select(.type=="A") | .name' | grep -q $SERVERNAME
|
||||
echo $RECORDS | jq -r '.records[] | select(.type=="A") | .name' | grep -q $SUBDOMAIN_IPV4
|
||||
if [ $? -eq 1 ]; then
|
||||
echo -e "${INFO} Record not found"
|
||||
echo -e "${PENDING} Set new Record"
|
||||
|
@ -90,7 +87,7 @@ if [ $? -eq 1 ]; then
|
|||
\"value\": \"${IPv4}\",
|
||||
\"ttl\": 60,
|
||||
\"type\": \"A\",
|
||||
\"name\": \"${SERVERNAME}\",
|
||||
\"name\": \"${SUBDOMAIN_IPV4}\",
|
||||
\"zone_id\": \"${HETZNER_API_ZONE}\"
|
||||
}")
|
||||
if [ $API_STATUS_CODE != "200" ]; then
|
||||
|
@ -101,8 +98,8 @@ if [ $? -eq 1 ]; then
|
|||
fi
|
||||
else
|
||||
echo -e "${INFO} Record already there"
|
||||
RECORD_ID=$(echo $RECORDS | jq -r '.records[] | select(.type=="A") | select(.name=="'${SERVERNAME}'") | .id' | head -1)
|
||||
OLD_IP=$(echo $RECORDS | jq -r '.records[] | select(.type=="A") | select(.name=="'${SERVERNAME}'") | .value' | 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)
|
||||
echo -e "${INFO} Current IP from Record: $OLD_IP"
|
||||
if [ $IPv4 != $OLD_IP ]; then
|
||||
echo -e "${INFO} IP has changed"
|
||||
|
@ -114,7 +111,7 @@ else
|
|||
\"value\": \"${IPv4}\",
|
||||
\"ttl\": 60,
|
||||
\"type\": \"A\",
|
||||
\"name\": \"${SERVERNAME}\",
|
||||
\"name\": \"${SUBDOMAIN_IPV4}\",
|
||||
\"zone_id\": \"${HETZNER_API_ZONE}\"
|
||||
}")
|
||||
if [ $API_STATUS_CODE != "200" ]; then
|
||||
|
|
19
ddns6.sh
19
ddns6.sh
|
@ -1,9 +1,6 @@
|
|||
#!/bin/bash
|
||||
##########################################################################################
|
||||
# SETTINGS
|
||||
HETZNER_API_TOKEN="" # https://dns.hetzner.com/settings/api-token
|
||||
SERVERNAME="" # desired subdomain e.g. "server1"
|
||||
DNSZONE="" # name of the zone in DNS Console e.g. "example.com"
|
||||
source .env
|
||||
##########################################################################################
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
|
@ -44,7 +41,7 @@ response_code() {
|
|||
#############################################
|
||||
echo -e "${INFO} DDNS Manager by Aaron"
|
||||
echo -e "${INFO} started $(date)"
|
||||
echo -e "${INFO} DNS Record will be $SERVERNAME.$DNSZONE"
|
||||
echo -e "${INFO} DNS Record will be $SUBDOMAIN_IPV6.$DNSZONE_IPV6"
|
||||
echo -e "${PENDING} get IP address"
|
||||
IPv6="$(curl -s6 https://ip.hetzner.com)"
|
||||
if [ -z $IPv6 ]; then
|
||||
|
@ -67,7 +64,7 @@ fi
|
|||
|
||||
#############################################
|
||||
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\") | .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
|
||||
echo -e "${REPLACE}${FAIL} get DNS Zone"
|
||||
exit 1
|
||||
|
@ -79,7 +76,7 @@ echo -e "${PENDING} Check DNS Console for existing records"
|
|||
RECORDS=$(curl -s "https://dns.hetzner.com/api/v1/records?zone_id=${HETZNER_API_ZONE}" \
|
||||
-H "Auth-API-Token: ${HETZNER_API_TOKEN}")
|
||||
echo -e "${REPLACE}${DONE} Check DNS Console for existing records"
|
||||
echo $RECORDS | jq -r '.records[] | select(.type=="AAAA") | .name' | grep -q $SERVERNAME
|
||||
echo $RECORDS | jq -r '.records[] | select(.type=="AAAA") | .name' | grep -q $SUBDOMAIN_IPV6
|
||||
if [ $? -eq 1 ]; then
|
||||
echo -e "${INFO} Record not found"
|
||||
echo -e "${PENDING} Set new Record"
|
||||
|
@ -90,7 +87,7 @@ if [ $? -eq 1 ]; then
|
|||
\"value\": \"${IPv6}\",
|
||||
\"ttl\": 60,
|
||||
\"type\": \"AAAA\",
|
||||
\"name\": \"${SERVERNAME}\",
|
||||
\"name\": \"${SUBDOMAIN_IPV6}\",
|
||||
\"zone_id\": \"${HETZNER_API_ZONE}\"
|
||||
}")
|
||||
if [ $API_STATUS_CODE != "200" ]; then
|
||||
|
@ -101,8 +98,8 @@ if [ $? -eq 1 ]; then
|
|||
fi
|
||||
else
|
||||
echo -e "${INFO} Record already there"
|
||||
RECORD_ID=$(echo $RECORDS | jq -r '.records[] | select(.type=="AAAA") | select(.name=="'${SERVERNAME}'") | .id' | head -1)
|
||||
OLD_IP=$(echo $RECORDS | jq -r '.records[] | select(.type=="AAAA") | select(.name=="'${SERVERNAME}'") | .value' | 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)
|
||||
echo -e "${INFO} Current IP from Record: $OLD_IP"
|
||||
if [ $IPv6 != $OLD_IP ]; then
|
||||
echo -e "${INFO} IP has changed"
|
||||
|
@ -114,7 +111,7 @@ else
|
|||
\"value\": \"${IPv6}\",
|
||||
\"ttl\": 60,
|
||||
\"type\": \"AAAA\",
|
||||
\"name\": \"${SERVERNAME}\",
|
||||
\"name\": \"${SUBDOMAIN_IPV6}\",
|
||||
\"zone_id\": \"${HETZNER_API_ZONE}\"
|
||||
}")
|
||||
if [ $API_STATUS_CODE != "200" ]; then
|
||||
|
|
Loading…
Reference in a new issue