2015-09-11 22:05:54 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2021-09-28 20:48:41 +13:00
|
|
|
function _check_unix_socket() {
|
2021-09-25 15:47:20 +12:00
|
|
|
# Warn if the DOCKER_HOST socket does not exist
|
2021-09-25 16:06:11 +12:00
|
|
|
if [[ ${DOCKER_HOST} == unix://* ]]; then
|
|
|
|
local SOCKET_FILE="${DOCKER_HOST#unix://}"
|
|
|
|
|
|
|
|
if [[ ! -S ${SOCKET_FILE} ]]; then
|
2021-09-25 15:47:20 +12:00
|
|
|
cat >&2 <<-EOT
|
2021-09-25 16:06:11 +12:00
|
|
|
ERROR: you need to share your Docker host socket with a volume at ${SOCKET_FILE}
|
|
|
|
Typically you should run your nginxproxy/nginx-proxy with: \`-v /var/run/docker.sock:${SOCKET_FILE}:ro\`
|
2021-09-25 16:29:03 +12:00
|
|
|
See the documentation at: https://github.com/nginx-proxy/nginx-proxy/#usage
|
2021-09-25 15:47:20 +12:00
|
|
|
EOT
|
2021-09-28 11:11:49 +13:00
|
|
|
|
2021-09-25 15:47:20 +12:00
|
|
|
exit 1
|
|
|
|
fi
|
2015-09-11 22:05:54 +00:00
|
|
|
fi
|
2021-09-28 20:48:41 +13:00
|
|
|
}
|
2015-09-12 10:37:21 +00:00
|
|
|
|
2021-09-28 20:48:41 +13:00
|
|
|
function _resolvers() {
|
2021-09-25 15:47:20 +12:00
|
|
|
# Compute the DNS resolvers for use in the templates - if the IP contains ":", it's IPv6 and must be enclosed in []
|
|
|
|
RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g'); export RESOLVERS
|
2021-02-05 19:56:56 +00:00
|
|
|
|
2021-09-25 16:06:11 +12:00
|
|
|
SCOPED_IPV6_REGEX='\[fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}\]'
|
2021-02-05 19:56:56 +00:00
|
|
|
|
2021-09-25 16:06:11 +12:00
|
|
|
if [[ -z ${RESOLVERS} ]]; then
|
|
|
|
echo 'Warning: unable to determine DNS resolvers for nginx' >&2
|
2021-09-25 15:47:20 +12:00
|
|
|
unset RESOLVERS
|
2021-09-25 16:06:11 +12:00
|
|
|
elif [[ ${RESOLVERS} =~ ${SCOPED_IPV6_REGEX} ]]; then
|
|
|
|
echo -n 'Warning: Scoped IPv6 addresses removed from resolvers: ' >&2
|
|
|
|
echo "${RESOLVERS}" | grep -Eo "$SCOPED_IPV6_REGEX" | paste -s -d ' ' >&2
|
|
|
|
RESOLVERS=$(echo "${RESOLVERS}" | sed -r "s/${SCOPED_IPV6_REGEX}//g" | xargs echo -n); export RESOLVERS
|
2021-09-25 15:47:20 +12:00
|
|
|
fi
|
2021-09-28 11:11:49 +13:00
|
|
|
}
|
|
|
|
|
2021-09-28 20:57:03 +13:00
|
|
|
function _setup_dhparam() {
|
|
|
|
echo 'Setting up DH Parameters..'
|
|
|
|
|
|
|
|
# DH params will be supplied for nginx here:
|
2021-09-26 16:51:37 +13:00
|
|
|
local DHPARAM_FILE='/etc/nginx/dhparam/dhparam.pem'
|
2021-09-28 20:57:03 +13:00
|
|
|
|
2021-09-26 16:51:37 +13:00
|
|
|
# Should be 2048, 3072, or 4096 (default):
|
|
|
|
local FFDHE_GROUP="${DHPARAM_BITS:=4096}"
|
|
|
|
|
|
|
|
# DH params may be provided by the user (rarely necessary)
|
2021-09-25 16:06:11 +12:00
|
|
|
if [[ -f ${DHPARAM_FILE} ]]; then
|
2021-09-28 20:57:03 +13:00
|
|
|
echo 'Warning: A custom dhparam.pem file was provided. Best practice is to use standardized RFC7919 DHE groups instead.' >&2
|
2021-09-26 16:51:37 +13:00
|
|
|
return 0
|
2021-09-28 21:49:06 +13:00
|
|
|
elif [[ ${DHPARAM_SKIP:=0} -eq 1 ]]; then
|
|
|
|
echo 'Skipping Diffie-Hellman parameters setup.'
|
|
|
|
return 0
|
2021-09-26 16:51:37 +13:00
|
|
|
elif [[ ! ${DHPARAM_BITS} =~ ^(2048|3072|4096)$ ]]; then
|
|
|
|
echo "ERROR: Unsupported DHPARAM_BITS size: ${DHPARAM_BITS}. Use: 2048, 3072, or 4096 (default)." >&2
|
|
|
|
exit 1
|
2021-09-28 20:57:03 +13:00
|
|
|
fi
|
2021-09-26 16:51:37 +13:00
|
|
|
|
|
|
|
# Use an existing pre-generated DH group from RFC7919 (https://datatracker.ietf.org/doc/html/rfc7919#appendix-A):
|
|
|
|
local RFC7919_DHPARAM_FILE="/app/dhparam/ffdhe${FFDHE_GROUP}.pem"
|
|
|
|
|
|
|
|
# Provide the DH params file to nginx:
|
|
|
|
cp "${RFC7919_DHPARAM_FILE}" "${DHPARAM_FILE}"
|
2021-09-28 20:57:03 +13:00
|
|
|
}
|
|
|
|
|
2021-09-28 11:11:49 +13:00
|
|
|
# Run the init logic if the default CMD was provided
|
|
|
|
if [[ $* == 'forego start -r' ]]; then
|
2021-09-28 20:48:41 +13:00
|
|
|
_check_unix_socket
|
|
|
|
|
|
|
|
_resolvers
|
|
|
|
|
|
|
|
_setup_dhparam
|
2021-09-28 11:11:49 +13:00
|
|
|
fi
|
2016-10-01 10:42:58 -04:00
|
|
|
|
2015-09-12 10:37:21 +00:00
|
|
|
exec "$@"
|