2020-01-18 23:19:48 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2020-02-04 08:47:39 +00:00
|
|
|
set -eo pipefail
|
|
|
|
|
2020-01-18 23:19:48 +00:00
|
|
|
/usr/local/bin/gomplate -V -o /app/config.toml -f /etc/templates/config.toml.tmpl
|
|
|
|
|
2020-02-04 08:47:39 +00:00
|
|
|
if [ -z "$BITWARDENRS_LDAP_BITWARDEN_URL" ] || [ -z "$BITWARDENRS_LDAP_HOST" ]
|
|
|
|
then
|
2020-02-04 09:22:17 +00:00
|
|
|
printf "Error: Bitwarden and/or LDAP server not configured. Exiting ...\n"
|
2020-02-04 08:47:39 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$BITWARDENRS_LDAP_BITWARDEN_URL" ]
|
|
|
|
then
|
2020-02-04 09:36:27 +00:00
|
|
|
WAITFOR_BW_SCHEME=$(/usr/local/bin/url-parser scheme --url "$BITWARDENRS_LDAP_BITWARDEN_URL")
|
|
|
|
WAITFOR_BW_HOST=$(/usr/local/bin/url-parser host --url "$BITWARDENRS_LDAP_BITWARDEN_URL")
|
|
|
|
WAITFOR_BW_PORT=$(/usr/local/bin/url-parser port --url "$BITWARDENRS_LDAP_BITWARDEN_URL")
|
2020-02-04 08:47:39 +00:00
|
|
|
|
2020-02-04 09:36:27 +00:00
|
|
|
if [ -z "$WAITFOR_BW_PORT" ]
|
2020-02-04 08:47:39 +00:00
|
|
|
then
|
2020-02-04 09:36:27 +00:00
|
|
|
[ "$WAITFOR_BW_SCHEME" = "https" ] && WAITFOR_BW_PORT=433 || WAITFOR_BW_PORT=80
|
2020-02-04 08:47:39 +00:00
|
|
|
fi
|
|
|
|
|
2020-02-04 09:36:27 +00:00
|
|
|
printf "Wait for bitwarden server on '%s:%s'...\n" "${WAITFOR_BW_HOST}" "${WAITFOR_BW_PORT}"
|
|
|
|
/usr/local/bin/wait-for "${WAITFOR_BW_HOST}":"${WAITFOR_BW_PORT}"
|
2020-02-04 08:47:39 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$BITWARDENRS_LDAP_HOST" ]
|
|
|
|
then
|
2020-02-04 09:22:17 +00:00
|
|
|
WAITFOR_LDAP_SSL=$(/usr/local/bin/gomplate -i '{{ getenv "BITWARDENRS_LDAP_SSL" "true" | conv.Bool }}')
|
2020-02-04 09:36:27 +00:00
|
|
|
|
2020-02-04 10:45:14 +00:00
|
|
|
if [ -z "$BITWARDENRS_LDAP_PORT" ]
|
2020-02-04 08:47:39 +00:00
|
|
|
then
|
2020-02-04 10:45:14 +00:00
|
|
|
[ "$WAITFOR_LDAP_SSL" = true ] && BITWARDENRS_LDAP_PORT=636 || BITWARDENRS_LDAP_PORT=389
|
2020-02-04 08:47:39 +00:00
|
|
|
fi
|
|
|
|
|
2020-02-04 10:45:14 +00:00
|
|
|
printf "Wait for ldap server on '%s:%s'...\n" "${BITWARDENRS_LDAP_HOST}" "${BITWARDENRS_LDAP_PORT}"
|
|
|
|
/usr/local/bin/wait-for "${BITWARDENRS_LDAP_HOST}":"${BITWARDENRS_LDAP_PORT}"
|
2020-02-04 08:47:39 +00:00
|
|
|
fi
|
|
|
|
|
2020-01-19 22:26:41 +00:00
|
|
|
exec env CONFIG_PATH=/app/config.toml /app/bitwarden_rs_ldap
|