#!/bin/bash

#======================================
# Configure...
#--------------------------------------

sed -i "s|#listen_addresses = 'localhost'.*|listen_addresses = '*'|g" /usr/share/postgresql14/postgresql.conf.sample
sed -i "s|#unix_socket_directories = '/tmp'.*|unix_socket_directories = '/run/postgresql'|g" /usr/share/postgresql14/postgresql.conf.sample

mkdir -p /var/lib/postgresql/data
chown -R postgres:postgres /var/lib/postgresql/data
chown -R postgres:postgres /docker-entrypoint.sh /docker-healthcheck.sh
chmod u+x /docker-entrypoint.sh /docker-healthcheck.sh

# make the image smaller: remove most of locale files
find /usr/share/locale -mindepth 1 -maxdepth 1 ! -name 'en' ! -name 'en_US*' | xargs rm -r

exit 0
