X-Git-Url: https://git.tld-linux.org/?p=packages%2Fdehydrated.git;a=blobdiff_plain;f=hook.sh;h=599cb7a1a7a7b456f12c70ada7139b30b1755f49;hp=d5387a4249566e01db6624c3bbf1f69dace4fb91;hb=b5d5d321a92ef9a1ee59bc6ffebc3bb2d2f93454;hpb=c64e35229801d5d23037b9d6e2b1d52bddd0c219 diff --git a/hook.sh b/hook.sh index d5387a4..599cb7a 100755 --- a/hook.sh +++ b/hook.sh @@ -1,82 +1,50 @@ -#!/bin/sh +#!/bin/bash -# concat file atomic way -atomic_concat() { - local file=$1; shift - > $file.new - chmod 600 $file.new - cat "$@" > $file.new - cp -f $file $file.dehydrated~ - mv -f $file.new $file -} +# This is main script for handling dehydrated hook scripts. +# Please do not edit this file! It will be overwritten by package updates! -lighttpd_reload() { - if [ ! -x /usr/sbin/lighttpd ] || [ ! -f /etc/lighttpd/server.pem ]; then - return - fi +# Directory with per certificate hook scripts called after +# certificate is successfully deployed +HOOKS_D="/etc/dehydrated/hooks.d" - echo " + Hook: Overwritting /etc/lighttpd/server.pem and reloading lighttpd..." - atomic_concat /etc/lighttpd/server.pem "$FULLCHAINCERT" "$PRIVKEY" - /sbin/service lighttpd reload -} +# Load system fucntions +. "/etc/dehydrated/hooks/functions" +# Load custom fucntions +. "/etc/dehydrated/hooks/custom_functions" -haproxy_reload() { - if [ ! -x /usr/sbin/haproxy ] || [ ! -f /etc/haproxy/server.pem ]; then - return - fi - - echo " + Hook: Overwritting /etc/haproxy/server.pem and restarting haproxy..." - atomic_concat /etc/haproxy/server.pem "$FULLCHAINCERT" "$PRIVKEY" - /sbin/service haproxy reload -} - -nginx_reload() { - if [ ! -f /etc/nginx/server.crt ] || [ ! -f /etc/nginx/server.key ]; then - return - fi - - echo " + Hook: Overwritting /etc/nginx/server.{crt,key} and reloading nginx..." - atomic_concat /etc/nginx/server.crt "$FULLCHAINCERT" - atomic_concat /etc/nginx/server.key "$PRIVKEY" - /sbin/service nginx reload -} - -httpd_reload() { - if [ ! -x /etc/rc.d/init.d/httpd ]; then - return - fi - - echo " + Hook: Reloading Apache..." - /sbin/service httpd graceful -} - - -case "$1" in +HANDLER="${1}" +shift +case "${HANDLER}" in deploy_cert) - DOMAIN="$2" - PRIVKEY="$3" - CERT="$4" - FULLCHAINCERT="$5" - CHAINCERT="$6" - TIMESTAMP="$7" - - lighttpd_reload - nginx_reload - httpd_reload - haproxy_reload - ;; + deploy_cert "$@" + custom_deploy_cert "$@" + ;; clean_challenge) - CHALLENGE_TOKEN="$2" - KEYAUTH="$3" - echo " + Hook: $1: Nothing to do..." - ;; + clean_challenge "$@" + custom_clean_challenge "$@" + ;; deploy_challenge) - echo " + Hook: $1: Nothing to do..." - ;; + deploy_challenge "$@" + custom_deploy_challenge "$@" + ;; +invalid_challenge) + invalid_challenge "$@" + custom_invalid_challenge "$@" + ;; +request_failure) + request_failure "$@" + custom_request_failure "$@" + ;; unchanged_cert) - echo " + Hook: $1: Nothing to do..." - ;; -*) - echo " + Hook: $1: Nothing to do..." - ;; + unchanged_cert "$@" + custom_unchanged_cert "$@" + ;; +startup_hook) + startup_hook "$@" + custom_startup_hook "$@" + ;; +exit_hook) + exit_hook "$@" + custom_exit_hook "$@" + ;; esac