#!/usr/bin/env bash set -e POSTGRES_USER="postgres" if [ "$(uname)" = "OpenBSD" ]; then POSTGRES_USER="_postgresql" fi cd / username=$1 shift tables="$(printf "'%s'," "${@//\'/\'\'}")" tables="${tables%,}" case "$(id -un)" in root) psql=(su -s /usr/bin/env - -- "$POSTGRES_USER" psql postgres "$POSTGRES_USER") ;; "$POSTGRES_USER") psql=(psql postgres "$POSTGRES_USER") ;; *) psql=(psql -h localhost postgres "$username") ;; esac "${psql[@]}" -v ON_ERROR_STOP=1 <