diff --git a/11/alpine3.17/docker-entrypoint.sh b/11/alpine3.17/docker-entrypoint.sh index a383a36487..97d10adf67 100755 --- a/11/alpine3.17/docker-entrypoint.sh +++ b/11/alpine3.17/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/11/alpine3.18/docker-entrypoint.sh b/11/alpine3.18/docker-entrypoint.sh index a383a36487..97d10adf67 100755 --- a/11/alpine3.18/docker-entrypoint.sh +++ b/11/alpine3.18/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/11/bookworm/docker-entrypoint.sh b/11/bookworm/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/11/bookworm/docker-entrypoint.sh +++ b/11/bookworm/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/11/bullseye/docker-entrypoint.sh b/11/bullseye/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/11/bullseye/docker-entrypoint.sh +++ b/11/bullseye/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/12/alpine3.17/docker-entrypoint.sh b/12/alpine3.17/docker-entrypoint.sh index a383a36487..97d10adf67 100755 --- a/12/alpine3.17/docker-entrypoint.sh +++ b/12/alpine3.17/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/12/alpine3.18/docker-entrypoint.sh b/12/alpine3.18/docker-entrypoint.sh index a383a36487..97d10adf67 100755 --- a/12/alpine3.18/docker-entrypoint.sh +++ b/12/alpine3.18/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/12/bookworm/docker-entrypoint.sh b/12/bookworm/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/12/bookworm/docker-entrypoint.sh +++ b/12/bookworm/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/12/bullseye/docker-entrypoint.sh b/12/bullseye/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/12/bullseye/docker-entrypoint.sh +++ b/12/bullseye/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/13/alpine3.17/docker-entrypoint.sh b/13/alpine3.17/docker-entrypoint.sh index a383a36487..97d10adf67 100755 --- a/13/alpine3.17/docker-entrypoint.sh +++ b/13/alpine3.17/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/13/alpine3.18/docker-entrypoint.sh b/13/alpine3.18/docker-entrypoint.sh index a383a36487..97d10adf67 100755 --- a/13/alpine3.18/docker-entrypoint.sh +++ b/13/alpine3.18/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/13/bookworm/docker-entrypoint.sh b/13/bookworm/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/13/bookworm/docker-entrypoint.sh +++ b/13/bookworm/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/13/bullseye/docker-entrypoint.sh b/13/bullseye/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/13/bullseye/docker-entrypoint.sh +++ b/13/bullseye/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/14/alpine3.17/docker-entrypoint.sh b/14/alpine3.17/docker-entrypoint.sh index a383a36487..97d10adf67 100755 --- a/14/alpine3.17/docker-entrypoint.sh +++ b/14/alpine3.17/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/14/alpine3.18/docker-entrypoint.sh b/14/alpine3.18/docker-entrypoint.sh index a383a36487..97d10adf67 100755 --- a/14/alpine3.18/docker-entrypoint.sh +++ b/14/alpine3.18/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/14/bookworm/docker-entrypoint.sh b/14/bookworm/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/14/bookworm/docker-entrypoint.sh +++ b/14/bookworm/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/14/bullseye/docker-entrypoint.sh b/14/bullseye/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/14/bullseye/docker-entrypoint.sh +++ b/14/bullseye/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/15/alpine3.17/docker-entrypoint.sh b/15/alpine3.17/docker-entrypoint.sh index a383a36487..97d10adf67 100755 --- a/15/alpine3.17/docker-entrypoint.sh +++ b/15/alpine3.17/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/15/alpine3.18/docker-entrypoint.sh b/15/alpine3.18/docker-entrypoint.sh index a383a36487..97d10adf67 100755 --- a/15/alpine3.18/docker-entrypoint.sh +++ b/15/alpine3.18/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/15/bookworm/docker-entrypoint.sh b/15/bookworm/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/15/bookworm/docker-entrypoint.sh +++ b/15/bookworm/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/15/bullseye/docker-entrypoint.sh b/15/bullseye/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/15/bullseye/docker-entrypoint.sh +++ b/15/bullseye/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/16/alpine3.17/docker-entrypoint.sh b/16/alpine3.17/docker-entrypoint.sh index a383a36487..97d10adf67 100755 --- a/16/alpine3.17/docker-entrypoint.sh +++ b/16/alpine3.17/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/16/alpine3.18/docker-entrypoint.sh b/16/alpine3.18/docker-entrypoint.sh index a383a36487..97d10adf67 100755 --- a/16/alpine3.18/docker-entrypoint.sh +++ b/16/alpine3.18/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/16/bookworm/docker-entrypoint.sh b/16/bookworm/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/16/bookworm/docker-entrypoint.sh +++ b/16/bookworm/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/16/bullseye/docker-entrypoint.sh b/16/bullseye/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/16/bullseye/docker-entrypoint.sh +++ b/16/bullseye/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 0ae0ecf8c2..97d10adf67 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init=false + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then