freebsd-dev/share/examples/isdn/contrib/answer.sh
Hellmuth Michaelis 9210280057 Add the contributed directory from the i4b tarball and the files from it
which would be nice to have.
Move isdnd_acct and isdnctl to the contrib directory where they belong to.
2001-05-25 13:25:59 +00:00

112 lines
2.1 KiB
Bash

#!/bin/sh
#---------------------------------------------------------------------------
#
# answer script for i4b isdnd
# ---------------------------
#
# last edit-date: [Fri May 25 15:21:05 2001]
#
# $FreeBSD$
#
#---------------------------------------------------------------------------
VARDIR=/var/isdn
LIBDIR=/usr/local/lib/isdn
LOGFILE=/tmp/answer.log
NCALLFILE=$VARDIR/ncall
DATE=`date +%d%H`
progname=${0##*/}
set -- $@ # have to split argument string !!!
# ----------------------------------------------------------------------
usage ()
{
echo "usage: $progname -D device -d dest -s src"
exit 1
}
ncall ()
{
nfile=$1
[ -f $nfile ] && read n < $nfile || n=0
echo $(($n + 1)) > $nfile
printf "%.4d" $n
}
# ----------------------------------------------------------------------
while getopts "D:d:s:" opt
do
case $opt
in
D) DEVICE=$OPTARG ;;
d) DEST=$OPTARG ;;
s) SRC=$OPTARG ;;
esac
done
[ -c "$DEVICE" -a -n "$DEST" -a -n "$SRC" ] || usage;
shift $(($OPTIND - 1))
# ----------------------------------------------------------------------
NCALL=`ncall $NCALLFILE`
echo "$progname: device $DEVICE destination $DEST source $SRC " >>$LOGFILE
{
echo "Date: "`date`
echo "From: \"$SRC\""
echo "To: \"$DEST\""
echo
} >> $VARDIR/I.$NCALL.$DATE
# ----------------------------------------------------------------------
tellnumber ()
{
number=$1
digits=`echo $number | sed -e 's/\(.\)/\1 /g'`
files=""
for digit in $digits
do
files="$files $LIBDIR/$digit.al"
done
cat $files
}
# ----------------------------------------------------------------------
do_answer ()
{
[ -f $LIBDIR/beep.al ] && cat $LIBDIR/beep.al
[ -f $LIBDIR/msg.al ] && cat $LIBDIR/msg.al
[ -f $LIBDIR/beep.al ] && cat $LIBDIR/beep.al
} > $DEVICE
do_record ()
{
cat $DEVICE > $VARDIR/R.$NCALL.$DATE
}
do_tell ()
{
[ -f $LIBDIR/beep.al ] && cat $LIBDIR/beep.al
[ -f $LIBDIR/msg.al ] && cat $LIBDIR/msg.al
tellnumber $SRC
[ -f $LIBDIR/beep.al ] && cat $LIBDIR/beep.al
} > $DEVICE
# ----------------------------------------------------------------------
case $progname
in
answer) do_answer ;;
record) do_answer; do_record ;;
tell) do_tell ;;
esac