#!/bin/sh
# Skript which is executed when the powerbutton is pressed
POWER_CMD="svdrpsend.pl HITK power"
EJECT_CMD="/_config/bin/ejectb.sh"

PBTMP="/tmp/~pb"

$POWER_CMD

if [ -f $PBTMP ] ; then
   ACTDATE=`date +%s`
   FDATE=`ls -l --time-style=+%s $PBTMP | tr -s ' ' |cut -f6 -d ' '`
   DIFF=$(($ACTDATE - $FDATE))
   if [ $DIFF -le 2 ] ; then
      $EJECT_CMD
      rm $PBTMP
   else
      logger -s "PB $ACTDATE $FDATE $DIFF"
      touch $PBTMP
   fi
else
   logger -s "PowerButton sent"
   touch $PBTMP
fi
