feature: initial logging, add curl check
This commit is contained in:
parent
911526dd08
commit
5a477d6c86
@ -57,7 +57,7 @@ scriptHelp() {
|
|||||||
quit() {
|
quit() {
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
# exit gracefully
|
# exit gracefully
|
||||||
printf "\n%s%s -- %s completed --%s\n\n" "$ok" "$(stamp)" "$scriptName" "$norm" >>"$logFile"
|
printf "%s[%s] -- CloudFlare DDNS update-script: execution complete --%s\n" "$ok" "$(stamp)" "$norm" >>"$logFile"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -148,25 +148,49 @@ while [ $# -gt 0 ]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
### pre-flight checks
|
### pre-flight checks
|
||||||
|
if ! command -v curl >/dev/null; then
|
||||||
|
printf "\n%sThis script requires curl be installed and accessible. Exiting.%s\n\n" "$err" "$norm"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
[ -z "$dnsRecords" ] && badParam errMsg "You must specify at least one DNS record to update. Exiting."
|
[ -z "$dnsRecords" ] && badParam errMsg "You must specify at least one DNS record to update. Exiting."
|
||||||
[ "$ip4" -eq 1 ] && [ "$ip6" -eq 1 ] && badParam errMsg "Cannot operate in IP4 and IP6 modes simultaneously. Exiting."
|
[ "$ip4" -eq 1 ] && [ "$ip6" -eq 1 ] && badParam errMsg "Cannot operate in IP4 and IP6 modes simultaneously. Exiting."
|
||||||
|
# turn off log file colourization if parameter is set
|
||||||
printf "\nscript: %s\n" "$scriptPath/$scriptName"
|
if [ "$colourizeLogFile" -eq 0 ]; then
|
||||||
printf "accountFile: %s\n" "$accountFile"
|
bold=""
|
||||||
printf "colourize: %s\n" "$colourizeLogFile"
|
cyan=""
|
||||||
if [ "$ip4" = 1 ]; then
|
err=""
|
||||||
printf "mode: IP4\n"
|
magenta=""
|
||||||
elif [ "$ip6" = 1 ]; then
|
norm=""
|
||||||
printf "mode: IP6\n"
|
ok=""
|
||||||
|
warn=""
|
||||||
|
yellow=""
|
||||||
fi
|
fi
|
||||||
printf "ip address: %s\n" "$ipAddress"
|
|
||||||
|
|
||||||
# iterate DNS records to update
|
### initial log entries
|
||||||
dnsRecordsToUpdate="$dnsRecords$dnsSeparator"
|
{
|
||||||
while [ "$dnsRecordsToUpdate" != "${dnsRecordsToUpdate#*${dnsSeparator}}" ] && { [ -n "${dnsRecordsToUpdate%%${dnsSeparator}*}" ] || [ -n "${dnsRecordsToUpdate#*${dnsSeparator}}" ]; }; do
|
printf "%s[%s] -- CloudFlare DDNS update-script: execution starting --%s\n" "$ok" "$(stamp)" "$norm"
|
||||||
|
printf "%sParameters:\n" "$magenta"
|
||||||
|
printf "script path: %s\n" "$scriptPath/$scriptName"
|
||||||
|
printf "credentials file: %s\n" "$accountFile"
|
||||||
|
if [ "$ip4" = 1 ]; then
|
||||||
|
printf "mode: IP4\n"
|
||||||
|
elif [ "$ip6" = 1 ]; then
|
||||||
|
printf "mode: IP6\n"
|
||||||
|
fi
|
||||||
|
printf "ddns ip address: %s\n" "$ipAddress"
|
||||||
|
# iterate DNS records to update
|
||||||
|
dnsRecordsToUpdate="$dnsRecords$dnsSeparator"
|
||||||
|
while [ "$dnsRecordsToUpdate" != "${dnsRecordsToUpdate#*${dnsSeparator}}" ] && { [ -n "${dnsRecordsToUpdate%%${dnsSeparator}*}" ] || [ -n "${dnsRecordsToUpdate#*${dnsSeparator}}" ]; }; do
|
||||||
record="${dnsRecordsToUpdate%%${dnsSeparator}*}"
|
record="${dnsRecordsToUpdate%%${dnsSeparator}*}"
|
||||||
dnsRecordsToUpdate="${dnsRecordsToUpdate#*${dnsSeparator}}"
|
dnsRecordsToUpdate="${dnsRecordsToUpdate#*${dnsSeparator}}"
|
||||||
printf "update record: %s\n" "$record"
|
printf "updating record: %s\n" "$record"
|
||||||
done
|
done
|
||||||
|
printf "(end of parameter list)%s\n" "$norm"
|
||||||
|
} >>"$logFile"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
### exit return codes
|
||||||
|
# 0: normal exit, no errors
|
||||||
|
# 1: invalid or unknown parameter
|
||||||
|
# 2: cannot find or access curl
|
||||||
|
Loading…
Reference in New Issue
Block a user