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 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/bash
  2. set -e
  3. DEB_CONF_RESULT=`debconf-show jitsi-meet-web-config | grep jvb-hostname`
  4. DOMAIN="${DEB_CONF_RESULT##*:}"
  5. # remove whitespace
  6. DOMAIN="$(echo -e "${DOMAIN}" | tr -d '[:space:]')"
  7. echo "-------------------------------------------------------------------------"
  8. echo "This script will:"
  9. echo "- Need a working DNS record pointing to this machine(for domain ${DOMAIN})"
  10. echo "- Download certbot-auto from https://dl.eff.org to /usr/local/sbin"
  11. echo "- Install additional dependencies in order to request Let’s Encrypt certificate"
  12. echo "- If running with jetty serving web content, will stop Jitsi Videobridge"
  13. echo "- Configure and reload nginx or apache2, whichever is used"
  14. echo "- Configure the coturn server to use Let's Encrypt certificate and add required deploy hooks"
  15. echo "- Add command in weekly cron job to renew certificates regularly"
  16. echo ""
  17. 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) "
  18. echo "by providing an email address for important account notifications"
  19. echo -n "Enter your email and press [ENTER]: "
  20. read EMAIL
  21. CERTBOT="$(command -v certbot || true)"
  22. if [ ! -x "$CERTBOT" ] ; then
  23. DISTRO=$(lsb_release -is)
  24. DISTRO_VERSION=$(lsb_release -rs)
  25. if [ "$DISTRO" != "Debian" ] && [ "$DISTRO" != "Ubuntu" ]; then
  26. echo "$DISTRO $DISTRO_VERSION is not supported"
  27. echo "Only Debian and Ubuntu 18.04+ are supported"
  28. exit 1
  29. fi
  30. if [ "$DISTRO" = "Ubuntu" ]; then
  31. apt-get update
  32. apt-get -y install software-properties-common
  33. add-apt-repository -y universe
  34. if [ "$DISTRO_VERSION" = "18.04" ]; then
  35. add-apt-repository -y ppa:certbot/certbot
  36. fi
  37. fi
  38. apt-get update
  39. apt-get -y install certbot
  40. CERTBOT="$(command -v certbot)"
  41. fi
  42. CRON_FILE="/etc/cron.weekly/letsencrypt-renew"
  43. if [ ! -d "/etc/cron.weekly" ] ; then
  44. mkdir "/etc/cron.weekly"
  45. fi
  46. echo "#!/bin/bash" > $CRON_FILE
  47. echo "$CERTBOT renew >> /var/log/le-renew.log" >> $CRON_FILE
  48. CERT_KEY="/etc/letsencrypt/live/$DOMAIN/privkey.pem"
  49. CERT_CRT="/etc/letsencrypt/live/$DOMAIN/fullchain.pem"
  50. if [ -f /etc/nginx/sites-enabled/$DOMAIN.conf ] ; then
  51. TURN_CONFIG="/etc/turnserver.conf"
  52. TURN_HOOK=/etc/letsencrypt/renewal-hooks/deploy/0000-coturn-certbot-deploy.sh
  53. if [ -f $TURN_CONFIG ] && grep -q "jitsi-meet coturn config" "$TURN_CONFIG" ; then
  54. mkdir -p $(dirname $TURN_HOOK)
  55. cp /usr/share/jitsi-meet-turnserver/coturn-certbot-deploy.sh $TURN_HOOK
  56. chmod u+x $TURN_HOOK
  57. sed -i "s/jitsi-meet.example.com/$DOMAIN/g" $TURN_HOOK
  58. $CERTBOT certonly --noninteractive \
  59. --webroot --webroot-path /usr/share/jitsi-meet \
  60. -d $DOMAIN \
  61. --agree-tos --email $EMAIL \
  62. --deploy-hook $TURN_HOOK
  63. else
  64. $CERTBOT certonly --noninteractive \
  65. --webroot --webroot-path /usr/share/jitsi-meet \
  66. -d $DOMAIN \
  67. --agree-tos --email $EMAIL
  68. fi
  69. echo "Configuring nginx"
  70. CONF_FILE="/etc/nginx/sites-available/$DOMAIN.conf"
  71. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  72. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  73. sed -i "s/ssl_certificate_key\ \/etc\/jitsi\/meet\/.*key/ssl_certificate_key\ $CERT_KEY_ESC/g" \
  74. $CONF_FILE
  75. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  76. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  77. sed -i "s/ssl_certificate\ \/etc\/jitsi\/meet\/.*crt/ssl_certificate\ $CERT_CRT_ESC/g" \
  78. $CONF_FILE
  79. if type service >/dev/null 2>&1
  80. then
  81. service nginx reload
  82. echo "service nginx reload" >> $CRON_FILE
  83. else
  84. systemctl reload nginx.service
  85. echo "systemctl reload nginx.service" >> $CRON_FILE
  86. fi
  87. elif [ -f /etc/apache2/sites-enabled/$DOMAIN.conf ] ; then
  88. $CERTBOT certonly --noninteractive \
  89. --webroot --webroot-path /usr/share/jitsi-meet \
  90. -d $DOMAIN \
  91. --agree-tos --email $EMAIL
  92. echo "Configuring apache2"
  93. CONF_FILE="/etc/apache2/sites-available/$DOMAIN.conf"
  94. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  95. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  96. sed -i "s/SSLCertificateKeyFile\ \/etc\/jitsi\/meet\/.*key/SSLCertificateKeyFile\ $CERT_KEY_ESC/g" \
  97. $CONF_FILE
  98. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  99. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  100. sed -i "s/SSLCertificateFile\ \/etc\/jitsi\/meet\/.*crt/SSLCertificateFile\ $CERT_CRT_ESC/g" \
  101. $CONF_FILE
  102. if type service >/dev/null 2>&1
  103. then
  104. service apache2 reload
  105. echo "service apache2 reload" >> $CRON_FILE
  106. else
  107. systemctl reload apache2.service
  108. echo "systemctl reload apache2.service" >> $CRON_FILE
  109. fi
  110. fi
  111. # the cron file that will renew certificates
  112. chmod a+x $CRON_FILE