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