-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhook
executable file
·71 lines (56 loc) · 1.97 KB
/
hook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
deploy_challenge() {
local PROCESSED="@"
while [ $# -gt 0 ]
do
local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
echo " - Deploying challenge for $DOMAIN"
# if used already we assume this is the wildcard
if [ -z "${PROCESSED##*@${DOMAIN}@*}" ]; then
ID=$(cat ../pdns-acme.json | jq -r ".domains[\"*.${DOMAIN}\"]")
else
ID=$(cat ../pdns-acme.json | jq -r ".domains[\"${DOMAIN}\"]")
fi
SERVER=$(cat ../pdns-acme.json | jq -r .config.server)
../pdns-client/pdns-client -s $SERVER -i $ID -c $TOKEN_VALUE
PROCESSED="${PROCESSED}${DOMAIN}@"
shift 3
done
sleep $(cat ../pdns-acme.json | jq -r '.config."deploy-wait"')
}
clean_challenge() {
local PROCESSED="@"
while [ $# -gt 0 ]
do
local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
echo " - Cleaning challenge for $DOMAIN"
# if used already we assume this is the wildcard
if [ -z "${PROCESSED##*@${DOMAIN}@*}" ]; then
ID=$(cat ../pdns-acme.json | jq -r ".domains[\"*.${DOMAIN}\"]")
SUFFIX=1
else
ID=$(cat ../pdns-acme.json | jq -r ".domains[\"${DOMAIN}\"]")
SUFFIX=
fi
SERVER=$(cat ../pdns-acme.json | jq -r .config.server)
../pdns-client/pdns-client -s $SERVER -i $ID -c none${SUFFIX}
PROCESSED="${PROCESSED}${DOMAIN}@"
shift 3
done
}
deploy_cert() {
while [ $# -gt 0 ]
do
local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" TIMESTAMP="${6}"
echo " - Deploying cert $DOMAIN"
cat ../pdns-acme.json | jq -r '.certs["'$DOMAIN'"].hook | (arrays | .[]),(strings)' | while read command
do
$command
done
shift 6
done
}
HANDLER="$1"; shift
if [[ "${HANDLER}" =~ ^(deploy_challenge|clean_challenge|deploy_cert)$ ]]; then
"$HANDLER" "$@"
fi