-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathletsencrypt.sh
More file actions
executable file
·53 lines (40 loc) · 1.35 KB
/
letsencrypt.sh
File metadata and controls
executable file
·53 lines (40 loc) · 1.35 KB
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
# mkdir public
# touch public/index.html
# This script will generate a valid letsencrypt cert for the provided domainName
# Server MUST be associated with the domain for this to work
#
# To run:
# ./letsencrypt.sh <dns> <email>
# Example:
# ./letsencrypt.sh oxartest.odbopensource.com martin@odbopensource.com
domainName=$1
emailAddress=$2
syntax="./letsencrypt.sh <domainName> <emailAddress>"
# Validation
if [[ $(whoami) != "root" ]]; then
echo "This script must be run as root."
echo "Try: sudo $syntax"
exit 1
fi
if [[ -z "$domainName" ]]; then
echo "Missing Domain Name. Example: $syntax"
exit 1
fi
if [[ -z "$emailAddress" ]]; then
echo "Missing Email Address. Example: $syntax"
exit 1
fi
# To lowercase
domainName="${domainName,,}"
emailAddress="${emailAddress,,}"
# stop node4ords
# Need to do this since it's using port 80 and certbot needs to create a simple web server to prove domain ownership
pm2 stop node4ords
# Generate cert
certbot certonly --standalone -d $domainName -m $emailAddress --agree-tos
# Update Node4ORDS with new config
cd /opt/node4ords
sed -ri "s/(^config\.web\.https\.keyPath\s+=)[^=]*$/\1 '\/etc\/letsencrypt\/live\/$domainName\/privkey.pem'/" config.js
sed -ri "s/(^config\.web\.https\.certPath\s+=)[^=]*$/\1 '\/etc\/letsencrypt\/live\/$domainName\/fullchain.pem'/" config.js
# pm2 stop simpleweb
pm2 start node4ords --watch