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

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

add_group_if_missing() {
    if [ -x /usr/sbin/adduser ]; then
        if ! id -g yacy >/dev/null 2>&1; then
                addgroup --gid 265 --force-badname yacy
        fi
    fi
}

add_user_if_missing() {
    if [ -x /usr/sbin/adduser ]; then
        if ! id -u yacy > /dev/null 2>&1; then
            adduser --system --home /var/lib/yacy --no-create-home \
                --uid 264 --gid 265 --disabled-password --force-badname \
                yacy
        fi
    fi
}

add_group_if_missing
add_user_if_missing

chown yacy:yacy -R /var/lib/yacy

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