Created
February 16, 2021 20:02
-
-
Save typomaker/00749200bbe63cb000cdf565fb36c99f to your computer and use it in GitHub Desktop.
Set env variables from one string URI for https://hub.docker.com/_/postgres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -Eeo pipefail | |
# check to see if this file is being run or sourced from another script | |
_is_sourced() { | |
# https://unix.stackexchange.com/a/215279 | |
[ "${#FUNCNAME[@]}" -ge 2 ] \ | |
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \ | |
&& [ "${FUNCNAME[1]}" = 'source' ] | |
} | |
read -r POSTGRES_USER POSTGRES_PASSWORD POSTGRES_DB<<<$(echo "$POSTGRES_URI"|sed -e's,^.*://\([^:]*\):\([^@]*\)@[^/]*/\([^?]*\).*,\1 \2 \3,g'); | |
export $POSTGRES_USER; | |
export $POSTGRES_PASSWORD; | |
export $POSTGRES_DB; | |
source /usr/local/bin/docker-entrypoint.sh | |
if ! _is_sourced; then | |
_main "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment