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

set -e

if ! getent group manticore >/dev/null; then
   addgroup --system manticore
fi
if ! getent passwd manticore >/dev/null; then
   adduser --system --ingroup manticore  --no-create-home --shell /bin/bash  --no-create-home --home /nonexistent manticore
fi
DATADIR=/var/lib/manticore
LOGDIR=/var/log/manticore
RUNDIR=/var/run/manticore
SYSCONFDIR=/etc/sphinxsearch
chown manticore:manticore $DATADIR
chown manticore:manticore $LOGDIR
chown manticore:manticore $RUNDIR
chown manticore:manticore $SYSCONFDIR

case "$1" in
    configure|abort-upgrade|abort-remove|abort-deconfigure)
    ;;

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

#add manticore init script to system start

#update-rc.d manticore defaults
echo ""
echo "Manticore installed!"
echo ""
echo "To manage indexes:"
echo "    editor /etc/sphinxsearch/sphinx.conf"
echo ""
echo "To rebuild all disk indexes:"
echo "    sudo -u manticore indexer --all --rotate"
echo ""
echo "To start/stop search daemon:"
if [ -x "/usr/bin/deb-systemd-helper" ]; then
echo "    systemctl start/stop manticore"
else
echo "    service manticore start/stop"
fi
echo "To query search daemon using MySQL client:"
echo "    mysql -h 0 -P 9306"
echo "    mysql> SELECT * FROM test1 WHERE MATCH('test');"
echo ""
echo "See the manual at docs.manticoresearch.com for details."
echo ""
echo "For commercial support please contact Manticore Software Ltd at"
echo "https://manticoresearch.com/contact/"
echo ""
#start manticore service

#invoke-rc.d manticore start

# section below id distribute-specific.
# It contains shell code generated by cmake cpack script.
if [ -x "/etc/init.d/manticore" ]; then
	update-rc.d manticore defaults >/dev/null
	invoke-rc.d manticore start
fi


#DEBHELPER#
