#!/bin/bash

#======================================
# Greeting...
#--------------------------------------
echo "Configure image: [$kiwi_iname]..."

#======================================
# Configure...
# This is based on Dockerfile from https://github.com/goharbor/harbor/tree/master/make/photon/db
#--------------------------------------

sed -i "s|#listen_addresses = 'localhost'.*|listen_addresses = '*'|g" /usr/share/postgresql12/postgresql.conf.sample \
sed -i "s|#unix_socket_directories = '/tmp'.*|unix_socket_directories = '/run/postgresql'|g" /usr/share/postgresql12/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 /docker-entrypoint-initdb.d
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
