#!/bin/bash
DAEMON_USER='postgres'
DAEMON_GROUP="$DAEMON_USER"
install -o "$DAEMON_USER" -g "$DAEMON_GROUP" -m 0755 -d /var/run/postgresql
readarray -t stats_temp_directories < <(grep -oP "^stats_temp_directory\s*=\s*['\"]?\K[^'\"\s]*" /etc/postgresql/*/main/postgresql.conf)
for dir in "${stats_temp_directories[@]}"; do
  install -o "$DAEMON_USER" -g "$DAEMON_GROUP" -m 0755 -d "$dir"
done
exec run-script-daemon postgresql
