entrypoint
686 Bytes
#!/bin/bash
set -ex
if [[ $(find /var/lib/postgresql -maxdepth 1 -mindepth 1|wc -l) = 0 ]]; then
zcat /var/lib/container/var_lib_postgresql.tar.gz | tar xf - -C /var/lib/postgresql
fi
postgres_home="$(getent passwd postgres | cut -f 6 -d :)"
if [[ $GID && $GID -ne 0 ]]; then
old_gid=$(getent group postgres | cut -f 3 -d :)
groupmod -g $GID postgres
find "$postgres_home" /etc/postgresql /var/run/postgresql -gid $old_gid -print0 | xargs -0r chgrp postgres
fi
if [[ $UID && $UID -ne 0 ]]; then
old_uid=$(getent passwd postgres | cut -f 3 -d :)
usermod -u $UID postgres
find /etc/postgresql /var/run/postgresql -uid $old_uid -print0 | xargs -0r chown postgres
fi
exec "$@"