summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2017-03-01 13:46:04 +0100
committerErich Eckner <git@eckner.net>2017-03-01 13:46:04 +0100
commit2284d60c017230074243ca8fad58c2680237f0c8 (patch)
tree85d71e658a1aaa453fb19187c0693a6b512fd599
parent5fe796f141259d49452713a85aaa117d73eead5a (diff)
downloadupdate-ddns-2284d60c017230074243ca8fad58c2680237f0c8.tar.xz
clean up calls
-rw-r--r--update-ddns.conf4
-rw-r--r--update-ddns.in142
2 files changed, 91 insertions, 55 deletions
diff --git a/update-ddns.conf b/update-ddns.conf
index e23b084..989b46a 100644
--- a/update-ddns.conf
+++ b/update-ddns.conf
@@ -1,3 +1,3 @@
-6 updateUrl1 eno1 dnsName1
-4 updateUrl2 eno1 dnsName2
+6 updateUrl1 dnsName1
+4 updateUrl2 dnsName2
4 updateUrl3 http://ip-check.url
diff --git a/update-ddns.in b/update-ddns.in
index 0fb993e..f99e330 100644
--- a/update-ddns.in
+++ b/update-ddns.in
@@ -18,7 +18,9 @@ then
done
fi
-while read -r ipVer updateUrl dev dnsName
+i=0
+
+while read -r ipVer updateUrl dnsName
do
if [[ "${ipVer}" = '#'* ]] || [ -z "${ipVer}" ]
@@ -28,73 +30,107 @@ do
if [ "${ipVer}" == '4' ]
then
- dnsVer='A'
- inetVer='inet'
- ipCmdVer='-4'
+ dnsVers[${i}]='A'
+ inetVers[${i}]='inet'
+ ipCmdVers[${i}]='-4'
elif [ "${ipVer}" == '6' ]
then
- dnsVer='AAAA'
- inetVer='inet6'
- ipCmdVer='-6'
+ dnsVers[${i}]='AAAA'
+ inetVers[${i}]='inet6'
+ ipCmdVers[${i}]='-6'
else
>&2 echo 'Error: First column in "#ETCDIR#/update-ddns.conf" needs to be "4" or "6"!'
exit 1
fi
- if [ -z "${dnsName}" ]
- then
- dnsIps="$(
- curl -${ipVer} "${dev}" 2> /dev/null
- )"
- ips="1"
- unset updateIp
- else
- dnsIps="$(
- dig $1 "${dnsName}" ${dnsVer} | \
- grep -v '^\s*\(;\|$\)' | \
- grep "\s${dnsVer}\s" | \
- awk '{print $5}' | \
- sort -u
- )"
-
- if [ "${dev}" == "-" ]
- then
- unset dev
- else
- dev="dev ${dev}"
- fi
+ updateUrls[${i}]="${updateUrl}"
+ dnsNamen[${i}]="${dnsName}"
+
+ i=$[${i}+1]
- ips="$(
- "${ipCmd}" -o "${ipCmdVer}" addr show ${dev} scope global | \
- awk '{print $4}' | \
- cut -d/ -f1 | \
- sort -u
- )"
+done < #ETCDIR#/update-ddns.conf
+
+for dnsName in $( \
+ echo "${dnsNamen[@]}" | \
+ tr ' ' '\n' | \
+ uniq
+)
+do
+ unset updateIps
+ unset updateUrl
+ unset curlForceIpVer
+ needsUpdate=false
- if [ $(echo "${ips}" | wc -l) -eq 0 ]
+ for ((j=0; j<${i}; j++))
+ do
+ [ "${dnsName}" != "${dnsNamen[${j}]}" ] && continue
+
+ updateUrl="${updateUrls[${j}]}"
+
+ if [[ "${dnsName}" == *'/'* ]]
then
- unset updateIp
+ dnsIps="$(
+ curl ${ipCmdVers[${j}]} "${dnsName}" 2> /dev/null
+ )"
+ ips='1'
+ updateIps="${updateIps}"',auto'
+ if [ -n "${curlForceIpVer}" ] && [ "${curlForceIpVer}" != "${ipCmdVers[${j}]}" ]
+ then
+ >&2 echo 'FEHLER: Ich kann nicht zwei verschiedene IP-Versionen automatisch ermitteln lassen (weil das Erich nicht braucht).'
+ exit 1
+ fi
+ curlForceIpVer="${ipCmdVers[${j}]}"
else
- updateIp='address='"$(echo -n "${ips}" | tr '\n' ',')"
- if [[ "${updateUrl}" = *'?'* ]]
+ dnsIps="$(
+ dig $1 "${dnsName}" ${dnsVers[${j}]} | \
+ grep -v '^\s*\(;\|$\)' | \
+ grep "\s${dnsVers[${j}]}\s" | \
+ awk '{print $5}' | \
+ sort -u
+ )"
+
+ ips="$(
+ "${ipCmd}" -o ${ipCmdVers[${j}]} addr show scope global | \
+ awk '{print $4}' | \
+ cut -d/ -f1 | \
+ sort -u
+ )"
+
+ if [ $(echo "${ips}" | wc -l) -eq 0 ]
then
- updateIp='&'"${updateIp}"
+ updateIps="${updateIps}"',auto'
+ if [ -n "${curlForceIpVer}" ] && [ "${curlForceIpVer}" != "${ipCmdVers[${j}]}" ]
+ then
+ >&2 echo 'FEHLER: Ich kann nicht zwei verschiedene IP-Versionen automatisch ermitteln lassen (weil das Erich nicht braucht).'
+ exit 1
+ fi
+ curlForceIpVer="${ipCmdVers[${j}]}"
else
- updateIp='?'"${updateIp}"
+ updateIps="${updateIps},$(echo -n "${ips}" | tr '\n' ',')"
fi
fi
- fi
- if [ -z "$(
- (
- echo "${dnsIps}"
- echo "${ips}"
- ) | \
- sort | \
- uniq -d
- )" ]
+ if [ -z "$(
+ (
+ echo "${dnsIps}"
+ echo "${ips}"
+ ) | \
+ sort | \
+ uniq -d
+ )" ]
+ then
+ needsUpdate=true
+ fi
+ done
+
+ if ${needsUpdate}
then
- curl -${ipVer} -sS "${updateUrl}${updateIp}" 2> /dev/null
+ if [[ "${updateUrl}" = *'?'* ]]
+ then
+ updateIps='&'"${updateIps}"
+ else
+ updateIps='?'"${updateIps}"
+ fi
+ curl ${curlForceIpVer} -sS "${updateUrl}${updateIps}" 2> /dev/null
fi
-
-done < #ETCDIR#/update-ddns.conf
+done