add tolerant and some work parameter commands

Setup to default of strict mode when it asked to exit script.
Add a parameter -tolerant has been add to disable strict mode. This should be the first parameter that is defined. 
Just did a little tying up tryied to remove tabs and pointless white space.
pull/26/head
timetoexpire 4 years ago committed by GitHub
parent dd8740ce05
commit d489b0f2e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 94
      cloudflare-template.sh

@ -12,11 +12,6 @@ slacksitename="" # Title of site "Example Site
slackchannel="" # Slack Channel #example slackchannel="" # Slack Channel #example
slackuri="" # URI for Slack WebHook "https://hooks.slack.com/services/xxxxx" slackuri="" # URI for Slack WebHook "https://hooks.slack.com/services/xxxxx"
#tolerant_is_set=0
top_exit_code=-1;
#argument_total=$#
#tolerant_is_set=false;
debug_output_echo () { debug_output_echo () {
if [ ! -z $debug_mode_active ]; then if [ ! -z $debug_mode_active ]; then
if [ $debug_mode_active -eq 1 ]; then if [ $debug_mode_active -eq 1 ]; then
@ -24,15 +19,19 @@ debug_output_echo () {
fi fi
fi fi
} }
exit_code () { exit_code () {
if [ -z $top_exit_code ]; then
top_exit_code=-999
fi
if [ $top_exit_code -lt $excode ]; then if [ $top_exit_code -lt $excode ]; then
top_exit_code=$excode top_exit_code=$excode
fi fi
if [ $tolerant_is_set -eq 1 ]; then if [ $tolerant_is_set -eq 1 ]; then
# Only when tolerent mode is active, it will not stop for error # Only when tolerent mode is active, it will not stop for error
logger_output="DDNS Updater: in tolerant mode - exit [$excode]" logger_output="DDNS Updater: in tolerant mode - exit [$excode]"
debug_output+=$logger_output"\n" debug_output+=$logger_output"\n"
logger $logger_output logger $logger_output
else else
#It strict mode it will stap instantly on error #It strict mode it will stap instantly on error
@ -46,8 +45,8 @@ cf_ddns_ip () {
## Check if we have a public IP ## Check if we have a public IP
########################################### ###########################################
ip=$(curl -s https://api.ipify.org || curl -s https://ipv4.icanhazip.com/) ip=$(curl -s https://api.ipify.org || curl -s https://ipv4.icanhazip.com/)
if [ "${ip}" == "" ]; then if [ "${ip}" == "" ]; then
logger_output="DDNS Updater: No public IP found" logger_output="DDNS Updater: No public IP found"
debug_output+=$logger_output"\n" debug_output+=$logger_output"\n"
logger -s $logger_output logger -s $logger_output
@ -57,7 +56,7 @@ cf_ddns_ip () {
fi fi
} }
cf_ddns_authheader () { cf_ddns_authheader (){
########################################### ###########################################
## Check and set the proper auth header ## Check and set the proper auth header
########################################### ###########################################
@ -69,11 +68,11 @@ cf_ddns_authheader () {
debug_output+="cf_ddns_authheader : "$auth_header"\n" debug_output+="cf_ddns_authheader : "$auth_header"\n"
} }
cf_ddns_seeka () { cf_ddns_seeka () {
########################################### ###########################################
## Seek for the A record ## Seek for the A record
########################################### ###########################################
logger_output="DDNS Updater: Check Initiated" logger_output="DDNS Updater: Check Initiated"
debug_output+=$logger_output"\n" debug_output+=$logger_output"\n"
logger "$logger_output" logger "$logger_output"
@ -167,7 +166,7 @@ cf_ddns() {
cf_ddns_ip cf_ddns_ip
cf_ddns_authheader cf_ddns_authheader
fi fi
cf_ddns_seeka cf_ddns_seeka
cf_ddns_checka cf_ddns_checka
if [ $cf_nonexistsrecord -eq 1 ]; then if [ $cf_nonexistsrecord -eq 1 ]; then
@ -179,94 +178,94 @@ cf_ddns() {
fi fi
fi fi
} }
cf_parameter_commands () { cf_parameter_commands () {
case "$parameter_current" in case ${parameter_current:1} in
"-debug") "debug")
debug_mode_active=1 debug_mode_active=1
;; ;;
"-help") "help")
echo "# crontab\n" echo "# crontab\n"
echo "*/5 * * * * /bin/bash /home/user/cloudflare-ddns-updater/cloudflare-init.sh" echo "*/5 * * * * /bin/bash /home/user/cloudflare-ddns-updater/cloudflare-init.sh"
echo '*/5 * * * * /bin/bash /home/user/cloudflare-ddns-updater/cloudflare-init.sh mydomain.com example.com www.example.com x1.example.com' echo '*/5 * * * * /bin/bash /home/user/cloudflare-ddns-updater/cloudflare-init.sh mydomain.com example.com www.example.com x1.example.com'
echo -e $output_help echo -e "\nAdd in -tolerant option that get continue if when reason to exit, this should be first parameter\n"
;; echo -e $output_help
*) ;;
echo "Unknown ***************************" "tolerant")
;; tolerant_is_set=1
logger_output="DDNS Updater: Been set as being tolerant"
debug_output+=$logger_output"\n"
logger $logger_output
;;
*)
logger_output="DDNS Updater: invalid parameter option been defined [${parameter_current}]"
debug_output+=$logger_output"\n"
logger -s $logger_output
;;
esac esac
} }
cf_err_human () { cf_err_human () {
err_is_human=0 err_is_human=0
if [ ${#auth_email} -eq 0 ]; then if [ ${#auth_email} -eq 0 ]; then
err_is_human=1 err_is_human=1
logger_output="DDNS Updater: ERROR [auth_email] record not been defined" logger_output="DDNS Updater: ERROR [auth_email] record not been defined"
debug_output+=$logger_output"\n"
logger -s $logger_output logger -s $logger_output
fi fi
if [ $auth_method != "token" ] && [ $auth_method != "global" ]; then if [ $auth_method != "token" ] && [ $auth_method != "global" ]; then
err_is_human=1 err_is_human=1
logger_output='DDNS Updater: ERROR [auth_method] is invaled it has to be defined "token" "global" defined' logger_output='DDNS Updater: ERROR [auth_method] is invaled it has to be defined "token" "global" defined'
debug_output+=$logger_output"\n"
logger -s $logger_output logger -s $logger_output
fi fi
if [ ${#auth_key} -eq 0 ]; then if [ ${#auth_key} -eq 0 ]; then
err_is_human=1 err_is_human=1
logger_output="DDNS Updater: ERROR [auth_key] record not been defined" logger_output="DDNS Updater: ERROR [auth_key] record not been defined"
debug_output+=$logger_output"\n"
logger -s $logger_output logger -s $logger_output
fi fi
if [ ${#zone_identifier} -eq 0 ]; then if [ ${#zone_identifier} -eq 0 ]; then
err_is_human=1 err_is_human=1
logger_output="DDNS Updater: ERROR [zone_identifier] record has not been defined" logger_output="DDNS Updater: ERROR [zone_identifier] record has not been defined"
debug_output+=$logger_output"\n"
logger -s $logger_output logger -s $logger_output
fi fi
if [ ${#record_name} -eq 0 ] && [ $argument_total -eq 0 ]; then if [ ${#record_name} -eq 0 ] && [ $argument_total -eq 0 ]; then
err_is_human=1 err_is_human=1
logger_output="DDNS Updater: ERROR [record_name] record not has been defined" logger_output="DDNS Updater: ERROR [record_name] record not has been defined"
debug_output+=$logger_output"\n"
logger -s $logger_output logger -s $logger_output
fi fi
if [ -z "$tolerant_is_set" ]; then if [ -z "$tolerant_is_set" ]; then
# if tolerant_is_set has not been set up it will be strict # if tolerant_is_set has not been set up it will be strict
tolerant_is_set=0 tolerant_is_set=0
fi fi
if [ $tolerant_is_set -lt 0 ] || [ $tolerant_is_set -gt 1 ]; then if [ $tolerant_is_set -lt 0 ] || [ $tolerant_is_set -gt 1 ]; then
err_is_human=1 err_is_human=1
logger_output="DDNS Updater: ERROR [tolerant_is_set] can only by 0 or 1" logger_output="DDNS Updater: ERROR [tolerant_is_set] can only by 0 or 1"
debug_output+=$logger_output"\n"
logger -s $logger_output logger -s $logger_output
fi fi
if [ $err_is_human -eq 1 ]; then if [ $err_is_human -eq 1 ]; then
#It is done this way so all errors get disclosed #It is done if there is error detected above
debug_output_echo
exit 1 exit 1
fi fi
} }
argument_total=$# argument_total=$#
tolerant_is_set=1 #top_exit_code=-999
debug_output="" debug_output=""
cf_err_human cf_err_human
if [ $# -ne 0 ]; then if [ $# -ne 0 ]; then
# If a parameter has been defined in will ignore any setting in [record_name] # If a parameter has been defined in will ignore any setting in [record_name]
parameter=("$@") parameter=("$@")
for (( argument_depth=0 ; argument_depth < argument_total ; argument_depth++ )); do for (( argument_depth=0 ; argument_depth < argument_total ; argument_depth++ )); do
parameter_current=${parameter[argument_depth]} parameter_current=${parameter[argument_depth]}
first_character=${parameter_current:0:1} first_character=${parameter_current:0:1}
if [ $first_character = "-" ]; then if [ $first_character = "-" ]; then
cf_parameter_commands cf_parameter_commands
else else
@ -278,5 +277,6 @@ else
# If no parameter been used it will use one above [record_name] # If no parameter been used it will use one above [record_name]
cf_ddns cf_ddns
fi fi
debug_output_echo debug_output_echo
exit $err_is_human exit $err_is_human

Loading…
Cancel
Save