1
0
mirror of https://github.com/EV21/dynb.git synced 2025-12-26 16:39:32 +01:00

fix: abort on all dig errors

This commit is contained in:
2022-04-12 20:23:52 +02:00
parent 3d1b27aaed
commit 756c17d117

97
dynb.sh
View File

@@ -421,8 +421,7 @@ function checkStatus
if [[ "$_statusHostname" == "$DYNB_DYN_DOMAIN" && ("$_statusUsername" == "$DYNB_USERNAME" || $_statusUsername == "$DYNB_TOKEN") ]]; then if [[ "$_statusHostname" == "$DYNB_DYN_DOMAIN" && ("$_statusUsername" == "$DYNB_USERNAME" || $_statusUsername == "$DYNB_TOKEN") ]]; then
errorMessage "Hostname supplied does not exist under specified account, enter new login credentials before performing an additional request." errorMessage "Hostname supplied does not exist under specified account, enter new login credentials before performing an additional request."
return 1 return 1
else else rm "$_statusFile"
rm "$_statusFile"
fi fi
return 0 return 0
;; ;;
@@ -430,8 +429,7 @@ function checkStatus
if [[ "$_statusUsername" == "$DYNB_USERNAME" && "$_statusPassword" == "$DYNB_PASSWORD" ]]; then if [[ "$_statusUsername" == "$DYNB_USERNAME" && "$_statusPassword" == "$DYNB_PASSWORD" ]]; then
errorMessage "Invalid username password combination." errorMessage "Invalid username password combination."
return 1 return 1
else else rm "$_statusFile"
rm "$_statusFile"
fi fi
return 0 return 0
;; ;;
@@ -455,20 +453,20 @@ function checkStatus
;; ;;
911 | 5*) 911 | 5*)
delta=$(($(date +%s) - _eventTime)) delta=$(($(date +%s) - _eventTime))
if [[ $delta -lt 1800 ]]; then if [[ $delta -lt 1800 ]]
then
errorMessage "$_status: The provider currently has an fatal error. DynB will wait for next update until 30 minutes have passed since last request, $(date --date=@$delta -u +%M) minutes already passed." errorMessage "$_status: The provider currently has an fatal error. DynB will wait for next update until 30 minutes have passed since last request, $(date --date=@$delta -u +%M) minutes already passed."
return 1 return 1
else else rm "$_statusFile"
rm "$_statusFile"
fi fi
return 0 return 0
;; ;;
*) *)
if [[ _errorCounter -gt 1 ]]; then if [[ _errorCounter -gt 1 ]]
then
errorMessage "An unknown response code has repeatedly been received. $_response" errorMessage "An unknown response code has repeatedly been received. $_response"
return 1 return 1
else else return 0
return 0
fi fi
;; ;;
esac esac
@@ -483,7 +481,9 @@ function ipHasChanged
4) 4)
remote_ip=$(getRemoteIP 4 $_ipv4_checker) remote_ip=$(getRemoteIP 4 $_ipv4_checker)
if ! is_IPv4_address "$remote_ip" if ! is_IPv4_address "$remote_ip"
then errorMessage "The response from the IP check server is not an IPv4 address: $remote_ip"; return 0 then
errorMessage "The response from the IP check server is not an IPv4 address: $remote_ip"
return 1
fi fi
if [[ $DYNB_UPDATE_METHOD == domrobot ]] if [[ $DYNB_UPDATE_METHOD == domrobot ]]
then dns_ip=$(getDNSIP A) then dns_ip=$(getDNSIP A)
@@ -493,7 +493,9 @@ function ipHasChanged
else dig_response=$(dig in a +short "$DYNB_DYN_DOMAIN") else dig_response=$(dig in a +short "$DYNB_DYN_DOMAIN")
fi fi
if [[ $dig_response == ";; connection timed out; no servers could be reached" ]] if [[ $dig_response == ";; connection timed out; no servers could be reached" ]]
then errorMessage "DNS request failed $dig_response"; return 0 then
errorMessage "DNS request failed $dig_response"
return 1
fi fi
# If the dns resolver lists multiple records in the answer section we filter the first line # If the dns resolver lists multiple records in the answer section we filter the first line
# using short option "-n" and not "--lines" because of alpines limited BusyBox head command # using short option "-n" and not "--lines" because of alpines limited BusyBox head command
@@ -507,19 +509,20 @@ function ipHasChanged
if ! is_IPv6_address "$remote_ip" if ! is_IPv6_address "$remote_ip"
then then
errorMessage "The response from the IP check server is not an IPv6 address: $remote_ip" errorMessage "The response from the IP check server is not an IPv6 address: $remote_ip"
return 0 return 1
fi fi
if [[ $DYNB_UPDATE_METHOD == domrobot ]]; then if [[ $DYNB_UPDATE_METHOD == domrobot ]]
dns_ip=$(getDNSIP AAAA) then dns_ip=$(getDNSIP AAAA)
else else
if [[ -n $_DNS_checkServer ]]; then if [[ -n $_DNS_checkServer ]]
dig_response=$(dig @"${_DNS_checkServer}" in aaaa +short "$DYNB_DYN_DOMAIN") then dig_response=$(dig @"${_DNS_checkServer}" in aaaa +short "$DYNB_DYN_DOMAIN")
else else dig_response=$(dig in aaaa +short "$DYNB_DYN_DOMAIN")
dig_response=$(dig in aaaa +short "$DYNB_DYN_DOMAIN")
fi fi
if [[ $dig_response == ";; connection timed out; no servers could be reached" ]]; then exitcode=$?
errorMessage "DNS request failed $dig_response" if [[ $exitcode -gt 0 ]]
return 0 then
errorMessage "DNS request failed with exit code: $exitcode $dig_response"
return 1
fi fi
# If the dns server lists multiple records in the answer section we filter the first line # If the dns server lists multiple records in the answer section we filter the first line
dns_ip=$(echo "$dig_response" | head -n 1) dns_ip=$(echo "$dig_response" | head -n 1)
@@ -531,20 +534,16 @@ function ipHasChanged
esac esac
if [[ "$remote_ip" == "$dns_ip" ]] if [[ "$remote_ip" == "$dns_ip" ]]
then return 0 then return 1
else else
case ${ip_version} in case ${ip_version} in
4) infoMessage "New IPv4: $_new_IPv4 old was: $dns_ip";; 4) infoMessage "New IPv4: $_new_IPv4 old was: $dns_ip";;
6) infoMessage "New IPv6: $_new_IPv6 old was: $dns_ip";; 6) infoMessage "New IPv6: $_new_IPv6 old was: $dns_ip";;
esac esac
return 1 return 0
fi fi
} }
################
## parameters ##
################
function handleParameters function handleParameters
{ {
# shellcheck disable=SC2154 # shellcheck disable=SC2154
@@ -556,7 +555,7 @@ function handleParameters
then ln --verbose --symbolic "$(realpath "$0")" "$HOME/.local/bin/dynb"; exit 0 then ln --verbose --symbolic "$(realpath "$0")" "$HOME/.local/bin/dynb"; exit 0
fi fi
# shellcheck disable=SC2154 # shellcheck disable=SC2154
if [[ $_arg_reset == "on" ]] if [[ $_arg_reset == "on" ]] && test -f "$_statusFile"
then rm --verbose "$_statusFile"; exit 0 then rm --verbose "$_statusFile"; exit 0
fi fi
# shellcheck disable=SC2154 # shellcheck disable=SC2154
@@ -637,27 +636,25 @@ function handleParameters
return 0 return 0
} }
##################
## dependencies ##
##################
function checkDependencies function checkDependencies
{ {
failCounter=0 failCounter=0
for i in curl dig; do for i in curl dig; do
if ! command -v $i >/dev/null 2>&1; then if ! command -v $i >/dev/null 2>&1
then
errorMessage "could not find \"$i\", DynB depends on it. " errorMessage "could not find \"$i\", DynB depends on it. "
((failCounter++)) ((failCounter++))
fi fi
done done
[[ -x $(command -v jq 2>/dev/null) ]] || { [[ -x $(command -v jq 2>/dev/null) ]] || {
if [[ $DYNB_UPDATE_METHOD != dyndns* ]]; then if [[ $DYNB_UPDATE_METHOD != dyndns* ]]
then
echo "This script depends on jq and it is not available." >&2 echo "This script depends on jq and it is not available." >&2
((failCounter++)) ((failCounter++))
fi fi
} }
if [[ failCounter -gt 0 ]]; then if [[ failCounter -gt 0 ]]
exit 1 then exit 1
fi fi
} }
@@ -696,16 +693,14 @@ function doDomrobotUpdates
fetchDNSRecords fetchDNSRecords
if [[ $_is_IPv4_enabled == true ]] if [[ $_is_IPv4_enabled == true ]]
then then
ipHasChanged 4 if ipHasChanged 4
if [[ $? == 1 ]]
then updateRecord 4 then updateRecord 4
else debugMessage "Skip IPv4 record update, it is already up to date" else debugMessage "Skip IPv4 record update, it is already up to date"
fi fi
fi fi
if [[ $_is_IPv6_enabled == true ]] if [[ $_is_IPv6_enabled == true ]]
then then
ipHasChanged 6 if ipHasChanged 6
if [[ $? == 1 ]]
then updateRecord 6 then updateRecord 6
else debugMessage "Skip IPv6 record update, it is already up to date" else debugMessage "Skip IPv6 record update, it is already up to date"
fi fi
@@ -715,11 +710,11 @@ function doDomrobotUpdates
function doDynDNS2Updates function doDynDNS2Updates
{ {
changed=0 changed=0
if [[ $_is_IPv4_enabled == true ]] if [[ $_is_IPv4_enabled == true ]] && ipHasChanged 4
then ipHasChanged 4; ((changed += $?)) then ((changed += 1))
fi fi
if [[ $_is_IPv6_enabled == true ]] if [[ $_is_IPv6_enabled == true ]] && ipHasChanged 6
then ipHasChanged 6; ((changed += $?)) then ((changed += 1))
fi fi
if [[ $changed -gt 0 ]] if [[ $changed -gt 0 ]]
then then
@@ -742,18 +737,16 @@ function doUpdates
{ {
if [[ $DYNB_UPDATE_METHOD == "domrobot" ]] if [[ $DYNB_UPDATE_METHOD == "domrobot" ]]
then doDomrobotUpdates then doDomrobotUpdates
fi elif [[ $DYNB_UPDATE_METHOD == "dyndns" ]]
if [[ $DYNB_UPDATE_METHOD == "dyndns" ]]
then doDynDNS2Updates then doDynDNS2Updates
fi fi
} }
function ipv6_is_not_working function ipv6_is_not_working
{ {
curl --ipv6 --head --silent --max-time 1 $_internet_connectivity_test_server > /dev/null curl --ipv6 --head --silent --max-time 5 $_internet_connectivity_test_server > /dev/null
status_code=$? status_code=$?
if [[ $status_code -gt 0 ]] if test $status_code -gt 0
then return 0 then return 0
else return 1 else return 1
fi fi
@@ -761,9 +754,9 @@ function ipv6_is_not_working
function ipv4_is_not_working function ipv4_is_not_working
{ {
curl --ipv4 --head --silent --max-time 1 $_internet_connectivity_test_server > /dev/null curl --ipv4 --head --silent --max-time 5 $_internet_connectivity_test_server > /dev/null
status_code=$? status_code=$?
if [[ $status_code -gt 0 ]] if test $status_code -gt 0
then return 0 then return 0
else return 1 else return 1
fi fi