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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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" ]; then
  26. apt-get update
  27. apt-get -y install certbot
  28. elif [ "$DISTRO" = "Ubuntu" ]; then
  29. if [ "$DISTRO_VERSION" = "20.04" ] || [ "$DISTRO_VERSION" = "19.10" ]; then
  30. apt-get update
  31. apt-get -y install software-properties-common
  32. add-apt-repository -y universe
  33. apt-get update
  34. apt-get -y install certbot
  35. elif [ "$DISTRO_VERSION" = "18.04" ]; then
  36. apt-get update
  37. apt-get -y install software-properties-common
  38. add-apt-repository -y universe
  39. add-apt-repository -y ppa:certbot/certbot
  40. apt-get update
  41. apt-get -y install certbot
  42. fi
  43. else
  44. echo "$DISTRO $DISTRO_VERSION is not supported"
  45. echo "Only Debian 9,10 and Ubuntu 18.04,19.10,20.04 are supported"
  46. exit 1
  47. fi
  48. CERTBOT="$(command -v certbot)"
  49. fi
  50. CRON_FILE="/etc/cron.weekly/letsencrypt-renew"
  51. if [ ! -d "/etc/cron.weekly" ] ; then
  52. mkdir "/etc/cron.weekly"
  53. fi
  54. echo "#!/bin/bash" > $CRON_FILE
  55. echo "$CERTBOT renew >> /var/log/le-renew.log" >> $CRON_FILE
  56. CERT_KEY="/etc/letsencrypt/live/$DOMAIN/privkey.pem"
  57. CERT_CRT="/etc/letsencrypt/live/$DOMAIN/fullchain.pem"
  58. if [ -f /etc/nginx/sites-enabled/$DOMAIN.conf ] ; then
  59. TURN_CONFIG="/etc/turnserver.conf"
  60. TURN_HOOK=/etc/letsencrypt/renewal-hooks/deploy/0000-coturn-certbot-deploy.sh
  61. if [ -f $TURN_CONFIG ] && grep -q "jitsi-meet coturn config" "$TURN_CONFIG" ; then
  62. mkdir -p $(dirname $TURN_HOOK)
  63. cp /usr/share/jitsi-meet-turnserver/coturn-certbot-deploy.sh $TURN_HOOK
  64. chmod u+x $TURN_HOOK
  65. sed -i "s/jitsi-meet.example.com/$DOMAIN/g" $TURN_HOOK
  66. $CERTBOT certonly --noninteractive \
  67. --webroot --webroot-path /usr/share/jitsi-meet \
  68. -d $DOMAIN \
  69. --agree-tos --email $EMAIL \
  70. --deploy-hook $TURN_HOOK
  71. else
  72. $CERTBOT certonly --noninteractive \
  73. --webroot --webroot-path /usr/share/jitsi-meet \
  74. -d $DOMAIN \
  75. --agree-tos --email $EMAIL
  76. fi
  77. echo "Configuring nginx"
  78. CONF_FILE="/etc/nginx/sites-available/$DOMAIN.conf"
  79. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  80. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  81. sed -i "s/ssl_certificate_key\ \/etc\/jitsi\/meet\/.*key/ssl_certificate_key\ $CERT_KEY_ESC/g" \
  82. $CONF_FILE
  83. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  84. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  85. sed -i "s/ssl_certificate\ \/etc\/jitsi\/meet\/.*crt/ssl_certificate\ $CERT_CRT_ESC/g" \
  86. $CONF_FILE
  87. if type service >/dev/null 2>&1
  88. then
  89. service nginx reload
  90. echo "service nginx reload" >> $CRON_FILE
  91. else
  92. systemctl reload nginx.service
  93. echo "systemctl reload nginx.service" >> $CRON_FILE
  94. fi
  95. elif [ -f /etc/apache2/sites-enabled/$DOMAIN.conf ] ; then
  96. $CERTBOT certonly --noninteractive \
  97. --webroot --webroot-path /usr/share/jitsi-meet \
  98. -d $DOMAIN \
  99. --agree-tos --email $EMAIL
  100. echo "Configuring apache2"
  101. CONF_FILE="/etc/apache2/sites-available/$DOMAIN.conf"
  102. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  103. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  104. sed -i "s/SSLCertificateKeyFile\ \/etc\/jitsi\/meet\/.*key/SSLCertificateKeyFile\ $CERT_KEY_ESC/g" \
  105. $CONF_FILE
  106. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  107. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  108. sed -i "s/SSLCertificateFile\ \/etc\/jitsi\/meet\/.*crt/SSLCertificateFile\ $CERT_CRT_ESC/g" \
  109. $CONF_FILE
  110. if type service >/dev/null 2>&1
  111. then
  112. service apache2 reload
  113. echo "service apache2 reload" >> $CRON_FILE
  114. else
  115. systemctl reload apache2.service
  116. echo "systemctl reload apache2.service" >> $CRON_FILE
  117. fi
  118. fi
  119. # the cron file that will renew certificates
  120. chmod a+x $CRON_FILE