10-config 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/with-contenv bash
  2. # make our folders
  3. mkdir -p \
  4. /config/{nginx/site-confs,keys} \
  5. /run \
  6. /var/lib/nginx/tmp/client_body \
  7. /var/tmp/nginx
  8. # generate keys (maybe)
  9. if [[ $DISABLE_HTTPS -ne 1 ]]; then
  10. if [[ $ENABLE_LETSENCRYPT -eq 1 ]]; then
  11. mkdir -p /config/acme.sh
  12. pushd /opt
  13. sh ./acme.sh --install --home /config/acme.sh --accountemail $LETSENCRYPT_EMAIL
  14. popd
  15. STAGING=""
  16. if [[ $LETSENCRYPT_USE_STAGING -eq 1 ]]; then
  17. STAGING="--staging"
  18. fi
  19. export LE_WORKING_DIR="/config/acme.sh"
  20. # TODO: move away from standalone mode to webroot mode.
  21. /config/acme.sh/acme.sh \
  22. $STAGING \
  23. --issue \
  24. --standalone \
  25. --pre-hook "if [[ -d /var/run/s6/services/nginx ]]; then s6-svc -d /var/run/s6/services/nginx; fi" \
  26. --post-hook "if [[ -d /var/run/s6/services/nginx ]]; then s6-svc -u /var/run/s6/services/nginx; fi" \
  27. -d $LETSENCRYPT_DOMAIN
  28. rc=$?
  29. if [[ $rc -eq 1 ]]; then
  30. echo "Failed to obtain a certificate from the Let's Encrypt CA."
  31. # this tries to get the user's attention and to spare the
  32. # authority's rate limit:
  33. sleep 15
  34. echo "Exiting."
  35. exit 1
  36. fi
  37. if [[ $rc -eq 0 ]]; then
  38. mkdir -p /config/acme-certs/$LETSENCRYPT_DOMAIN
  39. if ! /config/acme.sh/acme.sh \
  40. --install-cert -d $LETSENCRYPT_DOMAIN \
  41. --key-file /config/acme-certs/$LETSENCRYPT_DOMAIN/key.pem \
  42. --fullchain-file /config/acme-certs/$LETSENCRYPT_DOMAIN/fullchain.pem ; then
  43. echo "Failed to install certificate."
  44. # this tries to get the user's attention and to spare the
  45. # authority's rate limit:
  46. sleep 15
  47. echo "Exiting."
  48. exit 1
  49. fi
  50. fi
  51. else
  52. # use self-signed certs
  53. if [[ -f /config/keys/cert.key && -f /config/keys/cert.crt ]]; then
  54. echo "using keys found in /config/keys"
  55. else
  56. echo "generating self-signed keys in /config/keys, you can replace these with your own keys if required"
  57. SUBJECT="/C=US/ST=TX/L=Austin/O=jitsi.org/OU=Jitsi Server/CN=*"
  58. openssl req -new -x509 -days 3650 -nodes -out /config/keys/cert.crt -keyout /config/keys/cert.key -subj "$SUBJECT"
  59. fi
  60. fi
  61. fi
  62. # Detect nameserver for Nginx, if not specified.
  63. if [[ -z "$NGINX_RESOLVER" ]]; then
  64. IP_LIST=""
  65. # Parse IPs in /etc/resolv.conf, taking into account IPv6 addresses need to be
  66. # enclosed in square brackets for the Nginx config file.
  67. while read -r line; do
  68. if [[ $line =~ ^nameserver.* ]]; then
  69. IP=$(echo $line | cut -d" " -f2)
  70. COLONS=$(echo $IP | tr -dc ":" | awk '{ print length '})
  71. if [[ $COLONS -ge 2 ]]; then
  72. IP="[$IP]"
  73. fi
  74. if [[ ! "$IP_LIST" = "" ]]; then
  75. IP_LIST+=" "
  76. fi
  77. IP_LIST+="$IP"
  78. fi
  79. done < <(cat /etc/resolv.conf)
  80. export NGINX_RESOLVER=$IP_LIST
  81. fi
  82. echo "Using Nginx resolver: =$NGINX_RESOLVER="
  83. # copy config files
  84. tpl /defaults/nginx.conf > /config/nginx/nginx.conf
  85. tpl /defaults/meet.conf > /config/nginx/meet.conf
  86. if [[ -f /config/nginx/custom-meet.conf ]]; then
  87. cat /config/nginx/custom-meet.conf >> /config/nginx/meet.conf
  88. fi
  89. tpl /defaults/ssl.conf > /config/nginx/ssl.conf
  90. tpl /defaults/default > /config/nginx/site-confs/default
  91. tpl /defaults/system-config.js > /config/config.js
  92. tpl /defaults/settings-config.js >> /config/config.js
  93. if [[ -f /config/custom-config.js ]]; then
  94. cat /config/custom-config.js >> /config/config.js
  95. fi
  96. cp /defaults/interface_config.js /config/interface_config.js
  97. if [[ -f /config/custom-interface_config.js ]]; then
  98. cat /config/custom-interface_config.js >> /config/interface_config.js
  99. fi