Skip to content

Instantly share code, notes, and snippets.

@typomaker
Created February 16, 2021 20:02
Show Gist options
  • Save typomaker/00749200bbe63cb000cdf565fb36c99f to your computer and use it in GitHub Desktop.
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
#!/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