10-config 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. ACME_SERVER=""
  20. if [[ ! -z $LETSENCRYPT_ACME_SERVER ]]; then
  21. ACME_SERVER="--set-default-ca --server $LETSENCRYPT_ACME_SERVER"
  22. echo "Using custom ACME server: $LETSENCRYPT_ACME_SERVER"
  23. fi
  24. export LE_WORKING_DIR="/config/acme.sh"
  25. # TODO: move away from standalone mode to webroot mode.
  26. /config/acme.sh/acme.sh \
  27. $STAGING \
  28. $ACME_SERVER \
  29. --issue \
  30. --standalone \
  31. --pre-hook "if [[ -d /var/run/s6/services/nginx ]]; then s6-svc -d /var/run/s6/services/nginx; fi" \
  32. --post-hook "if [[ -d /var/run/s6/services/nginx ]]; then s6-svc -u /var/run/s6/services/nginx; fi" \
  33. -d $LETSENCRYPT_DOMAIN
  34. rc=$?
  35. if [[ $rc -eq 1 ]]; then
  36. echo "Failed to obtain a certificate from the Let's Encrypt CA."
  37. # this tries to get the user's attention and to spare the
  38. # authority's rate limit:
  39. sleep 15
  40. echo "Exiting."
  41. exit 1
  42. fi
  43. if [[ $rc -eq 0 ]]; then
  44. mkdir -p /config/acme-certs/$LETSENCRYPT_DOMAIN
  45. if ! /config/acme.sh/acme.sh \
  46. --install-cert -d $LETSENCRYPT_DOMAIN \
  47. --key-file /config/acme-certs/$LETSENCRYPT_DOMAIN/key.pem \
  48. --fullchain-file /config/acme-certs/$LETSENCRYPT_DOMAIN/fullchain.pem ; then
  49. echo "Failed to install certificate."
  50. # this tries to get the user's attention and to spare the
  51. # authority's rate limit:
  52. sleep 15
  53. echo "Exiting."
  54. exit 1
  55. fi
  56. fi
  57. else
  58. # use self-signed certs
  59. if [[ -f /config/keys/cert.key && -f /config/keys/cert.crt ]]; then
  60. echo "using keys found in /config/keys"
  61. else
  62. echo "generating self-signed keys in /config/keys, you can replace these with your own keys if required"
  63. SUBJECT="/C=US/ST=TX/L=Austin/O=jitsi.org/OU=Jitsi Server/CN=*"
  64. openssl req -new -x509 -days 3650 -nodes -out /config/keys/cert.crt -keyout /config/keys/cert.key -subj "$SUBJECT"
  65. fi
  66. fi
  67. fi
  68. # Detect nameserver for Nginx, if not specified.
  69. if [[ -z "$NGINX_RESOLVER" ]]; then
  70. IP_LIST=""
  71. # Parse IPs in /etc/resolv.conf, taking into account IPv6 addresses need to be
  72. # enclosed in square brackets for the Nginx config file.
  73. while read -r line; do
  74. if [[ $line =~ ^nameserver.* ]]; then
  75. IP=$(echo $line | cut -d" " -f2)
  76. COLONS=$(echo $IP | tr -dc ":" | awk '{ print length '})
  77. if [[ $COLONS -ge 2 ]]; then
  78. IP="[$IP]"
  79. fi
  80. if [[ ! "$IP_LIST" = "" ]]; then
  81. IP_LIST+=" "
  82. fi
  83. IP_LIST+="$IP"
  84. fi
  85. done < <(cat /etc/resolv.conf)
  86. export NGINX_RESOLVER=$IP_LIST
  87. fi
  88. echo "Using Nginx resolver: =$NGINX_RESOLVER="
  89. # colibri-ws settings
  90. COLIBRI_WEBSOCKET_UNSAFE_REGEX="[a-zA-Z0-9-\._]+"
  91. # use custom websocket regex if provided
  92. if [ -z "$COLIBRI_WEBSOCKET_REGEX" ]; then
  93. # default to the previous unsafe behavior only if flag is set
  94. if [[ "$ENABLE_COLIBRI_WEBSOCKET_UNSAFE_REGEX" == "1" ]]; then
  95. export COLIBRI_WEBSOCKET_REGEX="$COLIBRI_WEBSOCKET_UNSAFE_REGEX"
  96. else
  97. # default value to the JVB IP, works in compose and anywhere a dns lookup of the JVB reveals the correct IP for proxying
  98. [ -z "$COLIBRI_WEBSOCKET_JVB_LOOKUP_NAME" ] && export COLIBRI_WEBSOCKET_JVB_LOOKUP_NAME="jvb"
  99. if [[ "$DISABLE_COLIBRI_WEBSOCKET_JVB_LOOKUP" == "1" ]]; then
  100. # otherwise value default to the static value in the template 'jvb'
  101. 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"
  102. else
  103. export COLIBRI_WEBSOCKET_REGEX="$(dig +short +search $COLIBRI_WEBSOCKET_JVB_LOOKUP_NAME)"
  104. fi
  105. fi
  106. fi
  107. # maintain backward compatibility with older variable
  108. [ -z "${XMPP_HIDDEN_DOMAIN}" ] && export XMPP_HIDDEN_DOMAIN="$XMPP_RECORDER_DOMAIN"
  109. # copy config files
  110. tpl /defaults/nginx.conf > /config/nginx/nginx.conf
  111. tpl /defaults/meet.conf > /config/nginx/meet.conf
  112. if [[ -f /config/nginx/custom-meet.conf ]]; then
  113. cat /config/nginx/custom-meet.conf >> /config/nginx/meet.conf
  114. fi
  115. tpl /defaults/ssl.conf > /config/nginx/ssl.conf
  116. tpl /defaults/default > /config/nginx/site-confs/default
  117. tpl /defaults/system-config.js > /config/config.js
  118. tpl /defaults/settings-config.js >> /config/config.js
  119. if [[ -f /config/custom-config.js ]]; then
  120. cat /config/custom-config.js >> /config/config.js
  121. fi
  122. cp /defaults/interface_config.js /config/interface_config.js
  123. if [[ -f /config/custom-interface_config.js ]]; then
  124. cat /config/custom-interface_config.js >> /config/interface_config.js
  125. fi