-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathissue.sh
executable file
·68 lines (56 loc) · 1.64 KB
/
issue.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
source ./config.sh
source ./logger.sh
SERVER_PID=""
EXPORT=0
while read DOMAIN; do
if [ -d $LE_DIR/live/$DOMAIN ]; then
continue
fi
if [ -f $LE_DIR/failed/$DOMAIN ]; then
log_warn "$DOMAIN|Skipping domain marked as failed ..."
continue
fi
if [ -z "$SERVER_PID" ]; then
log_info "Starting http server ..."
python -m http.server 80 --directory $WEBROOT &
SERVER_PID=$!
trap "kill $SERVER_PID" EXIT
sleep 5
fi
FILE="$ACME_PATH/check-${DOMAIN}-$(date +%s)"
TEST_URL="http://$DOMAIN/$FILE"
log_info "$DOMAIN|Test challenge accessibility $TEST_URL ..."
echo "certbot" > $WEBROOT/$FILE
curl --silent -v --max-time 5 $TEST_URL > /tmp/result
ERR=$?
rm -f $WEBROOT/$FILE
if [ $ERR -ne 0 -o "$(cat /tmp/result)" != "certbot" ]; then
log_error "$DOMAIN|Domain challenge failed $TEST_URL"
continue
fi
log_info "$DOMAIN|Domain challenge ok, run certbot ..."
{
flock 200
certbot certonly \
--webroot -w $WEBROOT \
--non-interactive \
--agree-tos \
--no-eff-email \
--keep-until-expiring \
-m $CERTBOT_EMAIL \
--cert-name $DOMAIN \
-d $DOMAIN > $LE_DIR/failed/$DOMAIN
CERTBOT_RESULT=$?
} 200>$LOCK_FILE
if (( $CERTBOT_RESULT == 0 )); then
log_info "$DOMAIN|Cerbot ok"
rm -f $LE_DIR/failed/$DOMAIN
EXPORT=1
else
log_error"$DOMAIN|Cerbot failed read log $LE_DIR/failed/$DOMAIN ."
fi
done < <(./domains.sh)
if [ $EXPORT = 1 ]; then
./export.sh
fi