#!/bin/sh
# preinst script for percona-pg-telemetry
#
# see: dh_installdeb(1)

# create a postgres group and user

if ! getent passwd postgres > /dev/null; then
    adduser --system $quiet --home /var/lib/postgresql --no-create-home \
        --shell /bin/bash --group --gecos "PostgreSQL administrator" postgres
fi
# if the user was created manually, make sure the group is there as well
if ! getent group postgres > /dev/null; then
    addgroup --system $quiet postgres
fi
# make sure postgres is in the postgres group
if ! id -Gn postgres | grep -qw postgres; then
    adduser $quiet postgres postgres
fi
