dynamic-ip/src/agents.d/update-dns-namecheap

70 lines
2.2 KiB
Plaintext
Raw Normal View History

2023-10-31 12:12:01 -04:00
#!/bin/bash
# Internal Initialization
source "${DIP_FUNCTIONS}"
if [[ -r "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_NAME}.conf" ]]; then
source "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_NAME}.conf"
fi
if [[ -r "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_EXEC}.conf" ]]; then
source "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_EXEC}.conf"
fi
2023-10-31 12:33:05 -04:00
#if [[ -z "$agent_update_dns_r53_id" ]]; then
# logerr "ERROR: Need 'agent_update_dns_r53_id' to be defined to your Route53 Domain ID"
# exit 99
#fi
2023-10-31 12:12:01 -04:00
#if [[ -d "${DIP_BASE_DIR}/aws" ]]; then
# if [[ ! -r "${DIP_BASE_DIR}/aws/config" ]]; then
# logerr "ERROR: AWS config file not found: '${DIP_BASE_DIR}/aws/config'"
# exit 99
# elif [[ ! -r "${DIP_BASE_DIR}/aws/credentials" ]]; then
# logerr "ERROR: AWS credentials file not found: '${DIP_BASE_DIR}/aws/credentials'"
# exit 99
# else
# export AWS_CONFIG_FILE="${DIP_BASE_DIR}/aws/config"
# export AWS_SHARED_CREDENTIALS_FILE="${DIP_BASE_DIR}/aws/credentials"
# fi
#else
# logerr "ERROR: AWS config directory not found. '${DIP_BASE_DIR}/aws/' is expected to exist and contain 'config' and 'credentials' for AWS access."
# exit 99
#fi
if [[ -z "$DIP_CUR_IP" ]] || [[ -z "$DIP_OLD_IP" ]] || [[ -z "$DIP_RECORD" ]]; then
logerr "ERROR: Agent expects currentip, existingip, and record."
exit 98
fi
_get_host_and_domain() {
local record=$1
hostname=${record%%.*}
domain=${record#*.}
if [[ -n "${agent_update_dns_namecheap_token[$domain]}" ]]; then
token="${agent_update_dns_namecheap_token[$domain]}"
return 0
else
logerr "ERROR: Password for $domain not found in agent configuration."
return 1
fi
}
# Main
2023-10-31 12:33:05 -04:00
_get_host_and_domain "$DIP_RECORD" || exit 99
2023-10-31 12:12:01 -04:00
if valid_ipv4 "$DIP_CUR_IP"; then
log "Updating Namecheap DNS IPv4 Record for ${hostname}.${domain}"
curl "https://dynamicdns.park-your-domain.com/update?host=${hostname}&domain=${domain}&password=${token}&ip=${DIP_CUR_IP}"
fi
if valid_ipv6 "$DIP_CUR_IP"; then
log "Updating Namecheap DNS IPv6 Record for ${hostname}.${domain}"
curl "https://dynamicdns.park-your-domain.com/update?host=${hostname}&domain=${domain}&password=${token}&ip=${DIP_CUR_IP}"
fi