您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

install-letsencrypt-cert.sh 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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)"
  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. fi
  49. CRON_FILE="/etc/cron.weekly/letsencrypt-renew"
  50. if [ ! -d "/etc/cron.weekly" ] ; then
  51. mkdir "/etc/cron.weekly"
  52. fi
  53. echo "#!/bin/bash" > $CRON_FILE
  54. echo "$CERTBOT renew >> /var/log/le-renew.log" >> $CRON_FILE
  55. CERT_KEY="/etc/letsencrypt/live/$DOMAIN/privkey.pem"
  56. CERT_CRT="/etc/letsencrypt/live/$DOMAIN/fullchain.pem"
  57. if [ -f /etc/nginx/sites-enabled/$DOMAIN.conf ] ; then
  58. TURN_CONFIG="/etc/turnserver.conf"
  59. TURN_HOOK=/etc/letsencrypt/renewal-hooks/deploy/0000-coturn-certbot-deploy.sh
  60. if [ -f $TURN_CONFIG ] && grep -q "jitsi-meet coturn config" "$TURN_CONFIG" ; then
  61. mkdir -p $(dirname $TURN_HOOK)
  62. cp /usr/share/jitsi-meet-turnserver/coturn-certbot-deploy.sh $TURN_HOOK
  63. chmod u+x $TURN_HOOK
  64. sed -i "s/jitsi-meet.example.com/$DOMAIN/g" $TURN_HOOK
  65. $CERTBOT certonly --noninteractive \
  66. --webroot --webroot-path /usr/share/jitsi-meet \
  67. -d $DOMAIN \
  68. --agree-tos --email $EMAIL \
  69. --deploy-hook $TURN_HOOK
  70. else
  71. $CERTBOT certonly --noninteractive \
  72. --webroot --webroot-path /usr/share/jitsi-meet \
  73. -d $DOMAIN \
  74. --agree-tos --email $EMAIL
  75. fi
  76. echo "Configuring nginx"
  77. CONF_FILE="/etc/nginx/sites-available/$DOMAIN.conf"
  78. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  79. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  80. sed -i "s/ssl_certificate_key\ \/etc\/jitsi\/meet\/.*key/ssl_certificate_key\ $CERT_KEY_ESC/g" \
  81. $CONF_FILE
  82. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  83. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  84. sed -i "s/ssl_certificate\ \/etc\/jitsi\/meet\/.*crt/ssl_certificate\ $CERT_CRT_ESC/g" \
  85. $CONF_FILE
  86. if type service >/dev/null 2>&1
  87. then
  88. service nginx reload
  89. echo "service nginx reload" >> $CRON_FILE
  90. else
  91. systemctl reload nginx.service
  92. echo "systemctl reload nginx.service" >> $CRON_FILE
  93. fi
  94. elif [ -f /etc/apache2/sites-enabled/$DOMAIN.conf ] ; then
  95. $CERTBOT certonly --noninteractive \
  96. --webroot --webroot-path /usr/share/jitsi-meet \
  97. -d $DOMAIN \
  98. --agree-tos --email $EMAIL
  99. echo "Configuring apache2"
  100. CONF_FILE="/etc/apache2/sites-available/$DOMAIN.conf"
  101. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  102. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  103. sed -i "s/SSLCertificateKeyFile\ \/etc\/jitsi\/meet\/.*key/SSLCertificateKeyFile\ $CERT_KEY_ESC/g" \
  104. $CONF_FILE
  105. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  106. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  107. sed -i "s/SSLCertificateFile\ \/etc\/jitsi\/meet\/.*crt/SSLCertificateFile\ $CERT_CRT_ESC/g" \
  108. $CONF_FILE
  109. if type service >/dev/null 2>&1
  110. then
  111. service apache2 reload
  112. echo "service apache2 reload" >> $CRON_FILE
  113. else
  114. systemctl reload apache2.service
  115. echo "systemctl reload apache2.service" >> $CRON_FILE
  116. fi
  117. fi
  118. # the cron file that will renew certificates
  119. chmod a+x $CRON_FILE