#!/bin/sh
#
# Load unicon
#
# chkconfig: 234 95 05
# description: This package starts unicon.
# config: /usr/lib/unicon
# securlevel: 60

[ -f /usr/bin/unicon-start ] || exit 0

RETVAL=$?

UNICONPID=`pidof unicon`

case "$1" in
	start)
		if [ -f /var/lock/subsys/unicon ] && [ -n "$UNICONPID" ]; then
			echo "Unicon has been already started!"
			exit 2;
		fi
		echo "Starting unicon..."
		/usr/bin/unicon-start
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/unicon
		;;
	stop)
                if [ ! -f /var/lock/subsys/unicon ] && [ ! -n "$UNICONPID" ]; then
                        echo "Unicon has not been already started!"
                        exit 2;
                fi
                echo "Shuting down unicon... "
                for i in `pidof unicon` ; do
                        if [ "$i" != "$$" ] ; then
                                kill $i ;
                        fi
                done
		lsmod | grep encode\- | while read a b ; do
			rmmod $a ;
		done
		rmmod unikey
		rm -f /var/lock/subsys/unicon
		;;
	restart|reload)
		$0 stop
		$0 start
		exit 0
		;;
	status)
		echo "unicon is runing with pid of $UNICONPID"
		exit 0
		;;
	*)
		echo "Usage: unicon {start|stop|restart|reload|status}"
		exit 1
esac

exit $RETVAL
