#!/bin/sh

# 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 dh_installdeb(1) or http://www.debian.org/doc/debian-policy/

set -e

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

#DEBHELPER#

case "$1" in
    configure)
        adduser --system --group --home /usr/yc/search/ --no-create-home --disabled-password --disabled-login yc_search || true
        mkdir -p /var/log/yc/search/yc_search_queue/
        mkdir -p /media/yc/search/queue/data/

        chown -R yc_search /usr/yc/search/
        chown -R yc_search /var/log/yc/search/yc_search_queue
        chown -R yc_search /media/yc/search/queue/data/
        RESTARTS_COUNT_FILE=/var/log/yc/search/yc_search_queue/yc_search_queue.restart
        touch $RESTARTS_COUNT_FILE
        chown yc_search $RESTARTS_COUNT_FILE

	# zookeeper must listen all addresses, do it in perboot script
	# sed -i "s/$(hostname)/0.0.0.0/g" /usr/yc/search/yc_search_queue/yc_search_queue.conf

        systemctl restart rsyslog.service
        systemctl daemon-reload || true
        ;;

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

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

exit 0
