1
0
mirror of https://github.com/docker-library/postgres.git synced 2025-07-29 21:41:20 +03:00

Convert all entrypoint "echo"s to "printf"

The use of the `echo` shell built-in has been actively discouraged for a long time, but it's really convenient so we keep doing it.  This converts them all to use `printf` appropriately such that we avoid issues like `echo "$someVar"` from doing the wrong thing if `$someVar` is `-n` or similar.
This commit is contained in:
Tianon Gravi
2022-12-21 10:42:36 -08:00
parent f8827c3ce6
commit 7e5e7ece73
11 changed files with 308 additions and 264 deletions

View File

@ -11,7 +11,7 @@ file_env() {
local fileVar="${var}_FILE" local fileVar="${var}_FILE"
local def="${2:-}" local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
exit 1 exit 1
fi fi
local val="$def" local val="$def"
@ -77,8 +77,8 @@ docker_init_database_dir() {
NSS_WRAPPER_GROUP="$(mktemp)" NSS_WRAPPER_GROUP="$(mktemp)"
export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
local gid; gid="$(id -g)" local gid; gid="$(id -g)"
echo "postgres:x:$uid:$gid:PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD" printf 'postgres:x:%s:%s:PostgreSQL:%s:/bin/false\n' "$uid" "$gid" "$PGDATA" > "$NSS_WRAPPER_PASSWD"
echo "postgres:x:$gid:" > "$NSS_WRAPPER_GROUP" printf 'postgres:x:%s:\n' "$gid" > "$NSS_WRAPPER_GROUP"
break break
fi fi
done done
@ -88,7 +88,7 @@ docker_init_database_dir() {
set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@" set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@"
fi fi
eval 'initdb --username="$POSTGRES_USER" --pwfile=<(echo "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"' eval 'initdb --username="$POSTGRES_USER" --pwfile=<(printf "%s" "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
# unset/cleanup "nss_wrapper" bits # unset/cleanup "nss_wrapper" bits
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
@ -157,7 +157,7 @@ docker_process_init_files() {
# psql here for backwards compatibility "${psql[@]}" # psql here for backwards compatibility "${psql[@]}"
psql=( docker_process_sql ) psql=( docker_process_sql )
echo printf '\n'
local f local f
for f; do for f; do
case "$f" in case "$f" in
@ -165,20 +165,20 @@ docker_process_init_files() {
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452 # https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then if [ -x "$f" ]; then
echo "$0: running $f" printf '%s: running %s\n' "$0" "$f"
"$f" "$f"
else else
echo "$0: sourcing $f" printf '%s: sourcing %s\n' "$0" "$f"
. "$f" . "$f"
fi fi
;; ;;
*.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;; *.sql) printf '%s: running %s\n' "$0" "$f"; docker_process_sql -f "$f"; printf '\n' ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; *.sql.gz) printf '%s: running %s\n' "$0" "$f"; gunzip -c "$f" | docker_process_sql; printf '\n' ;;
*.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; *.sql.xz) printf '%s: running %s\n' "$0" "$f"; xzcat "$f" | docker_process_sql; printf '\n' ;;
*.sql.zst) echo "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; *.sql.zst) printf '%s: running %s\n' "$0" "$f"; zstd -dc "$f" | docker_process_sql; printf '\n' ;;
*) echo "$0: ignoring $f" ;; *) printf '%s: ignoring %s\n' "$0" "$f" ;;
esac esac
echo printf '\n'
done done
} }
@ -209,7 +209,7 @@ docker_setup_db() {
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL' POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
CREATE DATABASE :"db" ; CREATE DATABASE :"db" ;
EOSQL EOSQL
echo printf '\n'
fi fi
} }
@ -243,12 +243,12 @@ pg_setup_hba_conf() {
auth="$(postgres -C password_encryption "$@")" auth="$(postgres -C password_encryption "$@")"
: "${POSTGRES_HOST_AUTH_METHOD:=$auth}" : "${POSTGRES_HOST_AUTH_METHOD:=$auth}"
{ {
echo printf '\n'
if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then
echo '# warning trust is enabled for all connections' printf '# warning trust is enabled for all connections\n'
echo '# see https://www.postgresql.org/docs/12/auth-trust.html' printf '# see https://www.postgresql.org/docs/12/auth-trust.html\n'
fi fi
echo "host all all all $POSTGRES_HOST_AUTH_METHOD" printf 'host all all all %s\n' "$POSTGRES_HOST_AUTH_METHOD"
} >> "$PGDATA/pg_hba.conf" } >> "$PGDATA/pg_hba.conf"
} }
@ -328,13 +328,17 @@ _main() {
docker_temp_server_stop docker_temp_server_stop
unset PGPASSWORD unset PGPASSWORD
echo cat <<-'EOM'
echo 'PostgreSQL init process complete; ready for start up.'
echo PostgreSQL init process complete; ready for start up.
EOM
else else
echo cat <<-'EOM'
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo PostgreSQL Database directory appears to contain a database; Skipping initialization
EOM
fi fi
fi fi

View File

@ -11,7 +11,7 @@ file_env() {
local fileVar="${var}_FILE" local fileVar="${var}_FILE"
local def="${2:-}" local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
exit 1 exit 1
fi fi
local val="$def" local val="$def"
@ -77,8 +77,8 @@ docker_init_database_dir() {
NSS_WRAPPER_GROUP="$(mktemp)" NSS_WRAPPER_GROUP="$(mktemp)"
export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
local gid; gid="$(id -g)" local gid; gid="$(id -g)"
echo "postgres:x:$uid:$gid:PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD" printf 'postgres:x:%s:%s:PostgreSQL:%s:/bin/false\n' "$uid" "$gid" "$PGDATA" > "$NSS_WRAPPER_PASSWD"
echo "postgres:x:$gid:" > "$NSS_WRAPPER_GROUP" printf 'postgres:x:%s:\n' "$gid" > "$NSS_WRAPPER_GROUP"
break break
fi fi
done done
@ -88,7 +88,7 @@ docker_init_database_dir() {
set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@" set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@"
fi fi
eval 'initdb --username="$POSTGRES_USER" --pwfile=<(echo "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"' eval 'initdb --username="$POSTGRES_USER" --pwfile=<(printf "%s" "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
# unset/cleanup "nss_wrapper" bits # unset/cleanup "nss_wrapper" bits
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
@ -157,7 +157,7 @@ docker_process_init_files() {
# psql here for backwards compatibility "${psql[@]}" # psql here for backwards compatibility "${psql[@]}"
psql=( docker_process_sql ) psql=( docker_process_sql )
echo printf '\n'
local f local f
for f; do for f; do
case "$f" in case "$f" in
@ -165,20 +165,20 @@ docker_process_init_files() {
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452 # https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then if [ -x "$f" ]; then
echo "$0: running $f" printf '%s: running %s\n' "$0" "$f"
"$f" "$f"
else else
echo "$0: sourcing $f" printf '%s: sourcing %s\n' "$0" "$f"
. "$f" . "$f"
fi fi
;; ;;
*.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;; *.sql) printf '%s: running %s\n' "$0" "$f"; docker_process_sql -f "$f"; printf '\n' ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; *.sql.gz) printf '%s: running %s\n' "$0" "$f"; gunzip -c "$f" | docker_process_sql; printf '\n' ;;
*.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; *.sql.xz) printf '%s: running %s\n' "$0" "$f"; xzcat "$f" | docker_process_sql; printf '\n' ;;
*.sql.zst) echo "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; *.sql.zst) printf '%s: running %s\n' "$0" "$f"; zstd -dc "$f" | docker_process_sql; printf '\n' ;;
*) echo "$0: ignoring $f" ;; *) printf '%s: ignoring %s\n' "$0" "$f" ;;
esac esac
echo printf '\n'
done done
} }
@ -209,7 +209,7 @@ docker_setup_db() {
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL' POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
CREATE DATABASE :"db" ; CREATE DATABASE :"db" ;
EOSQL EOSQL
echo printf '\n'
fi fi
} }
@ -243,12 +243,12 @@ pg_setup_hba_conf() {
auth="$(postgres -C password_encryption "$@")" auth="$(postgres -C password_encryption "$@")"
: "${POSTGRES_HOST_AUTH_METHOD:=$auth}" : "${POSTGRES_HOST_AUTH_METHOD:=$auth}"
{ {
echo printf '\n'
if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then
echo '# warning trust is enabled for all connections' printf '# warning trust is enabled for all connections\n'
echo '# see https://www.postgresql.org/docs/12/auth-trust.html' printf '# see https://www.postgresql.org/docs/12/auth-trust.html\n'
fi fi
echo "host all all all $POSTGRES_HOST_AUTH_METHOD" printf 'host all all all %s\n' "$POSTGRES_HOST_AUTH_METHOD"
} >> "$PGDATA/pg_hba.conf" } >> "$PGDATA/pg_hba.conf"
} }
@ -328,13 +328,17 @@ _main() {
docker_temp_server_stop docker_temp_server_stop
unset PGPASSWORD unset PGPASSWORD
echo cat <<-'EOM'
echo 'PostgreSQL init process complete; ready for start up.'
echo PostgreSQL init process complete; ready for start up.
EOM
else else
echo cat <<-'EOM'
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo PostgreSQL Database directory appears to contain a database; Skipping initialization
EOM
fi fi
fi fi

View File

@ -11,7 +11,7 @@ file_env() {
local fileVar="${var}_FILE" local fileVar="${var}_FILE"
local def="${2:-}" local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
exit 1 exit 1
fi fi
local val="$def" local val="$def"
@ -77,8 +77,8 @@ docker_init_database_dir() {
NSS_WRAPPER_GROUP="$(mktemp)" NSS_WRAPPER_GROUP="$(mktemp)"
export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
local gid; gid="$(id -g)" local gid; gid="$(id -g)"
echo "postgres:x:$uid:$gid:PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD" printf 'postgres:x:%s:%s:PostgreSQL:%s:/bin/false\n' "$uid" "$gid" "$PGDATA" > "$NSS_WRAPPER_PASSWD"
echo "postgres:x:$gid:" > "$NSS_WRAPPER_GROUP" printf 'postgres:x:%s:\n' "$gid" > "$NSS_WRAPPER_GROUP"
break break
fi fi
done done
@ -88,7 +88,7 @@ docker_init_database_dir() {
set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@" set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@"
fi fi
eval 'initdb --username="$POSTGRES_USER" --pwfile=<(echo "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"' eval 'initdb --username="$POSTGRES_USER" --pwfile=<(printf "%s" "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
# unset/cleanup "nss_wrapper" bits # unset/cleanup "nss_wrapper" bits
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
@ -157,7 +157,7 @@ docker_process_init_files() {
# psql here for backwards compatibility "${psql[@]}" # psql here for backwards compatibility "${psql[@]}"
psql=( docker_process_sql ) psql=( docker_process_sql )
echo printf '\n'
local f local f
for f; do for f; do
case "$f" in case "$f" in
@ -165,20 +165,20 @@ docker_process_init_files() {
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452 # https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then if [ -x "$f" ]; then
echo "$0: running $f" printf '%s: running %s\n' "$0" "$f"
"$f" "$f"
else else
echo "$0: sourcing $f" printf '%s: sourcing %s\n' "$0" "$f"
. "$f" . "$f"
fi fi
;; ;;
*.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;; *.sql) printf '%s: running %s\n' "$0" "$f"; docker_process_sql -f "$f"; printf '\n' ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; *.sql.gz) printf '%s: running %s\n' "$0" "$f"; gunzip -c "$f" | docker_process_sql; printf '\n' ;;
*.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; *.sql.xz) printf '%s: running %s\n' "$0" "$f"; xzcat "$f" | docker_process_sql; printf '\n' ;;
*.sql.zst) echo "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; *.sql.zst) printf '%s: running %s\n' "$0" "$f"; zstd -dc "$f" | docker_process_sql; printf '\n' ;;
*) echo "$0: ignoring $f" ;; *) printf '%s: ignoring %s\n' "$0" "$f" ;;
esac esac
echo printf '\n'
done done
} }
@ -209,7 +209,7 @@ docker_setup_db() {
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL' POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
CREATE DATABASE :"db" ; CREATE DATABASE :"db" ;
EOSQL EOSQL
echo printf '\n'
fi fi
} }
@ -243,12 +243,12 @@ pg_setup_hba_conf() {
auth="$(postgres -C password_encryption "$@")" auth="$(postgres -C password_encryption "$@")"
: "${POSTGRES_HOST_AUTH_METHOD:=$auth}" : "${POSTGRES_HOST_AUTH_METHOD:=$auth}"
{ {
echo printf '\n'
if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then
echo '# warning trust is enabled for all connections' printf '# warning trust is enabled for all connections\n'
echo '# see https://www.postgresql.org/docs/12/auth-trust.html' printf '# see https://www.postgresql.org/docs/12/auth-trust.html\n'
fi fi
echo "host all all all $POSTGRES_HOST_AUTH_METHOD" printf 'host all all all %s\n' "$POSTGRES_HOST_AUTH_METHOD"
} >> "$PGDATA/pg_hba.conf" } >> "$PGDATA/pg_hba.conf"
} }
@ -328,13 +328,17 @@ _main() {
docker_temp_server_stop docker_temp_server_stop
unset PGPASSWORD unset PGPASSWORD
echo cat <<-'EOM'
echo 'PostgreSQL init process complete; ready for start up.'
echo PostgreSQL init process complete; ready for start up.
EOM
else else
echo cat <<-'EOM'
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo PostgreSQL Database directory appears to contain a database; Skipping initialization
EOM
fi fi
fi fi

View File

@ -11,7 +11,7 @@ file_env() {
local fileVar="${var}_FILE" local fileVar="${var}_FILE"
local def="${2:-}" local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
exit 1 exit 1
fi fi
local val="$def" local val="$def"
@ -77,8 +77,8 @@ docker_init_database_dir() {
NSS_WRAPPER_GROUP="$(mktemp)" NSS_WRAPPER_GROUP="$(mktemp)"
export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
local gid; gid="$(id -g)" local gid; gid="$(id -g)"
echo "postgres:x:$uid:$gid:PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD" printf 'postgres:x:%s:%s:PostgreSQL:%s:/bin/false\n' "$uid" "$gid" "$PGDATA" > "$NSS_WRAPPER_PASSWD"
echo "postgres:x:$gid:" > "$NSS_WRAPPER_GROUP" printf 'postgres:x:%s:\n' "$gid" > "$NSS_WRAPPER_GROUP"
break break
fi fi
done done
@ -88,7 +88,7 @@ docker_init_database_dir() {
set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@" set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@"
fi fi
eval 'initdb --username="$POSTGRES_USER" --pwfile=<(echo "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"' eval 'initdb --username="$POSTGRES_USER" --pwfile=<(printf "%s" "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
# unset/cleanup "nss_wrapper" bits # unset/cleanup "nss_wrapper" bits
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
@ -157,7 +157,7 @@ docker_process_init_files() {
# psql here for backwards compatibility "${psql[@]}" # psql here for backwards compatibility "${psql[@]}"
psql=( docker_process_sql ) psql=( docker_process_sql )
echo printf '\n'
local f local f
for f; do for f; do
case "$f" in case "$f" in
@ -165,20 +165,20 @@ docker_process_init_files() {
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452 # https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then if [ -x "$f" ]; then
echo "$0: running $f" printf '%s: running %s\n' "$0" "$f"
"$f" "$f"
else else
echo "$0: sourcing $f" printf '%s: sourcing %s\n' "$0" "$f"
. "$f" . "$f"
fi fi
;; ;;
*.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;; *.sql) printf '%s: running %s\n' "$0" "$f"; docker_process_sql -f "$f"; printf '\n' ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; *.sql.gz) printf '%s: running %s\n' "$0" "$f"; gunzip -c "$f" | docker_process_sql; printf '\n' ;;
*.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; *.sql.xz) printf '%s: running %s\n' "$0" "$f"; xzcat "$f" | docker_process_sql; printf '\n' ;;
*.sql.zst) echo "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; *.sql.zst) printf '%s: running %s\n' "$0" "$f"; zstd -dc "$f" | docker_process_sql; printf '\n' ;;
*) echo "$0: ignoring $f" ;; *) printf '%s: ignoring %s\n' "$0" "$f" ;;
esac esac
echo printf '\n'
done done
} }
@ -209,7 +209,7 @@ docker_setup_db() {
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL' POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
CREATE DATABASE :"db" ; CREATE DATABASE :"db" ;
EOSQL EOSQL
echo printf '\n'
fi fi
} }
@ -243,12 +243,12 @@ pg_setup_hba_conf() {
auth="$(postgres -C password_encryption "$@")" auth="$(postgres -C password_encryption "$@")"
: "${POSTGRES_HOST_AUTH_METHOD:=$auth}" : "${POSTGRES_HOST_AUTH_METHOD:=$auth}"
{ {
echo printf '\n'
if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then
echo '# warning trust is enabled for all connections' printf '# warning trust is enabled for all connections\n'
echo '# see https://www.postgresql.org/docs/12/auth-trust.html' printf '# see https://www.postgresql.org/docs/12/auth-trust.html\n'
fi fi
echo "host all all all $POSTGRES_HOST_AUTH_METHOD" printf 'host all all all %s\n' "$POSTGRES_HOST_AUTH_METHOD"
} >> "$PGDATA/pg_hba.conf" } >> "$PGDATA/pg_hba.conf"
} }
@ -328,13 +328,17 @@ _main() {
docker_temp_server_stop docker_temp_server_stop
unset PGPASSWORD unset PGPASSWORD
echo cat <<-'EOM'
echo 'PostgreSQL init process complete; ready for start up.'
echo PostgreSQL init process complete; ready for start up.
EOM
else else
echo cat <<-'EOM'
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo PostgreSQL Database directory appears to contain a database; Skipping initialization
EOM
fi fi
fi fi

View File

@ -11,7 +11,7 @@ file_env() {
local fileVar="${var}_FILE" local fileVar="${var}_FILE"
local def="${2:-}" local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
exit 1 exit 1
fi fi
local val="$def" local val="$def"
@ -77,8 +77,8 @@ docker_init_database_dir() {
NSS_WRAPPER_GROUP="$(mktemp)" NSS_WRAPPER_GROUP="$(mktemp)"
export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
local gid; gid="$(id -g)" local gid; gid="$(id -g)"
echo "postgres:x:$uid:$gid:PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD" printf 'postgres:x:%s:%s:PostgreSQL:%s:/bin/false\n' "$uid" "$gid" "$PGDATA" > "$NSS_WRAPPER_PASSWD"
echo "postgres:x:$gid:" > "$NSS_WRAPPER_GROUP" printf 'postgres:x:%s:\n' "$gid" > "$NSS_WRAPPER_GROUP"
break break
fi fi
done done
@ -88,7 +88,7 @@ docker_init_database_dir() {
set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@" set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@"
fi fi
eval 'initdb --username="$POSTGRES_USER" --pwfile=<(echo "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"' eval 'initdb --username="$POSTGRES_USER" --pwfile=<(printf "%s" "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
# unset/cleanup "nss_wrapper" bits # unset/cleanup "nss_wrapper" bits
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
@ -157,7 +157,7 @@ docker_process_init_files() {
# psql here for backwards compatibility "${psql[@]}" # psql here for backwards compatibility "${psql[@]}"
psql=( docker_process_sql ) psql=( docker_process_sql )
echo printf '\n'
local f local f
for f; do for f; do
case "$f" in case "$f" in
@ -165,20 +165,20 @@ docker_process_init_files() {
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452 # https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then if [ -x "$f" ]; then
echo "$0: running $f" printf '%s: running %s\n' "$0" "$f"
"$f" "$f"
else else
echo "$0: sourcing $f" printf '%s: sourcing %s\n' "$0" "$f"
. "$f" . "$f"
fi fi
;; ;;
*.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;; *.sql) printf '%s: running %s\n' "$0" "$f"; docker_process_sql -f "$f"; printf '\n' ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; *.sql.gz) printf '%s: running %s\n' "$0" "$f"; gunzip -c "$f" | docker_process_sql; printf '\n' ;;
*.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; *.sql.xz) printf '%s: running %s\n' "$0" "$f"; xzcat "$f" | docker_process_sql; printf '\n' ;;
*.sql.zst) echo "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; *.sql.zst) printf '%s: running %s\n' "$0" "$f"; zstd -dc "$f" | docker_process_sql; printf '\n' ;;
*) echo "$0: ignoring $f" ;; *) printf '%s: ignoring %s\n' "$0" "$f" ;;
esac esac
echo printf '\n'
done done
} }
@ -209,7 +209,7 @@ docker_setup_db() {
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL' POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
CREATE DATABASE :"db" ; CREATE DATABASE :"db" ;
EOSQL EOSQL
echo printf '\n'
fi fi
} }
@ -243,12 +243,12 @@ pg_setup_hba_conf() {
auth="$(postgres -C password_encryption "$@")" auth="$(postgres -C password_encryption "$@")"
: "${POSTGRES_HOST_AUTH_METHOD:=$auth}" : "${POSTGRES_HOST_AUTH_METHOD:=$auth}"
{ {
echo printf '\n'
if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then
echo '# warning trust is enabled for all connections' printf '# warning trust is enabled for all connections\n'
echo '# see https://www.postgresql.org/docs/12/auth-trust.html' printf '# see https://www.postgresql.org/docs/12/auth-trust.html\n'
fi fi
echo "host all all all $POSTGRES_HOST_AUTH_METHOD" printf 'host all all all %s\n' "$POSTGRES_HOST_AUTH_METHOD"
} >> "$PGDATA/pg_hba.conf" } >> "$PGDATA/pg_hba.conf"
} }
@ -328,13 +328,17 @@ _main() {
docker_temp_server_stop docker_temp_server_stop
unset PGPASSWORD unset PGPASSWORD
echo cat <<-'EOM'
echo 'PostgreSQL init process complete; ready for start up.'
echo PostgreSQL init process complete; ready for start up.
EOM
else else
echo cat <<-'EOM'
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo PostgreSQL Database directory appears to contain a database; Skipping initialization
EOM
fi fi
fi fi

View File

@ -11,7 +11,7 @@ file_env() {
local fileVar="${var}_FILE" local fileVar="${var}_FILE"
local def="${2:-}" local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
exit 1 exit 1
fi fi
local val="$def" local val="$def"
@ -77,8 +77,8 @@ docker_init_database_dir() {
NSS_WRAPPER_GROUP="$(mktemp)" NSS_WRAPPER_GROUP="$(mktemp)"
export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
local gid; gid="$(id -g)" local gid; gid="$(id -g)"
echo "postgres:x:$uid:$gid:PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD" printf 'postgres:x:%s:%s:PostgreSQL:%s:/bin/false\n' "$uid" "$gid" "$PGDATA" > "$NSS_WRAPPER_PASSWD"
echo "postgres:x:$gid:" > "$NSS_WRAPPER_GROUP" printf 'postgres:x:%s:\n' "$gid" > "$NSS_WRAPPER_GROUP"
break break
fi fi
done done
@ -88,7 +88,7 @@ docker_init_database_dir() {
set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@" set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@"
fi fi
eval 'initdb --username="$POSTGRES_USER" --pwfile=<(echo "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"' eval 'initdb --username="$POSTGRES_USER" --pwfile=<(printf "%s" "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
# unset/cleanup "nss_wrapper" bits # unset/cleanup "nss_wrapper" bits
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
@ -157,7 +157,7 @@ docker_process_init_files() {
# psql here for backwards compatibility "${psql[@]}" # psql here for backwards compatibility "${psql[@]}"
psql=( docker_process_sql ) psql=( docker_process_sql )
echo printf '\n'
local f local f
for f; do for f; do
case "$f" in case "$f" in
@ -165,20 +165,20 @@ docker_process_init_files() {
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452 # https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then if [ -x "$f" ]; then
echo "$0: running $f" printf '%s: running %s\n' "$0" "$f"
"$f" "$f"
else else
echo "$0: sourcing $f" printf '%s: sourcing %s\n' "$0" "$f"
. "$f" . "$f"
fi fi
;; ;;
*.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;; *.sql) printf '%s: running %s\n' "$0" "$f"; docker_process_sql -f "$f"; printf '\n' ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; *.sql.gz) printf '%s: running %s\n' "$0" "$f"; gunzip -c "$f" | docker_process_sql; printf '\n' ;;
*.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; *.sql.xz) printf '%s: running %s\n' "$0" "$f"; xzcat "$f" | docker_process_sql; printf '\n' ;;
*.sql.zst) echo "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; *.sql.zst) printf '%s: running %s\n' "$0" "$f"; zstd -dc "$f" | docker_process_sql; printf '\n' ;;
*) echo "$0: ignoring $f" ;; *) printf '%s: ignoring %s\n' "$0" "$f" ;;
esac esac
echo printf '\n'
done done
} }
@ -209,7 +209,7 @@ docker_setup_db() {
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL' POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
CREATE DATABASE :"db" ; CREATE DATABASE :"db" ;
EOSQL EOSQL
echo printf '\n'
fi fi
} }
@ -243,12 +243,12 @@ pg_setup_hba_conf() {
auth="$(postgres -C password_encryption "$@")" auth="$(postgres -C password_encryption "$@")"
: "${POSTGRES_HOST_AUTH_METHOD:=$auth}" : "${POSTGRES_HOST_AUTH_METHOD:=$auth}"
{ {
echo printf '\n'
if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then
echo '# warning trust is enabled for all connections' printf '# warning trust is enabled for all connections\n'
echo '# see https://www.postgresql.org/docs/12/auth-trust.html' printf '# see https://www.postgresql.org/docs/12/auth-trust.html\n'
fi fi
echo "host all all all $POSTGRES_HOST_AUTH_METHOD" printf 'host all all all %s\n' "$POSTGRES_HOST_AUTH_METHOD"
} >> "$PGDATA/pg_hba.conf" } >> "$PGDATA/pg_hba.conf"
} }
@ -328,13 +328,17 @@ _main() {
docker_temp_server_stop docker_temp_server_stop
unset PGPASSWORD unset PGPASSWORD
echo cat <<-'EOM'
echo 'PostgreSQL init process complete; ready for start up.'
echo PostgreSQL init process complete; ready for start up.
EOM
else else
echo cat <<-'EOM'
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo PostgreSQL Database directory appears to contain a database; Skipping initialization
EOM
fi fi
fi fi

View File

@ -11,7 +11,7 @@ file_env() {
local fileVar="${var}_FILE" local fileVar="${var}_FILE"
local def="${2:-}" local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
exit 1 exit 1
fi fi
local val="$def" local val="$def"
@ -77,8 +77,8 @@ docker_init_database_dir() {
NSS_WRAPPER_GROUP="$(mktemp)" NSS_WRAPPER_GROUP="$(mktemp)"
export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
local gid; gid="$(id -g)" local gid; gid="$(id -g)"
echo "postgres:x:$uid:$gid:PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD" printf 'postgres:x:%s:%s:PostgreSQL:%s:/bin/false\n' "$uid" "$gid" "$PGDATA" > "$NSS_WRAPPER_PASSWD"
echo "postgres:x:$gid:" > "$NSS_WRAPPER_GROUP" printf 'postgres:x:%s:\n' "$gid" > "$NSS_WRAPPER_GROUP"
break break
fi fi
done done
@ -88,7 +88,7 @@ docker_init_database_dir() {
set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@" set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@"
fi fi
eval 'initdb --username="$POSTGRES_USER" --pwfile=<(echo "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"' eval 'initdb --username="$POSTGRES_USER" --pwfile=<(printf "%s" "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
# unset/cleanup "nss_wrapper" bits # unset/cleanup "nss_wrapper" bits
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
@ -157,7 +157,7 @@ docker_process_init_files() {
# psql here for backwards compatibility "${psql[@]}" # psql here for backwards compatibility "${psql[@]}"
psql=( docker_process_sql ) psql=( docker_process_sql )
echo printf '\n'
local f local f
for f; do for f; do
case "$f" in case "$f" in
@ -165,20 +165,20 @@ docker_process_init_files() {
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452 # https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then if [ -x "$f" ]; then
echo "$0: running $f" printf '%s: running %s\n' "$0" "$f"
"$f" "$f"
else else
echo "$0: sourcing $f" printf '%s: sourcing %s\n' "$0" "$f"
. "$f" . "$f"
fi fi
;; ;;
*.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;; *.sql) printf '%s: running %s\n' "$0" "$f"; docker_process_sql -f "$f"; printf '\n' ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; *.sql.gz) printf '%s: running %s\n' "$0" "$f"; gunzip -c "$f" | docker_process_sql; printf '\n' ;;
*.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; *.sql.xz) printf '%s: running %s\n' "$0" "$f"; xzcat "$f" | docker_process_sql; printf '\n' ;;
*.sql.zst) echo "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; *.sql.zst) printf '%s: running %s\n' "$0" "$f"; zstd -dc "$f" | docker_process_sql; printf '\n' ;;
*) echo "$0: ignoring $f" ;; *) printf '%s: ignoring %s\n' "$0" "$f" ;;
esac esac
echo printf '\n'
done done
} }
@ -209,7 +209,7 @@ docker_setup_db() {
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL' POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
CREATE DATABASE :"db" ; CREATE DATABASE :"db" ;
EOSQL EOSQL
echo printf '\n'
fi fi
} }
@ -243,12 +243,12 @@ pg_setup_hba_conf() {
auth="$(postgres -C password_encryption "$@")" auth="$(postgres -C password_encryption "$@")"
: "${POSTGRES_HOST_AUTH_METHOD:=$auth}" : "${POSTGRES_HOST_AUTH_METHOD:=$auth}"
{ {
echo printf '\n'
if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then
echo '# warning trust is enabled for all connections' printf '# warning trust is enabled for all connections\n'
echo '# see https://www.postgresql.org/docs/12/auth-trust.html' printf '# see https://www.postgresql.org/docs/12/auth-trust.html\n'
fi fi
echo "host all all all $POSTGRES_HOST_AUTH_METHOD" printf 'host all all all %s\n' "$POSTGRES_HOST_AUTH_METHOD"
} >> "$PGDATA/pg_hba.conf" } >> "$PGDATA/pg_hba.conf"
} }
@ -328,13 +328,17 @@ _main() {
docker_temp_server_stop docker_temp_server_stop
unset PGPASSWORD unset PGPASSWORD
echo cat <<-'EOM'
echo 'PostgreSQL init process complete; ready for start up.'
echo PostgreSQL init process complete; ready for start up.
EOM
else else
echo cat <<-'EOM'
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo PostgreSQL Database directory appears to contain a database; Skipping initialization
EOM
fi fi
fi fi

View File

@ -11,7 +11,7 @@ file_env() {
local fileVar="${var}_FILE" local fileVar="${var}_FILE"
local def="${2:-}" local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
exit 1 exit 1
fi fi
local val="$def" local val="$def"
@ -77,8 +77,8 @@ docker_init_database_dir() {
NSS_WRAPPER_GROUP="$(mktemp)" NSS_WRAPPER_GROUP="$(mktemp)"
export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
local gid; gid="$(id -g)" local gid; gid="$(id -g)"
echo "postgres:x:$uid:$gid:PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD" printf 'postgres:x:%s:%s:PostgreSQL:%s:/bin/false\n' "$uid" "$gid" "$PGDATA" > "$NSS_WRAPPER_PASSWD"
echo "postgres:x:$gid:" > "$NSS_WRAPPER_GROUP" printf 'postgres:x:%s:\n' "$gid" > "$NSS_WRAPPER_GROUP"
break break
fi fi
done done
@ -88,7 +88,7 @@ docker_init_database_dir() {
set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@" set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@"
fi fi
eval 'initdb --username="$POSTGRES_USER" --pwfile=<(echo "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"' eval 'initdb --username="$POSTGRES_USER" --pwfile=<(printf "%s" "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
# unset/cleanup "nss_wrapper" bits # unset/cleanup "nss_wrapper" bits
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
@ -157,7 +157,7 @@ docker_process_init_files() {
# psql here for backwards compatibility "${psql[@]}" # psql here for backwards compatibility "${psql[@]}"
psql=( docker_process_sql ) psql=( docker_process_sql )
echo printf '\n'
local f local f
for f; do for f; do
case "$f" in case "$f" in
@ -165,20 +165,20 @@ docker_process_init_files() {
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452 # https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then if [ -x "$f" ]; then
echo "$0: running $f" printf '%s: running %s\n' "$0" "$f"
"$f" "$f"
else else
echo "$0: sourcing $f" printf '%s: sourcing %s\n' "$0" "$f"
. "$f" . "$f"
fi fi
;; ;;
*.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;; *.sql) printf '%s: running %s\n' "$0" "$f"; docker_process_sql -f "$f"; printf '\n' ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; *.sql.gz) printf '%s: running %s\n' "$0" "$f"; gunzip -c "$f" | docker_process_sql; printf '\n' ;;
*.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; *.sql.xz) printf '%s: running %s\n' "$0" "$f"; xzcat "$f" | docker_process_sql; printf '\n' ;;
*.sql.zst) echo "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; *.sql.zst) printf '%s: running %s\n' "$0" "$f"; zstd -dc "$f" | docker_process_sql; printf '\n' ;;
*) echo "$0: ignoring $f" ;; *) printf '%s: ignoring %s\n' "$0" "$f" ;;
esac esac
echo printf '\n'
done done
} }
@ -209,7 +209,7 @@ docker_setup_db() {
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL' POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
CREATE DATABASE :"db" ; CREATE DATABASE :"db" ;
EOSQL EOSQL
echo printf '\n'
fi fi
} }
@ -243,12 +243,12 @@ pg_setup_hba_conf() {
auth="$(postgres -C password_encryption "$@")" auth="$(postgres -C password_encryption "$@")"
: "${POSTGRES_HOST_AUTH_METHOD:=$auth}" : "${POSTGRES_HOST_AUTH_METHOD:=$auth}"
{ {
echo printf '\n'
if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then
echo '# warning trust is enabled for all connections' printf '# warning trust is enabled for all connections\n'
echo '# see https://www.postgresql.org/docs/12/auth-trust.html' printf '# see https://www.postgresql.org/docs/12/auth-trust.html\n'
fi fi
echo "host all all all $POSTGRES_HOST_AUTH_METHOD" printf 'host all all all %s\n' "$POSTGRES_HOST_AUTH_METHOD"
} >> "$PGDATA/pg_hba.conf" } >> "$PGDATA/pg_hba.conf"
} }
@ -328,13 +328,17 @@ _main() {
docker_temp_server_stop docker_temp_server_stop
unset PGPASSWORD unset PGPASSWORD
echo cat <<-'EOM'
echo 'PostgreSQL init process complete; ready for start up.'
echo PostgreSQL init process complete; ready for start up.
EOM
else else
echo cat <<-'EOM'
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo PostgreSQL Database directory appears to contain a database; Skipping initialization
EOM
fi fi
fi fi

View File

@ -11,7 +11,7 @@ file_env() {
local fileVar="${var}_FILE" local fileVar="${var}_FILE"
local def="${2:-}" local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
exit 1 exit 1
fi fi
local val="$def" local val="$def"
@ -77,8 +77,8 @@ docker_init_database_dir() {
NSS_WRAPPER_GROUP="$(mktemp)" NSS_WRAPPER_GROUP="$(mktemp)"
export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
local gid; gid="$(id -g)" local gid; gid="$(id -g)"
echo "postgres:x:$uid:$gid:PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD" printf 'postgres:x:%s:%s:PostgreSQL:%s:/bin/false\n' "$uid" "$gid" "$PGDATA" > "$NSS_WRAPPER_PASSWD"
echo "postgres:x:$gid:" > "$NSS_WRAPPER_GROUP" printf 'postgres:x:%s:\n' "$gid" > "$NSS_WRAPPER_GROUP"
break break
fi fi
done done
@ -88,7 +88,7 @@ docker_init_database_dir() {
set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@" set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@"
fi fi
eval 'initdb --username="$POSTGRES_USER" --pwfile=<(echo "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"' eval 'initdb --username="$POSTGRES_USER" --pwfile=<(printf "%s" "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
# unset/cleanup "nss_wrapper" bits # unset/cleanup "nss_wrapper" bits
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
@ -157,7 +157,7 @@ docker_process_init_files() {
# psql here for backwards compatibility "${psql[@]}" # psql here for backwards compatibility "${psql[@]}"
psql=( docker_process_sql ) psql=( docker_process_sql )
echo printf '\n'
local f local f
for f; do for f; do
case "$f" in case "$f" in
@ -165,20 +165,20 @@ docker_process_init_files() {
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452 # https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then if [ -x "$f" ]; then
echo "$0: running $f" printf '%s: running %s\n' "$0" "$f"
"$f" "$f"
else else
echo "$0: sourcing $f" printf '%s: sourcing %s\n' "$0" "$f"
. "$f" . "$f"
fi fi
;; ;;
*.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;; *.sql) printf '%s: running %s\n' "$0" "$f"; docker_process_sql -f "$f"; printf '\n' ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; *.sql.gz) printf '%s: running %s\n' "$0" "$f"; gunzip -c "$f" | docker_process_sql; printf '\n' ;;
*.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; *.sql.xz) printf '%s: running %s\n' "$0" "$f"; xzcat "$f" | docker_process_sql; printf '\n' ;;
*.sql.zst) echo "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; *.sql.zst) printf '%s: running %s\n' "$0" "$f"; zstd -dc "$f" | docker_process_sql; printf '\n' ;;
*) echo "$0: ignoring $f" ;; *) printf '%s: ignoring %s\n' "$0" "$f" ;;
esac esac
echo printf '\n'
done done
} }
@ -209,7 +209,7 @@ docker_setup_db() {
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL' POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
CREATE DATABASE :"db" ; CREATE DATABASE :"db" ;
EOSQL EOSQL
echo printf '\n'
fi fi
} }
@ -243,12 +243,12 @@ pg_setup_hba_conf() {
auth="$(postgres -C password_encryption "$@")" auth="$(postgres -C password_encryption "$@")"
: "${POSTGRES_HOST_AUTH_METHOD:=$auth}" : "${POSTGRES_HOST_AUTH_METHOD:=$auth}"
{ {
echo printf '\n'
if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then
echo '# warning trust is enabled for all connections' printf '# warning trust is enabled for all connections\n'
echo '# see https://www.postgresql.org/docs/12/auth-trust.html' printf '# see https://www.postgresql.org/docs/12/auth-trust.html\n'
fi fi
echo "host all all all $POSTGRES_HOST_AUTH_METHOD" printf 'host all all all %s\n' "$POSTGRES_HOST_AUTH_METHOD"
} >> "$PGDATA/pg_hba.conf" } >> "$PGDATA/pg_hba.conf"
} }
@ -328,13 +328,17 @@ _main() {
docker_temp_server_stop docker_temp_server_stop
unset PGPASSWORD unset PGPASSWORD
echo cat <<-'EOM'
echo 'PostgreSQL init process complete; ready for start up.'
echo PostgreSQL init process complete; ready for start up.
EOM
else else
echo cat <<-'EOM'
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo PostgreSQL Database directory appears to contain a database; Skipping initialization
EOM
fi fi
fi fi

View File

@ -11,7 +11,7 @@ file_env() {
local fileVar="${var}_FILE" local fileVar="${var}_FILE"
local def="${2:-}" local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
exit 1 exit 1
fi fi
local val="$def" local val="$def"
@ -77,8 +77,8 @@ docker_init_database_dir() {
NSS_WRAPPER_GROUP="$(mktemp)" NSS_WRAPPER_GROUP="$(mktemp)"
export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
local gid; gid="$(id -g)" local gid; gid="$(id -g)"
echo "postgres:x:$uid:$gid:PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD" printf 'postgres:x:%s:%s:PostgreSQL:%s:/bin/false\n' "$uid" "$gid" "$PGDATA" > "$NSS_WRAPPER_PASSWD"
echo "postgres:x:$gid:" > "$NSS_WRAPPER_GROUP" printf 'postgres:x:%s:\n' "$gid" > "$NSS_WRAPPER_GROUP"
break break
fi fi
done done
@ -88,7 +88,7 @@ docker_init_database_dir() {
set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@" set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@"
fi fi
eval 'initdb --username="$POSTGRES_USER" --pwfile=<(echo "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"' eval 'initdb --username="$POSTGRES_USER" --pwfile=<(printf "%s" "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
# unset/cleanup "nss_wrapper" bits # unset/cleanup "nss_wrapper" bits
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
@ -157,7 +157,7 @@ docker_process_init_files() {
# psql here for backwards compatibility "${psql[@]}" # psql here for backwards compatibility "${psql[@]}"
psql=( docker_process_sql ) psql=( docker_process_sql )
echo printf '\n'
local f local f
for f; do for f; do
case "$f" in case "$f" in
@ -165,20 +165,20 @@ docker_process_init_files() {
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452 # https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then if [ -x "$f" ]; then
echo "$0: running $f" printf '%s: running %s\n' "$0" "$f"
"$f" "$f"
else else
echo "$0: sourcing $f" printf '%s: sourcing %s\n' "$0" "$f"
. "$f" . "$f"
fi fi
;; ;;
*.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;; *.sql) printf '%s: running %s\n' "$0" "$f"; docker_process_sql -f "$f"; printf '\n' ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; *.sql.gz) printf '%s: running %s\n' "$0" "$f"; gunzip -c "$f" | docker_process_sql; printf '\n' ;;
*.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; *.sql.xz) printf '%s: running %s\n' "$0" "$f"; xzcat "$f" | docker_process_sql; printf '\n' ;;
*.sql.zst) echo "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; *.sql.zst) printf '%s: running %s\n' "$0" "$f"; zstd -dc "$f" | docker_process_sql; printf '\n' ;;
*) echo "$0: ignoring $f" ;; *) printf '%s: ignoring %s\n' "$0" "$f" ;;
esac esac
echo printf '\n'
done done
} }
@ -209,7 +209,7 @@ docker_setup_db() {
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL' POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
CREATE DATABASE :"db" ; CREATE DATABASE :"db" ;
EOSQL EOSQL
echo printf '\n'
fi fi
} }
@ -243,12 +243,12 @@ pg_setup_hba_conf() {
auth="$(postgres -C password_encryption "$@")" auth="$(postgres -C password_encryption "$@")"
: "${POSTGRES_HOST_AUTH_METHOD:=$auth}" : "${POSTGRES_HOST_AUTH_METHOD:=$auth}"
{ {
echo printf '\n'
if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then
echo '# warning trust is enabled for all connections' printf '# warning trust is enabled for all connections\n'
echo '# see https://www.postgresql.org/docs/12/auth-trust.html' printf '# see https://www.postgresql.org/docs/12/auth-trust.html\n'
fi fi
echo "host all all all $POSTGRES_HOST_AUTH_METHOD" printf 'host all all all %s\n' "$POSTGRES_HOST_AUTH_METHOD"
} >> "$PGDATA/pg_hba.conf" } >> "$PGDATA/pg_hba.conf"
} }
@ -328,13 +328,17 @@ _main() {
docker_temp_server_stop docker_temp_server_stop
unset PGPASSWORD unset PGPASSWORD
echo cat <<-'EOM'
echo 'PostgreSQL init process complete; ready for start up.'
echo PostgreSQL init process complete; ready for start up.
EOM
else else
echo cat <<-'EOM'
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo PostgreSQL Database directory appears to contain a database; Skipping initialization
EOM
fi fi
fi fi

View File

@ -11,7 +11,7 @@ file_env() {
local fileVar="${var}_FILE" local fileVar="${var}_FILE"
local def="${2:-}" local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
exit 1 exit 1
fi fi
local val="$def" local val="$def"
@ -77,8 +77,8 @@ docker_init_database_dir() {
NSS_WRAPPER_GROUP="$(mktemp)" NSS_WRAPPER_GROUP="$(mktemp)"
export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP export LD_PRELOAD="$wrapper" NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
local gid; gid="$(id -g)" local gid; gid="$(id -g)"
echo "postgres:x:$uid:$gid:PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD" printf 'postgres:x:%s:%s:PostgreSQL:%s:/bin/false\n' "$uid" "$gid" "$PGDATA" > "$NSS_WRAPPER_PASSWD"
echo "postgres:x:$gid:" > "$NSS_WRAPPER_GROUP" printf 'postgres:x:%s:\n' "$gid" > "$NSS_WRAPPER_GROUP"
break break
fi fi
done done
@ -88,7 +88,7 @@ docker_init_database_dir() {
set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@" set -- --waldir "$POSTGRES_INITDB_WALDIR" "$@"
fi fi
eval 'initdb --username="$POSTGRES_USER" --pwfile=<(echo "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"' eval 'initdb --username="$POSTGRES_USER" --pwfile=<(printf "%s" "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
# unset/cleanup "nss_wrapper" bits # unset/cleanup "nss_wrapper" bits
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
@ -157,7 +157,7 @@ docker_process_init_files() {
# psql here for backwards compatibility "${psql[@]}" # psql here for backwards compatibility "${psql[@]}"
psql=( docker_process_sql ) psql=( docker_process_sql )
echo printf '\n'
local f local f
for f; do for f; do
case "$f" in case "$f" in
@ -165,20 +165,20 @@ docker_process_init_files() {
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452 # https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then if [ -x "$f" ]; then
echo "$0: running $f" printf '%s: running %s\n' "$0" "$f"
"$f" "$f"
else else
echo "$0: sourcing $f" printf '%s: sourcing %s\n' "$0" "$f"
. "$f" . "$f"
fi fi
;; ;;
*.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;; *.sql) printf '%s: running %s\n' "$0" "$f"; docker_process_sql -f "$f"; printf '\n' ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; *.sql.gz) printf '%s: running %s\n' "$0" "$f"; gunzip -c "$f" | docker_process_sql; printf '\n' ;;
*.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; *.sql.xz) printf '%s: running %s\n' "$0" "$f"; xzcat "$f" | docker_process_sql; printf '\n' ;;
*.sql.zst) echo "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; *.sql.zst) printf '%s: running %s\n' "$0" "$f"; zstd -dc "$f" | docker_process_sql; printf '\n' ;;
*) echo "$0: ignoring $f" ;; *) printf '%s: ignoring %s\n' "$0" "$f" ;;
esac esac
echo printf '\n'
done done
} }
@ -209,7 +209,7 @@ docker_setup_db() {
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL' POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
CREATE DATABASE :"db" ; CREATE DATABASE :"db" ;
EOSQL EOSQL
echo printf '\n'
fi fi
} }
@ -243,12 +243,12 @@ pg_setup_hba_conf() {
auth="$(postgres -C password_encryption "$@")" auth="$(postgres -C password_encryption "$@")"
: "${POSTGRES_HOST_AUTH_METHOD:=$auth}" : "${POSTGRES_HOST_AUTH_METHOD:=$auth}"
{ {
echo printf '\n'
if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then if [ 'trust' = "$POSTGRES_HOST_AUTH_METHOD" ]; then
echo '# warning trust is enabled for all connections' printf '# warning trust is enabled for all connections\n'
echo '# see https://www.postgresql.org/docs/12/auth-trust.html' printf '# see https://www.postgresql.org/docs/12/auth-trust.html\n'
fi fi
echo "host all all all $POSTGRES_HOST_AUTH_METHOD" printf 'host all all all %s\n' "$POSTGRES_HOST_AUTH_METHOD"
} >> "$PGDATA/pg_hba.conf" } >> "$PGDATA/pg_hba.conf"
} }
@ -328,13 +328,17 @@ _main() {
docker_temp_server_stop docker_temp_server_stop
unset PGPASSWORD unset PGPASSWORD
echo cat <<-'EOM'
echo 'PostgreSQL init process complete; ready for start up.'
echo PostgreSQL init process complete; ready for start up.
EOM
else else
echo cat <<-'EOM'
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo PostgreSQL Database directory appears to contain a database; Skipping initialization
EOM
fi fi
fi fi