#!/bin/sh
SD=/mnt/card
CF=/mnt/cf
HD=/data
SOUND=/usr/share/sounds/click.wav

if [ "$1" = "-wait" ]; then
  if [ "$2" != "" ]; then
    sleep $2
  else
    sleep 5
  fi
fi

if [ -f $SOUND ]; then 
  if [ -f /usr/bin/esdplay ]; then
    esdplay $SOUND
  else 
    cat $SOUND > /dev/dsp 
  fi
fi

let i=1
FN="$SD/screencap$i.png"
while test -f $FN || test -f $FN.xwd;
do
  let i=1+$i
  FN="$SD/screencap$i.png"
done

echo "saving screenshot as $FN"
if [ -f /usr/local/bin/scrot ]; then
  scrot "$FN"
else 
  xwd -display :0 -root > "$FN".xwd
  if [ "`which convert`" != "" ]; then
    convert "$FN".xwd "$FN"
    if [ -f $FN ]; then
      rm "$FN".xwd
    fi
  fi
fi
