#!/bin/sh

set -e

U_NAME='hbf'
U_HOME='/var/run/yandex-hbf-agent'

case "$1" in
    configure)
        if ! getent group ${U_NAME} > /dev/null; then
            groupadd ${U_NAME}
        else
            echo "Group '${U_NAME}' already exists."
        fi

        if ! getent passwd ${U_NAME} > /dev/null; then
            useradd --system --gid ${U_NAME} --shell /bin/false \
                    --home-dir ${U_HOME} ${U_NAME}
        else
            echo "Group '${U_NAME}' already exists."
        fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

service yandex-hbf-agent stop || :
service yandex-hbf-agent start || :

exit 0
