From b516d7889e21d0d5e78620bd2f73a77f41d417ba Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Tue, 11 Sep 2018 23:32:42 -0600 Subject: [PATCH] Setup initial skeleton for script with parameters --- cfddns.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 cfddns.sh diff --git a/cfddns.sh b/cfddns.sh new file mode 100755 index 0000000..73c5fee --- /dev/null +++ b/cfddns.sh @@ -0,0 +1,54 @@ +#!/bin/bash + + +### Define functions + +function scriptHelp { +echo -e "\e[1;31mInvalid parameter(s) provided\e[0m" +echo -e "\e[1;39mUsage: \e[1;36m$(basename ${0})" \ + "\e[1;35m-f path/to/account/details.file" \ + "\e[1;33m-r record.to.update\e[0m" \ + "\e[1;33m[-r another.record.to.update]\e[0m\n" +echo -e "\e[1;39mExample: \e[1;36m$(basename ${0})" \ + "\e[1;35m-f /home/janedoe/myCloudFlareDetails.info" \ + "\e[1;33m-r server.mydomain.com\e[0m" +echo -e "\e[1;39mExample: \e[1;36m$(basename ${0})" \ + "\e[1;35m-f /home/janedoe/myCloudFlareDetails.info" \ + "\e[1;33m-r server.mydomain.com\e[0m" \ + "\e[1;33m-r server2.mydomain.com\e[0m" +exit 1 +} + +### end of functions + + +### unset environment variables used in this script and initialize arrays +unset PARAMS +unset accountFile +dnsRecords=() + +### Process script parameters +if [ -z $1 ]; then + scriptHelp +fi +while getopts ':f:r:' PARAMS; do + case "$PARAMS" in + f) + accountFile="${OPTARG}" + ;; + r) + dnsRecords+=($OPTARG) + ;; + ?) + scriptHelp + ;; + esac +done + + +### Echo results (testing) +echo "Based on parameters provided:" +echo "Login details at: ${accountFile}" +echo "Updating records: ${dnsRecords[*]}" + +exit 0