From 99664be1df538e0d613685d223dde3e7cef8eda4 Mon Sep 17 00:00:00 2001 From: Marcin Krol Date: Fri, 27 Oct 2017 10:44:20 +0000 Subject: [PATCH] - moved hook processing code to functions --- hook.functions | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ hook.sh | 40 +++++++--------------------------------- 2 files changed, 57 insertions(+), 33 deletions(-) diff --git a/hook.functions b/hook.functions index 6f9b47b..190b0d9 100644 --- a/hook.functions +++ b/hook.functions @@ -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 4587fe8..2025617 100755 --- 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..." -- 2.46.0