-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhttpd-challenge-hook.sh
executable file
·54 lines (45 loc) · 1.17 KB
/
httpd-challenge-hook.sh
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
#!/bin/sh
# This is a uacme hook script for challenge type http-01 that automatically
# starts busybox httpd server on port 80 to serve the key authorization for the
# challenge verification and stops it when it's done.
#
# This file is part of muacme.
set -eu
PROGNAME=$(basename "$0")
HTTP_BASE_DIR='/tmp/uacme-challenge'
CHALLENGE_DIR="$HTTP_BASE_DIR/.well-known/acme-challenge"
PIDFILE='/run/uacme-httpd.pid'
if [ $# -ne 5 ]; then
echo "Usage: $PROGNAME (begin | done | failed) http-01 <ident> <token> <auth>" >&2
exit 85 # copied from uacme.sh
fi
method=$1
type=$2
ident=$3
token=$4
auth=$5
if [ "$type" != 'http-01' ]; then
echo "$PROGNAME: unsupported type: $type" >&2
exit 1
fi
case "$method" in
begin)
mkdir -p "$CHALLENGE_DIR"
start-stop-daemon \
--start \
--background \
--make-pidfile \
--pidfile "$PIDFILE" \
--stderr-logger 'logger -t muacme -p cron.err' \
-- httpd -f -u nobody:nogroup -h "$HTTP_BASE_DIR" || true
printf '%s' "$auth" > "$CHALLENGE_DIR/$token"
;;
done | failed)
rm "$CHALLENGE_DIR/$token"
start-stop-daemon --stop --pidfile "$PIDFILE" || true
;;
*)
echo "$PROGNAME: invalid method: $method" >&2
exit 1
;;
esac