#!/bin/sh
# postinst script for kuiper
#
# see: dh_installdeb(1)

set -e -u

if command -v systemctl >/dev/null 2>&1; then
    systemctl enable kuiper
fi

# create group
if ! getent group kuiper >/dev/null; then
        addgroup --system kuiper
fi

# create user
if ! getent passwd kuiper >/dev/null; then
        adduser --ingroup kuiper \
                --home /var/lib/kuiper \
                --disabled-password \
                --system --shell /bin/bash --no-create-home \
                --gecos "kuiper user" kuiper
fi

chown -R kuiper:kuiper /var/lib/kuiper
chown -R kuiper:kuiper /usr/lib/kuiper
chown -R kuiper:kuiper /etc/kuiper

chmod 0755 /etc/kuiper
chmod 0644 /etc/kuiper/*
chmod -R +X /etc/kuiper
chmod -R 0755 /usr/lib/kuiper/bin
[ -f /usr/bin/kuiperd ] && rm /usr/bin/kuiperd
[ -f /usr/bin/kuiper ] && rm /usr/bin/kuiper
ln -s /usr/lib/kuiper/bin/server /usr/bin/kuiperd
ln -s /usr/lib/kuiper/bin/cli /usr/bin/kuiper

case "$1" in
    configure)
    ;;

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

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

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
