#! /bin/sh

# This shellscript gets called by vgetty if a DTMF
# command is detected, the digits heard are stored
# in $1 (not including the leading * and trailing #).

# Default location is in /usr/spool/voice, make sure that
# the `zplay' utility is somewhere in the path.

# Below is sample code for remote playing of messages,
# type the code (`*12345#') on a touchtone phone after the
# recording beep, it will play all messages received 
# since your last call.

CODE=12345

PATH=/bin:/usr/bin:/usr/local/bin:/usr/spool/voice

# Tell somebody about the DTMF command (this is silly...)
echo $1 | mail -s 'DTMF command' root

if [ .$1 != .$CODE ]
then
	# spy alert !!!!!!!
	exit 1
fi

cd /usr/spool/voice

if [ ! -f timestamp ]; then touch timestamp; fi
touch timestamp-n

for i in `find incoming -type f -newer timestamp -print`
do
	# short beep
	zplay -S -b '[880,990,4]'
	# play the message
	zplay -S $i
done
# long beep
zplay -S -b '[880,990,12]'

mv timestamp-n timestamp
