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

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

RETVAL=$?

case "$1" in
	start)
		if [ -f /var/lock/subsys/unicon ] ; then
			echo -n "Unicon has been already started!"
			exit 2;
		fi
		echo -n "Starting unicon..."
		/usr/bin/unicon-start
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/unicon
		;;
	stop)
                if [ ! -f /var/lock/subsys/unicon ] ; then
                        echo -n "Unicon has not been already started!"
                        exit 2;
                fi
                echo -n "Shuting down unicon... "
		ps ax | grep unicon | head -1 | while read a b ; do 
			kill $a ;
		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 "No status available for this package"
		exit 0
		;;
	*)
		echo "Usage: unicon {start|stop|restart|reload|status}"
		exit 1
esac

exit $RETVAL
