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

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