#! /bin/sh
#Endzeitscript fr lcd4linux
#
logofile="/tmp/lcd/logo"
endfile="/tmp/lcd/end"
endfileneu="/tmp/lcd/endzeit"
durationfile="/tmp/lcd/duration"
read logo < $logofile
logo=$(echo ${logo:29:3})

if [ $(expr match "$logo" "mp_") -eq 3 ]; then
	pos=$(cut -d '/' -f 1 "$durationfile")
	ges=$(cut -d '/' -f 2 "$durationfile")
	rest=$(expr $ges - $pos)
	std=$(date +"%H")
	min=$(date +"%M")
	mins=$(expr $min + $rest + $std \* 60)
	std=$(printf "%02d\n" $(expr $mins / 60 % 24))
	min=$(printf "%02d\n" $(expr $mins % 60))
	echo "$std:$min" > $endfileneu
else
	cp -f $endfile $endfileneu
fi
echo .
exit 0