2015-12-31 18:50:25 +01:00
|
|
|
#!/bin/bash
|
2017-11-22 00:19:14 +01:00
|
|
|
# shellcheck disable=SC2155
|
2015-12-31 18:50:25 +01:00
|
|
|
|
2016-01-03 12:31:24 +01:00
|
|
|
set -u
|
|
|
|
|
2018-01-11 21:45:54 +01:00
|
|
|
if [[ -n "${ACME_TOS_HASH:-}" ]]; then
|
2018-02-08 23:57:50 +01:00
|
|
|
echo "Info: the ACME_TOS_HASH environment variable is no longer used by simp_le and has been deprecated."
|
|
|
|
echo "simp_le now implicitly agree to the ACME CA ToS."
|
2018-01-11 21:45:54 +01:00
|
|
|
fi
|
|
|
|
|
2015-12-31 18:50:25 +01:00
|
|
|
function check_docker_socket {
|
2016-01-06 19:33:16 +01:00
|
|
|
if [[ $DOCKER_HOST == unix://* ]]; then
|
|
|
|
socket_file=${DOCKER_HOST#unix://}
|
|
|
|
if [[ ! -S $socket_file ]]; then
|
2018-02-08 23:57:50 +01:00
|
|
|
echo "Error: you need to share your Docker host socket with a volume at $socket_file" >&2
|
|
|
|
echo "Typically you should run your container with: '-v /var/run/docker.sock:$socket_file:ro'" >&2
|
2016-01-06 19:33:16 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2015-12-31 18:50:25 +01:00
|
|
|
}
|
2016-01-06 19:33:16 +01:00
|
|
|
|
2015-12-31 18:50:25 +01:00
|
|
|
function check_writable_directory {
|
|
|
|
local dir="$1"
|
2018-05-20 18:15:10 +02:00
|
|
|
docker_api "/containers/${SELF_CID:-$(get_self_cid)}/json" | jq ".Mounts[].Destination" | grep -q "^\"$dir\"$"
|
2016-08-18 04:16:00 +02:00
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
echo "Warning: '$dir' does not appear to be a mounted volume."
|
|
|
|
fi
|
2015-12-31 18:50:25 +01:00
|
|
|
if [[ ! -d "$dir" ]]; then
|
|
|
|
echo "Error: can't access to '$dir' directory !" >&2
|
2018-02-10 00:11:24 +01:00
|
|
|
echo "Check that '$dir' directory is declared as a writable volume." >&2
|
2015-12-31 18:50:25 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
touch $dir/.check_writable 2>/dev/null
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
echo "Error: can't write to the '$dir' directory !" >&2
|
|
|
|
echo "Check that '$dir' directory is export as a writable volume." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
rm -f $dir/.check_writable
|
|
|
|
}
|
|
|
|
|
2016-01-05 14:03:22 +01:00
|
|
|
function check_dh_group {
|
2017-08-25 09:03:52 +02:00
|
|
|
local DHPARAM_BITS="${DHPARAM_BITS:-2048}"
|
|
|
|
re='^[0-9]*$'
|
|
|
|
if ! [[ "$DHPARAM_BITS" =~ $re ]] ; then
|
|
|
|
echo "Error: invalid Diffie-Hellman size of $DHPARAM_BITS !" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-01-05 14:03:22 +01:00
|
|
|
if [[ ! -f /etc/nginx/certs/dhparam.pem ]]; then
|
|
|
|
echo "Creating Diffie-Hellman group (can take several minutes...)"
|
2017-08-25 09:03:52 +02:00
|
|
|
openssl dhparam -out /etc/nginx/certs/.dhparam.pem.tmp $DHPARAM_BITS
|
2016-01-05 14:03:22 +01:00
|
|
|
mv /etc/nginx/certs/.dhparam.pem.tmp /etc/nginx/certs/dhparam.pem || exit 1
|
2016-01-06 19:33:16 +01:00
|
|
|
fi
|
2016-01-05 14:03:22 +01:00
|
|
|
}
|
|
|
|
|
2016-06-26 00:31:15 +02:00
|
|
|
source /app/functions.sh
|
2016-01-06 19:33:16 +01:00
|
|
|
|
2016-01-03 12:31:24 +01:00
|
|
|
[[ $DEBUG == true ]] && set -x
|
2015-12-31 18:50:25 +01:00
|
|
|
|
|
|
|
if [[ "$*" == "/bin/bash /app/start.sh" ]]; then
|
2018-06-04 10:44:19 +02:00
|
|
|
acmev2_re='https://acme-.*v02\.api\.letsencrypt\.org/directory'
|
|
|
|
if [[ "${ACME_CA_URI:-}" =~ $acmev2_re ]]; then
|
|
|
|
echo "Error: ACME v2 API is not yet supported by simp_le."
|
|
|
|
echo "See https://github.com/zenhack/simp_le/issues/101"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-12-31 18:50:25 +01:00
|
|
|
check_docker_socket
|
2018-05-20 18:15:10 +02:00
|
|
|
if [[ -z "$(get_self_cid)" ]]; then
|
|
|
|
echo "Error: can't get my container ID !" >&2
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
export SELF_CID="$(get_self_cid)"
|
|
|
|
fi
|
2018-02-09 00:27:14 +01:00
|
|
|
if [[ -z "$(get_nginx_proxy_container)" ]]; then
|
|
|
|
echo "Error: can't get nginx-proxy container ID !" >&2
|
|
|
|
echo "Check that you are doing one of the following :" >&2
|
|
|
|
echo -e "\t- Use the --volumes-from option to mount volumes from the nginx-proxy container." >&2
|
|
|
|
echo -e "\t- Set the NGINX_PROXY_CONTAINER env var on the letsencrypt-companion container to the name of the nginx-proxy container." >&2
|
|
|
|
echo -e "\t- Label the nginx-proxy container to use with 'com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy'." >&2
|
|
|
|
exit 1
|
2018-02-09 10:38:44 +01:00
|
|
|
elif [[ -z "$(get_docker_gen_container)" ]] && ! is_docker_gen_container "$(get_nginx_proxy_container)"; then
|
|
|
|
echo "Error: can't get docker-gen container id !" >&2
|
|
|
|
echo "If you are running a three containers setup, check that you are doing one of the following :" >&2
|
|
|
|
echo -e "\t- Set the NGINX_DOCKER_GEN_CONTAINER env var on the letsencrypt-companion container to the name of the docker-gen container." >&2
|
|
|
|
echo -e "\t- Label the docker-gen container to use with 'com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen.'" >&2
|
|
|
|
exit 1
|
2016-02-11 21:18:20 +01:00
|
|
|
fi
|
2015-12-31 18:50:25 +01:00
|
|
|
check_writable_directory '/etc/nginx/certs'
|
2016-01-01 14:32:40 +01:00
|
|
|
check_writable_directory '/etc/nginx/vhost.d'
|
2015-12-31 18:50:25 +01:00
|
|
|
check_writable_directory '/usr/share/nginx/html'
|
2016-01-05 14:03:22 +01:00
|
|
|
check_dh_group
|
2015-12-31 18:50:25 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
exec "$@"
|