2
0

10-config 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. # colibri-ws settings
  84. COLIBRI_WEBSOCKET_UNSAFE_REGEX="[a-zA-Z0-9-\._]+"
  85. # use custom websocket regex if provided
  86. if [ -z "$COLIBRI_WEBSOCKET_REGEX" ]; then
  87. # default to the previous unsafe behavior only if flag is set
  88. if [[ "$ENABLE_COLIBRI_WEBSOCKET_UNSAFE_REGEX" == "1" ]]; then
  89. export COLIBRI_WEBSOCKET_REGEX="$COLIBRI_WEBSOCKET_UNSAFE_REGEX"
  90. else
  91. # default value to the JVB IP, works in compose and anywhere a dns lookup of the JVB reveals the correct IP for proxying
  92. [ -z "$COLIBRI_WEBSOCKET_JVB_LOOKUP_NAME" ] && export COLIBRI_WEBSOCKET_JVB_LOOKUP_NAME="jvb"
  93. if [[ "$DISABLE_COLIBRI_WEBSOCKET_JVB_LOOKUP" == "1" ]]; then
  94. # otherwise value default to the static value in the template 'jvb'
  95. echo "WARNING: DISABLE_COLIBRI_WEBSOCKET_JVB_LOOKUP is set and no value for COLIBRI_WEBSOCKET_REGEX was provided, using static value 'jvb' for COLIBRI_WEBSOCKET_REGEX"
  96. else
  97. export COLIBRI_WEBSOCKET_REGEX="$(dig +short +search $COLIBRI_WEBSOCKET_JVB_LOOKUP_NAME)"
  98. fi
  99. fi
  100. fi
  101. # maintain backward compatibility with older variable
  102. [ -z "${XMPP_HIDDEN_DOMAIN}" ] && export XMPP_HIDDEN_DOMAIN="$XMPP_RECORDER_DOMAIN"
  103. # copy config files
  104. tpl /defaults/nginx.conf > /config/nginx/nginx.conf
  105. tpl /defaults/meet.conf > /config/nginx/meet.conf
  106. if [[ -f /config/nginx/custom-meet.conf ]]; then
  107. cat /config/nginx/custom-meet.conf >> /config/nginx/meet.conf
  108. fi
  109. tpl /defaults/ssl.conf > /config/nginx/ssl.conf
  110. tpl /defaults/default > /config/nginx/site-confs/default
  111. tpl /defaults/system-config.js > /config/config.js
  112. tpl /defaults/settings-config.js >> /config/config.js
  113. if [[ -f /config/custom-config.js ]]; then
  114. cat /config/custom-config.js >> /config/config.js
  115. fi
  116. cp /defaults/interface_config.js /config/interface_config.js
  117. if [[ -f /config/custom-interface_config.js ]]; then
  118. cat /config/custom-interface_config.js >> /config/interface_config.js
  119. fi