68 lines
1.7 KiB
Bash
Executable File
68 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
# Load configuration
|
|
set -o allexport
|
|
source ${script_dir}/config/dyndns
|
|
set +o allexport
|
|
|
|
# Import logging functionality
|
|
logfile=${script_dir}/log/dyndns.log
|
|
log_identifier="DNS"
|
|
source ${script_dir}/functions/logging.sh
|
|
|
|
url="https://${USERNAME}:${PASSWORD}@infomaniak.com/nic/update?hostname="
|
|
|
|
log "Updating DynDNS for ${MAIN_DOMAIN}"
|
|
|
|
response=$(curl -s -f "${url}${MAIN_DOMAIN}")
|
|
if [[ $? -ne 0 ]]; then
|
|
log_echo "[ERROR] ${MAIN_DOMAIN} DynDNS Request Failed!"
|
|
exit 1
|
|
fi
|
|
|
|
log "Response: ${response}"
|
|
|
|
if [[ "$response" =~ ^nochg ]]; then
|
|
# IP has not changed
|
|
# log_echo "IP has not changed, is still $(echo $response | awk '{print $2}')"
|
|
exit 0
|
|
|
|
elif [[ "$response" =~ ^good ]]; then
|
|
# IP has changed
|
|
log_echo "IP HAS CHANGED TO $(echo $response | awk '{print $2}')"
|
|
log_echo "${MAIN_DOMAIN} was updated successfully"
|
|
|
|
domains_error=0
|
|
for $domain in $ADDITIONAL_DOMAINS
|
|
do
|
|
log "Updating DynDNS for ${domain}"
|
|
additional_response=$(curl -s -f "${url}mneun.ch")
|
|
if [[ $? -ne 0 ]]; then
|
|
log_echo "[ERROR] ${domain} DynDNS Request Failed!"
|
|
exit 1
|
|
fi
|
|
|
|
log "${domain} response: ${additional_response}"
|
|
|
|
if [[ "$additional_response" =~ ^good ]]; then
|
|
# Change succeeded
|
|
log_echo "${domain} was updated successfully"
|
|
elif [[ "$additional_response" =~ ^nochg ]]; then
|
|
log_echo "${domain} did not change"
|
|
else
|
|
log_echo "[ERROR] ${domain} DynDNS request response does not match expectations!"
|
|
domains_error=1
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
if [ $domain_error -eq 1 ]; then
|
|
exit 2
|
|
fi
|
|
else
|
|
log_echo "[ERROR] ${MAIN_DOMAIN} DynDNS request respone does not match expectations!"
|
|
exit 2
|
|
fi
|