zhongrj
2025-11-25 b89962006164a462404b79a738bee8cbb6d7fe7e
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/bash
__dirname=$(cd $(dirname "$0"); pwd -P)
cd ${__dirname}
 
hash certbot 2>/dev/null || not_found=true 
if [ $not_found ]; then
    echo "Certbot not found. You need to install certbot to use this script."
    exit 1
fi
 
if [ "$WO_SSL" = "NO" ] || [ ! -z "$WO_SSL_KEY" ]; then
    echo "SSL not enabled, or manual SSL key specified, exiting."
    exit 1
fi
 
DOMAIN="${WO_HOST:=$1}"
if [ -z $DOMAIN ]; then
    echo "Usage: $0 <my.domain.com>"
    exit 1
fi
 
# Stop nginx if needed (free the port used by the standalone server)
nginx_was_running="NO"
pgrep nginx > /dev/null
if [ $? -eq 0 ]; then
    killall nginx
    nginx_was_running="YES"
fi
 
# Generate/update certificate
certbot certonly --http-01-port 8080 --work-dir ./letsencrypt --config-dir ./letsencrypt --logs-dir ./letsencrypt --standalone -d $DOMAIN --register-unsafely-without-email --agree-tos --keep
 
# Create ssl dir if necessary
if [ ! -e ssl/ ]; then
    mkdir ssl
fi
 
# Update symlinks
if [ -e ssl/key.pem ]; then
    rm ssl/key.pem
fi
 
if [ -e ssl/cert.pem ]; then
    rm ssl/cert.pem
fi
 
if [ -e "letsencrypt/live/$DOMAIN" ]; then
    ln -vs "../letsencrypt/live/$DOMAIN/privkey.pem" ssl/key.pem
    ln -vs "../letsencrypt/live/$DOMAIN/fullchain.pem" ssl/cert.pem
else
    echo -e "\033[91mWARN: We couldn't automatically generate the SSL certificate. Review the console log. WebODM will likely be inaccessible.\033[39m"
fi
 
# Restart nginx if necessary
if [ "$nginx_was_running" = "YES" ]; then
    echo "Restarting nginx..."
    nginx -c $(pwd)/nginx-ssl.conf
fi