]> TLD Linux GIT Repositories - packages/dehydrated.git/blob - hook.functions
- added support for custom functions
[packages/dehydrated.git] / hook.functions
1 #!/bin/bash
2
3 # This file contains base functions for dehydrated system hook scripts.
4 # Please do not edit this file! It will be overwritten by package updates!
5 # If you need to implement your own functions, take a look at
6 # custom_functions file.
7
8 # This function checks for per certificate hook scripts in hooks.d directory.
9 # If not found, it executes global hook script instead.
10 deploy_cert() {
11   local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" TIMESTAMP="${6}"
12   if [[ -n "${HOOKS_D}" ]]; then
13     if [[ ! -d "${HOOKS_D}" ]]; then
14       echo " + System hook: ${HANDLER}: The path ${HOOKS_D} specified for HOOKS_D does not point to a directory."
15     else
16       if [[ -f "${HOOKS_D}/${DOMAIN}" ]]; then 
17         if  [[ -r "${HOOKS_D}/${DOMAIN}" ]]; then
18           echo " + System hook: ${HANDLER}: Executing hook script for certificate ${DOMAIN}."
19           . "${HOOKS_D}/${DOMAIN}"
20         else
21           echo " + System hook: ${HANDLER}: Cannot execute hook script for certificate ${DOMAIN}."
22         fi
23       else
24         if [[ -f "${HOOKS_D}/global" ]] && [[ -r "${HOOKS_D}/global" ]]; then
25           echo " + System hook: ${HANDLER}: Executing global hook script"
26           . "${HOOKS_D}/global"
27         else
28           echo " + System hook: ${HANDLER}: Cannot execute global hook script."
29         fi
30       fi
31     fi
32   fi
33 }
34
35 clean_challenge() {
36   local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
37   echo " + System hook: ${HANDLER}: Nothing to do..."
38 }
39
40 deploy_challenge() {
41   local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
42   echo " + System hook: ${HANDLER}: Nothing to do..."
43 }
44
45 invalid_challenge() {
46   local DOMAIN="${1}" RESPONSE="${2}"
47   echo " + System hook: ${HANDLER}: Nothing to do..."
48 }
49
50 request_failure() {
51   local STATUSCODE="${1}" REASON="${2}" REQTYPE="${3}"
52   echo " + System hook: ${HANDLER}: Nothing to do..."
53 }
54
55 unchanged_cert() {
56   local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}"
57   echo " + System hook: ${HANDLER}: Nothing to do..."
58 }
59
60 startup_hook() {
61   echo " + System hook: ${HANDLER}: Nothing to do..."
62 }
63
64 exit_hook() {
65   echo " + System hook: ${HANDLER}: Nothing to do..."
66 }
67
68 # Function to concat files atomic way to avoid MITM problems
69 atomic_concat() {
70   local file=$1; shift
71   > $file.new
72   chmod 600 $file.new
73   cat "$@" > $file.new
74   cp -f $file $file.dehydrated~
75   mv -f $file.new $file
76 }
77
78 lighttpd_reload() {
79   if [ ! -x /usr/sbin/lighttpd ] || [ ! -f /etc/lighttpd/server.pem ]; then
80     return
81   fi
82   echo " + System hook: Overwritting /etc/lighttpd/server.pem and reloading lighttpd..."
83   atomic_concat /etc/lighttpd/server.pem "$FULLCHAINCERT" "$PRIVKEY"
84   /sbin/service lighttpd reload
85 }
86
87 haproxy_reload() {
88   if [ ! -x /usr/sbin/haproxy ] || [ ! -f /etc/haproxy/server.pem ]; then
89     return
90   fi
91   echo " + System hook: Overwritting /etc/haproxy/server.pem and restarting haproxy..."
92   atomic_concat /etc/haproxy/server.pem "$FULLCHAINCERT" "$PRIVKEY"
93   /sbin/service haproxy reload
94 }
95
96 nginx_reload() {
97   if [ ! -f /etc/nginx/server.crt ] || [ ! -f /etc/nginx/server.key ]; then
98     return
99   fi
100   echo " + System hook: Overwritting /etc/nginx/server.{crt,key} and reloading nginx..."
101   atomic_concat /etc/nginx/server.crt "$FULLCHAINCERT"
102   atomic_concat /etc/nginx/server.key "$PRIVKEY"
103   /sbin/service nginx reload
104 }
105
106 apache_reload() {
107   if [ ! -x /etc/rc.d/init.d/httpd ]; then
108     return
109   fi
110   echo " + System hook: Reloading Apache..."
111   /sbin/service httpd graceful
112 }
113
114 postfix_reload() {
115   if [ ! -x /etc/rc.d/init.d/postfix ]; then
116     return
117   fi
118   echo " + System hook: Reloading Postfix..."
119   /sbin/service postfix reload
120 }
121
122 dovecot_reload() {
123   if [ ! -x /etc/rc.d/init.d/dovecot ]; then
124     return
125   fi
126   echo " + System hook: Reloading Dovecot..."
127   /sbin/service dovecot reload
128 }