lets-encrypt-scripts/gen-unifi-cert.sh

57 lines
2.3 KiB
Bash
Raw Normal View History

2016-02-19 21:13:25 -07:00
#!/usr/bin/env bash
# Modified script from here: https://github.com/FarsetLabs/letsencrypt-helper-scripts/blob/master/letsencrypt-unifi.sh
# Modified by: Brielle Bruns <bruns@2mbit.com>
2016-02-27 14:19:29 -07:00
# Download URL: https://source.sosdg.org/brielle/lets-encrypt-scripts
# Last Changed: 2/27/2016
# 02/02/2016: Fixed some errors with key export/import, removed lame docker requirements
# 02/27/2016: More verbose progress report
# The main domain name of your controller
2016-02-19 21:13:25 -07:00
DOMAIN="unifi.xxxx.xxxxx"
2016-02-27 14:19:29 -07:00
# Your e-mail address for notifications of certificate issues
2016-02-19 21:13:25 -07:00
EMAIL="email@here"
2016-02-27 14:19:29 -07:00
# Identrust cross-signed CA cert needed by the java keystore for import.
# Can get original here: https://www.identrust.com/certificates/trustid/root-download-x3.html
2016-02-19 21:13:25 -07:00
EXTRACERT="/root/DSTROOTCAX3.txt"
2016-02-27 14:19:29 -07:00
2016-02-19 21:13:25 -07:00
TEMPFILE=$(mktemp)
2016-02-27 14:19:29 -07:00
echo "Stopping Unifi controller..."
2016-02-19 21:13:25 -07:00
service unifi stop
2016-02-27 14:19:29 -07:00
echo "Firing up standalone authenticator on TCP port 443 and requesting cert..."
2016-02-19 21:13:25 -07:00
/usr/src/letsencrypt/letsencrypt-auto \
--email ${EMAIL} \
--server https://acme-v01.api.letsencrypt.org/directory \
--agree-tos \
--renew-by-default \
-d ${DOMAIN} \
--standalone --standalone-supported-challenges tls-sni-01 \
certonly
2016-02-27 14:19:29 -07:00
echo "Using openssl to prepare certificate..."
2016-02-19 21:13:25 -07:00
openssl pkcs12 -export -passout pass:aircontrolenterprise \
-in /etc/letsencrypt/live/${DOMAIN}/cert.pem \
-inkey /etc/letsencrypt/live/${DOMAIN}/privkey.pem \
-out ${TEMPFILE} -name unifi \
-CAfile /etc/letsencrypt/live/${DOMAIN}/chain.pem -caname root
2016-02-27 14:19:29 -07:00
echo "Removing existing certificate from Unifi protected keystore..."
2016-02-19 21:13:25 -07:00
keytool -delete -alias unifi -keystore /usr/lib/unifi/data/keystore \
-deststorepass aircontrolenterprise
2016-02-27 14:19:29 -07:00
echo "Inserting certificate into Unifi keystore..."
2016-02-19 21:13:25 -07:00
keytool -trustcacerts -importkeystore \
-deststorepass aircontrolenterprise \
-destkeypass aircontrolenterprise \
-destkeystore /usr/lib/unifi/data/keystore \
-srckeystore ${TEMPFILE} -srcstoretype PKCS12 \
-srcstorepass aircontrolenterprise \
-alias unifi
rm -f ${TEMPFILE}
2016-02-27 14:19:29 -07:00
echo "Importing cert into Unifi database..."
2016-02-19 21:13:25 -07:00
java -jar /usr/lib/unifi/lib/ace.jar import_cert \
/etc/letsencrypt/live/${DOMAIN}/cert.pem \
/etc/letsencrypt/live/${DOMAIN}/chain.pem \
${EXTRACERT}
2016-02-27 14:19:29 -07:00
echo "Starting Unifi controller..."
2016-02-19 21:13:25 -07:00
service unifi start
2016-02-27 14:19:29 -07:00
echo "Done!"