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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 ""
  15. 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) "
  16. echo "by providing an email address for important account notifications"
  17. echo -n "Enter your email and press [ENTER]: "
  18. read EMAIL
  19. cd /usr/local/sbin
  20. if [ ! -f certbot-auto ] ; then
  21. wget https://dl.eff.org/certbot-auto
  22. chmod a+x ./certbot-auto
  23. fi
  24. CRON_FILE="/etc/cron.weekly/letsencrypt-renew"
  25. if [ ! -d "/etc/cron.weekly" ] ; then
  26. mkdir "/etc/cron.weekly"
  27. fi
  28. echo "#!/bin/bash" > $CRON_FILE
  29. echo "/usr/local/sbin/certbot-auto renew >> /var/log/le-renew.log" >> $CRON_FILE
  30. CERT_KEY="/etc/letsencrypt/live/$DOMAIN/privkey.pem"
  31. CERT_CRT="/etc/letsencrypt/live/$DOMAIN/fullchain.pem"
  32. if [ -f /etc/nginx/sites-enabled/$DOMAIN.conf ] ; then
  33. ./certbot-auto certonly --noninteractive \
  34. --webroot --webroot-path /usr/share/jitsi-meet \
  35. -d $DOMAIN \
  36. --agree-tos --email $EMAIL
  37. echo "Configuring nginx"
  38. CONF_FILE="/etc/nginx/sites-available/$DOMAIN.conf"
  39. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  40. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  41. sed -i "s/ssl_certificate_key\ \/etc\/jitsi\/meet\/.*key/ssl_certificate_key\ $CERT_KEY_ESC/g" \
  42. $CONF_FILE
  43. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  44. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  45. sed -i "s/ssl_certificate\ \/etc\/jitsi\/meet\/.*crt/ssl_certificate\ $CERT_CRT_ESC/g" \
  46. $CONF_FILE
  47. echo "service nginx reload" >> $CRON_FILE
  48. service nginx reload
  49. TURN_CONFIG="/etc/turnserver.conf"
  50. if [ -f $TURN_CONFIG ] && grep -q "jitsi-meet coturn config" "$TURN_CONFIG" ; then
  51. echo "Configuring turnserver"
  52. sed -i "s/cert=\/etc\/jitsi\/meet\/.*crt/cert=$CERT_CRT_ESC/g" $TURN_CONFIG
  53. sed -i "s/pkey=\/etc\/jitsi\/meet\/.*key/pkey=$CERT_KEY_ESC/g" $TURN_CONFIG
  54. echo "service coturn restart" >> $CRON_FILE
  55. service coturn restart
  56. fi
  57. elif [ -f /etc/apache2/sites-enabled/$DOMAIN.conf ] ; then
  58. ./certbot-auto certonly --noninteractive \
  59. --webroot --webroot-path /usr/share/jitsi-meet \
  60. -d $DOMAIN \
  61. --agree-tos --email $EMAIL
  62. echo "Configuring apache2"
  63. CONF_FILE="/etc/apache2/sites-available/$DOMAIN.conf"
  64. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  65. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  66. sed -i "s/SSLCertificateKeyFile\ \/etc\/jitsi\/meet\/.*key/SSLCertificateKeyFile\ $CERT_KEY_ESC/g" \
  67. $CONF_FILE
  68. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  69. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  70. sed -i "s/SSLCertificateFile\ \/etc\/jitsi\/meet\/.*crt/SSLCertificateFile\ $CERT_CRT_ESC/g" \
  71. $CONF_FILE
  72. echo "service apache2 reload" >> $CRON_FILE
  73. service apache2 reload
  74. else
  75. service jitsi-videobridge stop
  76. ./certbot-auto certonly --noninteractive \
  77. --standalone \
  78. -d $DOMAIN \
  79. --agree-tos --email $EMAIL
  80. echo "Configuring jetty"
  81. CERT_P12="/etc/jitsi/videobridge/$DOMAIN.p12"
  82. CERT_JKS="/etc/jitsi/videobridge/$DOMAIN.jks"
  83. # create jks from certs
  84. openssl pkcs12 -export \
  85. -in $CERT_CRT -inkey $CERT_KEY -passout pass:changeit > $CERT_P12
  86. keytool -importkeystore -destkeystore $CERT_JKS \
  87. -srckeystore $CERT_P12 -srcstoretype pkcs12 \
  88. -noprompt -storepass changeit -srcstorepass changeit
  89. service jitsi-videobridge start
  90. fi
  91. # the cron file that will renew certificates
  92. chmod a+x $CRON_FILE