entrypoint 683 Bytes
#!/bin/bash

declare -a found_errors

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 ]]; 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 ]]; 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 "$@"