You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.3 KiB

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