-
Notifications
You must be signed in to change notification settings - Fork 1
/
letsencrypt.sh
58 lines (48 loc) · 1.36 KB
/
letsencrypt.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
#!/bin/sh
VER="2021-01-31-r01"
HOST="$1"
FORCEOPT="$2"
ACMEDIR="/opt/acme"
ACMEBIN="$ACMEDIR/acme.sh"
ACMEURL="https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh"
KEYFILE="/root/.acme.sh/$HOST/$HOST.key"
UHTTPD="/etc/init.d/uhttpd"
UHTTPD_CRT=$(uci get uhttpd.main.cert)
UHTTPD_KEY=$(uci get uhttpd.main.key)
if [ -z "$HOST" ]; then
echo "Usage: $0 mybbq.example.com"
exit 1
fi
if [ -n "$FORCEOPT" ]; then
FORCEOPT="--force"
else
FORCEOPT=""
fi
# Download the acme.sh script if missing
if [ ! -f "$ACMEBIN" ]; then
mkdir -p "$ACMEDIR"
curl -o "$ACMEBIN" "$ACMEURL"
chmod +x "$ACMEBIN"
fi
# If a key exists, renew, otherwise issue a new cert
if [ -f "$KEYFILE" ]; then
MODE="--renew"
else
MODE="--issue"
fi
# Allows the openssl listener to start on port 443 to vaalidate the cert
echo "[$(date)] Removing HTTPS listener from uhttpd"
uci -q delete uhttpd.main.listen_https
$UHTTPD reload
# acme.sh defaults to zerossl now. This makes sure it uses letsencrypt
$ACMEBIN --set-default-ca --server letsencrypt
# Issue or renew the cert
$ACMEBIN --alpn "$MODE" \
--key-file "$UHTTPD_KEY" \
--fullchain-file "$UHTTPD_CRT" \
-d "$HOST" $FORCEOPT
# Add the HTTPS listener back to uttpd
echo "[$(date)] Adding HTTPS listener to uhttpd"
uci add_list uhttpd.main.listen_https="0.0.0.0:443"
uci add_list uhttpd.main.listen_https="[::]:443"
$UHTTPD reload