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.

install-letsencrypt-cert.sh 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/bash
  2. set -e
  3. echo "-------------------------------------------------------------------------"
  4. echo "This script will:"
  5. echo "- Need a working DNS record pointing to this machine(for hostname ${DOMAIN})"
  6. echo "- Install additional dependencies in order to request Let’s Encrypt certificate (acme.sh)"
  7. echo "- Configure and reload nginx or apache2, whichever is used"
  8. echo "- Configure the coturn server to use Let's Encrypt certificate and add required deploy hooks"
  9. echo "- Configure renew of certificate"
  10. echo ""
  11. EMAIL=$1
  12. if [ -z "$EMAIL" ]; then
  13. echo "You need to agree to the ACME server's Subscriber Agreement (https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf) "
  14. echo "by providing an email address for important account notifications"
  15. echo -n "Enter your email and press [ENTER]: "
  16. read EMAIL
  17. fi
  18. DOMAIN=$2
  19. if [ -z "$DOMAIN" ]; then
  20. DEB_CONF_RESULT=$(debconf-show jitsi-meet-web-config | grep jitsi-meet/jvb-hostname)
  21. DOMAIN="${DEB_CONF_RESULT##*:}"
  22. fi
  23. # remove whitespace
  24. DOMAIN="$(echo -e "${DOMAIN}" | tr -d '[:space:]')"
  25. export HOME=/opt/acmesh
  26. curl https://get.acme.sh | sh -s email=$EMAIL
  27. # Checks whether nginx or apache is installed
  28. NGINX_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'nginx' 2>/dev/null | awk '{print $3}' || true)"
  29. NGINX_FULL_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'nginx-full' 2>/dev/null | awk '{print $3}' || true)"
  30. NGINX_EXTRAS_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'nginx-extras' 2>/dev/null | awk '{print $3}' || true)"
  31. OPENRESTY_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'openresty' 2>/dev/null | awk '{print $3}' || true)"
  32. APACHE_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'apache2' 2>/dev/null | awk '{print $3}' || true)"
  33. RELOAD_CMD=""
  34. if [ "$NGINX_INSTALL_CHECK" = "installed" ] || [ "$NGINX_INSTALL_CHECK" = "unpacked" ] \
  35. || [ "$NGINX_FULL_INSTALL_CHECK" = "installed" ] || [ "$NGINX_FULL_INSTALL_CHECK" = "unpacked" ] \
  36. || [ "$NGINX_EXTRAS_INSTALL_CHECK" = "installed" ] || [ "$NGINX_EXTRAS_INSTALL_CHECK" = "unpacked" ]; then
  37. RELOAD_CMD="systemctl force-reload nginx.service"
  38. elif [ "$OPENRESTY_INSTALL_CHECK" = "installed" ] || [ "$OPENRESTY_INSTALL_CHECK" = "unpacked" ] ; then
  39. RELOAD_CMD="systemctl force-reload openresty.service"
  40. elif [ "$APACHE_INSTALL_CHECK" = "installed" ] || [ "$APACHE_INSTALL_CHECK" = "unpacked" ] ; then
  41. RELOAD_CMD="systemctl force-reload apache2.service"
  42. else
  43. RELOAD_CMD="echo 'No webserver found'"
  44. fi
  45. RELOAD_CMD+=" && /usr/share/jitsi-meet/scripts/coturn-le-update.sh ${DOMAIN}"
  46. ISSUE_FAILED_CODE=0
  47. ISSUE_CERT_CMD="/opt/acmesh/.acme.sh/acme.sh -f --issue -d ${DOMAIN} -w /usr/share/jitsi-meet --server letsencrypt"
  48. eval "${ISSUE_CERT_CMD}" || ISSUE_FAILED_CODE=$?
  49. INSTALL_CERT_CMD="/opt/acmesh/.acme.sh/acme.sh -f --install-cert -d ${DOMAIN} --key-file /etc/jitsi/meet/${DOMAIN}.key --fullchain-file /etc/jitsi/meet/${DOMAIN}.crt --reloadcmd \"${RELOAD_CMD}\""
  50. if [ ${ISSUE_FAILED_CODE} -ne 0 ] ; then
  51. # it maybe this certificate already exists (code 2 - skip, no need to renew)
  52. if [ ${ISSUE_FAILED_CODE} -eq 2 ]; then
  53. eval "$INSTALL_CERT_CMD"
  54. else
  55. echo "Issuing the certificate from Let's Encrypt failed, continuing ..."
  56. echo "You can retry later by executing:"
  57. echo "/usr/share/jitsi-meet/scripts/install-letsencrypt-cert.sh $EMAIL"
  58. fi
  59. else
  60. eval "$INSTALL_CERT_CMD"
  61. fi