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

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