diff options
Diffstat (limited to 'update-ddns.in')
-rw-r--r-- | update-ddns.in | 142 |
1 files changed, 89 insertions, 53 deletions
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 |