]> TLD Linux GIT Repositories - packages/dehydrated.git/commitdiff
- moved hook processing code to functions
authorMarcin Krol <hawk@tld-linux.org>
Fri, 27 Oct 2017 10:44:20 +0000 (10:44 +0000)
committerMarcin Krol <hawk@tld-linux.org>
Fri, 27 Oct 2017 10:44:20 +0000 (10:44 +0000)
hook.functions
hook.sh

index 6f9b47b7ccbc3b4d4357431e9b6ca5ad611030ab..190b0d9685d0ad5273706efe8bab0ec47e3e779f 100644 (file)
@@ -1,5 +1,55 @@
 #!/bin/sh
 
+deploy_cert() {
+  local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" TIMESTAMP="${6}"
+  if [[ -n "${HOOKS_D}" ]]; then
+    if [[ ! -d "${HOOKS_D}" ]]; then
+      echo " + Hook: ${HANDLER}: The path ${HOOKS_D} specified for HOOKS_D does not point to a directory."
+    else
+      if [[ -f "${HOOKS_D}/${DOMAIN}" ]]; then 
+        if  [[ -r "${HOOKS_D}/${DOMAIN}" ]]; then
+          echo " + Hook: ${HANDLER}: Executing hook script for certificate ${DOMAIN}."
+          . "${HOOKS_D}/${DOMAIN}"
+        else
+          echo " + Hook: ${HANDLER}: Cannot execute hook script for certificate ${DOMAIN}."
+        fi
+      else
+        if [[ -f "${HOOKS_D}/global" ]] && [[ -r "${HOOKS_D}/global" ]]; then
+          echo " + Hook: ${HANDLER}: Executing global hook script"
+          . "${HOOKS_D}/global"
+        else
+          echo " + Hook: ${HANDLER}: Cannot execute global hook script."
+        fi
+      fi
+    fi
+  fi
+}
+
+clean_challenge() {
+  local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
+  echo " + Hook: ${HANDLER}: Nothing to do..."
+}
+
+deploy_challenge() {
+  local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
+  echo " + Hook: ${HANDLER}: Nothing to do..."
+}
+
+invalid_challenge() {
+  local DOMAIN="${1}" RESPONSE="${2}"
+  echo " + Hook: ${HANDLER}: Nothing to do..."
+}
+
+request_failure() {
+  local STATUSCODE="${1}" REASON="${2}" REQTYPE="${3}"
+  echo " + Hook: ${HANDLER}: Nothing to do..."
+}
+
+unchanged_cert() {
+  local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}"
+  echo " + Hook: ${HANDLER}: Nothing to do..."
+}
+
 # concat file atomic way
 atomic_concat() {
   local file=$1; shift
diff --git a/hook.sh b/hook.sh
index 4587fe817b6074a3d5cbd9aac12b0ced1560d5ed..2025617099ab009a84a13bc84e2d1142ebfda837 100755 (executable)
--- a/hook.sh
+++ b/hook.sh
@@ -4,55 +4,29 @@
 # certificate is successfully deployed
 HOOKS_D="/etc/dehydrated/hooks.d"
 
-# Predefined functions, ie. for reloading/updating system services
+# Load fucntions
 . "/etc/dehydrated/hooks/functions"
 
 HANDLER="${1}"
 shift
 case "${HANDLER}" in
 deploy_cert)
-  local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" TIMESTAMP="${6}"
-  if [[ -n "${HOOKS_D}" ]]; then
-    if [[ ! -d "${HOOKS_D}" ]]; then
-      echo " + Hook: ${HANDLER}: The path ${HOOKS_D} specified for HOOKS_D does not point to a directory."
-    else
-      if [[ -f "${HOOKS_D}/${DOMAIN}" ]]; then 
-        if  [[ -r "${HOOKS_D}/${DOMAIN}" ]]; then
-          echo " + Hook: ${HANDLER}: Executing hook script for certificate ${DOMAIN}."
-          . "${HOOKS_D}/${DOMAIN}"
-        else
-          echo " + Hook: ${HANDLER}: Cannot execute hook script for certificate ${DOMAIN}."
-        fi
-      else
-        if [[ -f "${HOOKS_D}/global" ]] && [[ -r "${HOOKS_D}/global" ]]; then
-          echo " + Hook: ${HANDLER}: Executing global hook script"
-          . "${HOOKS_D}/global"
-        else
-          echo " + Hook: ${HANDLER}: Cannot execute global hook script."
-        fi
-      fi
-    fi
-  fi
+  deploy_cert "$@"
   ;;
 clean_challenge)
-  local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
-  echo " + Hook: ${HANDLER}: Nothing to do..."
+  clean_challenge "$@"
   ;;
 deploy_challenge)
-  local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
-  echo " + Hook: ${HANDLER}: Nothing to do..."
+  deploy_challenge "$@"
   ;;
 invalid_challenge)
-  local DOMAIN="${1}" RESPONSE="${2}"
-  echo " + Hook: ${HANDLER}: Nothing to do..."
+  invalid_challenge "$@"
   ;;
 request_failure)
-  local STATUSCODE="${1}" REASON="${2}" REQTYPE="${3}"
-  echo " + Hook: ${HANDLER}: Nothing to do..."
+  request_failure "$@"
   ;;
 unchanged_cert)
-  local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}"
-  echo " + Hook: ${HANDLER}: Nothing to do..."
+  unchanged_cert "$@"
   ;;
 *)
   echo " + Hook: ${HANDLER}: Nothing to do..."