#!/bin/sh

cmd_frontlight=/mnt/onboard/.kobo/koreader/frontlight

frontlight_level_default=30
test -e /tmp/frontlight || echo $frontlight_level_default > /tmp/frontlight

arg=":$1"

if test $arg == :off ; then
	rm -f /tmp/frontlight-on
	$cmd_frontlight 0
	exit
fi

if test $arg == :on ; then
	prev_level=0
	test -e /tmp/frontlight  && prev_level=$(cat /tmp/frontlight)
	$cmd_frontlight $prev_level
	touch /tmp/frontlight-on
	exit
fi

if test $arg == :swap ; then
 if test -e /tmp/frontlight-on ; then
  ${cmd_frontlight}-wrap off
 else
  ${cmd_frontlight}-wrap on
 fi

 exit
fi

# default is level to set
$cmd_frontlight $1
echo $1 >  /tmp/frontlight
if test $arg == :0 ; then
	rm -f /tmp/frontlight-on
else
	touch /tmp/frontlight-on
fi


