Browse Source

Removed config file and modified script to create a template file if one does not exist

Now a configuration file will be automatically created. This allows the script to be more easily cloned and run direction from the repository as the configuration file can be ignored
master
Paul Git 1 year ago
parent
commit
5c194d758f
  1. 1
      .gitignore
  2. 8
      cloudflare-ddns.conf
  3. 33
      cloudflare-ddns.sh

1
.gitignore

@ -1 +1,2 @@
cloudflare.ids
cloudflare-ddns.conf

8
cloudflare-ddns.conf

@ -1,8 +0,0 @@
# Update these with your values
AUTH_EMAIL="YOUR_CLOUDFLARE_AUTH_EMAIL"
AUTH_KEY="YOUR_CLOUDFLARE_AUTH_KEY"
ZONE_NAME="example.com"
RECORD_NAME="site.example.com"
# This can be any IP checking site that returns the IP as plain text
IP_CHECK_URL="http://ipv4.icanhazip.com"

33
cloudflare-ddns.sh

@ -20,6 +20,16 @@ _red() {
printf '\033[1;31;31m%b\033[0m' "$1"
}
_yellow() {
printf '\033[1;31;33m%b\033[0m' "$1"
}
_warn() {
printf -- "%s" "[$(date)] "
_yellow "$1"
printf "\n"
}
_error() {
printf -- "%s" "[$(date)] "
_red "$1"
@ -37,6 +47,13 @@ _info() {
_printargs "[email protected]"
}
_exit() {
printf "\n"
_red "$0 has been terminated."
printf "\n"
exit 1
}
_exists() {
local cmd="$1"
if eval type type > /dev/null 2>&1; then
@ -86,7 +103,21 @@ load_config()
{
# Check if the configuration file exists, if not then no need to go any further
if [[ ! -e "$CONFIG_FILE" ]]; then
_error "Unable to find $CONFIG_FILE"
cat > $CONFIG_FILE <<EOF
# Cloudflare as a Dynamic DNS Provider
# Update these with your values
AUTH_EMAIL="YOUR_CLOUDFLARE_AUTH_EMAIL"
AUTH_KEY="YOUR_CLOUDFLARE_AUTH_KEY"
ZONE_NAME="example.com"
RECORD_NAME="site.example.com"
# This can be any IP checking site that returns the IP as plain text
IP_CHECK_URL="http://ipv4.icanhazip.com"
EOF
_warn "A configuration file was not found, $CONFIG_FILE has been created."
_warn "This file contains template information. Please update it with your values."
_exit
fi
# Load the config file

Loading…
Cancel
Save