#!/bin/bash
cd `dirname $0`/../
path_tools=`pwd`

CENTOS="CentOS"
UBUNTU="Ubuntu"
DEBIAN="Debian"
TLINUX="tlinux"
OPENSUSE="openSUSE"
OTHER="otheros"

VOS=$OTHER
issue=`cat /etc/issue | tr A-Z a-z`
if [ `echo $issue | grep debian | wc -l` -ge 1 ]; then
    VOS=$DEBIAN
elif [ `echo $issue | grep ubuntu | wc -l` -ge 1 ]; then
    VOS=$UBUNTU
elif [ `echo $issue | grep centos | wc -l` -ge 1 ]; then
    VOS=$CENTOS
elif [ `echo $issue | grep tlinux | wc -l` -ge 1 ]; then
    VOS=$TLINUX
elif [ `echo $issue | grep opensuse | wc -l` -ge 1 ]; then
    VOS=$OPENSUSE
fi

tools/stop.sh

if [ $VOS = $TLINUX ] || [ $VOS = $CENTOS ] || [ $VOS = $OPENSUSE ]; then
    chkconfig loglistenerd on
elif [ $VOS = $DEBIAN ] || [ $VOS = $UBUNTU ]; then
    update-rc.d /etc/init.d/loglistenerd start 55 2 3 4 5 . stop 45 0 1 6 .
else
    ln -s /etc/init.d/loglistenerd /etc/rc.d/rc0.d/K45loglistenerd
    ln -s /etc/init.d/loglistenerd /etc/rc.d/rc1.d/K45loglistenerd
    ln -s /etc/init.d/loglistenerd /etc/rc.d/rc2.d/S55loglistenerd
    ln -s /etc/init.d/loglistenerd /etc/rc.d/rc3.d/S55loglistenerd
    ln -s /etc/init.d/loglistenerd /etc/rc.d/rc4.d/S55loglistenerd
    ln -s /etc/init.d/loglistenerd /etc/rc.d/rc5.d/S55loglistenerd
    ln -s /etc/init.d/loglistenerd /etc/rc.d/rc6.d/K45loglistenerd
fi

bin/loglistenerm -d    1>&2 2>/dev/null &

