#!/bin/sh

file_path="/etc/enigma2/settings"
config_key="config.cimisc.cihelperenabled=False"

if grep -q "$config_key" "$file_path"; then
    exit 0
fi

[ -x /usr/bin/ciplushelper ] || exit 0

case "$1" in
	start)
		if [ -n "`pidof /usr/bin/ciplushelper`" ] ; then
			echo "ciplushelper is already running!"
		else
			echo -n "Running ciplushelper..."
			sleep 2
			/usr/bin/ciplushelper &
		fi
	;;
	stop)
		killall ciplushelper 2>/dev/null
		echo "done."
	;;
	restart)
		$0 stop
		sleep 3
		$0 start
	;;
	enable_autostart)
		update-rc.d ciplushelper defaults 50
	;;
	disable_autostart)
		update-rc.d -f ciplushelper remove
	;;
	*)
	echo " "
	echo "Options: $0 {start|stop|restart|enable_autostart|disable_autostart}"
	echo " "
	exit 1
esac

exit 0
