Compare commits

...

3 Commits

Author SHA1 Message Date
Jason K 4ba3e79ce3
Merge pull request #5 from paul-nelson-baker/main
Environment Input Variables with Validation
2021-08-08 18:47:15 +08:00
Paul FREAKN Baker a0362bacba Reading from enviroment variables with validation
This change allows one to set a environment variables prior to executing
the script. This enables end-users to avoid editing the script itself,
which in turns makes it functionally easier. This also enables end-users
to potentially just drop this script into arbitrary environments without
changing the contents (EG: Docker containers or VMs under configuration
management)
2021-07-20 11:43:06 -06:00
Paul FREAKN Baker 77613a34a4 Fixing potential globbing matching in condition
https://github.com/koalaman/shellcheck/wiki/SC2053
2021-07-20 11:28:15 -06:00
1 changed files with 35 additions and 8 deletions

View File

@ -1,13 +1,40 @@
#!/bin/bash
set -u
auth_email="" # The email used to login 'https://dash.cloudflare.com'
auth_method="token" # Set to "global" for Global API Key or "token" for Scoped API Token
auth_key="" # Your API Token or Global API Key
zone_identifier="" # Can be found in the "Overview" tab of your domain
record_name="" # Which record you want to be synced
proxy=false # Set the proxy to true or false
auth_email="${DDNS_AUTH_EMAIL:-}" # The email used to login 'https://dash.cloudflare.com'
auth_method="${DDNS_AUTH_METHOD:-token}" # Set to "global" for Global API Key or "token" for Scoped API Token
auth_key="${DDNS_AUTH_KEY:-}" # Your API Token or Global API Key
zone_identifier="${DDNS_ZONE_IDENTIFIER:-}" # Can be found in the "Overview" tab of your domain
record_name="${DDNS_RECORD_NAME:-}" # Which record you want to be synced
proxy="${DDNS_PROXY:-false}" # Set the proxy to true or false
###########################################
## Validate variables have been set
###########################################
if [ -z "${auth_email}" ]; then
logger "DDNS Updater: DDNS_AUTH_EMAIL was unset"
exit 1
fi
if [ -z "${auth_method}" ]; then
logger "DDNS Updater: DDNS_AUTH_METHOD was unset"
exit 1
fi
if [ -z "${auth_key}" ]; then
logger "DDNS Updater: DDNS_AUTH_KEY was unset"
exit 1
fi
if [ -z "${zone_identifier}" ]; then
logger "DDNS Updater: DDNS_ZONE_IDENTIFIER was unset"
exit 1
fi
if [ -z "${record_name}" ]; then
logger "DDNS Updater: DDNS_RECORD_NAME was unset"
exit 1
fi
if [ -z "${proxy}" ]; then
logger "DDNS Updater: DDNS_PROXY was unset"
exit 1
fi
###########################################
## Check if we have a public IP
@ -48,7 +75,7 @@ fi
###########################################
old_ip=$(echo "$record" | grep -Po '(?<="content":")[^"]*' | head -1)
# Compare if they're the same
if [[ $ip == $old_ip ]]; then
if [[ $ip == "${old_ip}" ]]; then
logger "DDNS Updater: IP ($ip) for ${record_name} has not changed."
exit 0
fi