From a0362bacbaa8acb3d8da183ffcfe504facb42033 Mon Sep 17 00:00:00 2001 From: Paul FREAKN Baker Date: Tue, 20 Jul 2021 11:35:39 -0600 Subject: [PATCH] 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) --- cloudflare-template.sh | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/cloudflare-template.sh b/cloudflare-template.sh index a87fa38..64b741b 100644 --- a/cloudflare-template.sh +++ b/cloudflare-template.sh @@ -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