Merge from vendor branch HEIMDAL:
[dragonfly.git] / etc / isdn / tell-record
1 #!/bin/sh
2 #---------------------------------------------------------------------------
3 #
4 #       tell called and calling numbers answer script for i4b isdnd
5 #       -----------------------------------------------------------
6 #
7 # $FreeBSD: src/etc/isdn/tell-record,v 1.4.2.1 2001/03/06 02:42:05 obrien Exp $
8 # $DragonFly: src/etc/isdn/tell-record,v 1.2 2003/06/17 04:24:47 dillon Exp $
9 #
10 #       last edit-date: [Tue Oct 31 10:59:49 2000]
11 #
12 #---------------------------------------------------------------------------
13 VARDIR=/var/isdn
14
15 #FreeBSD < 3.1, NetBSD, OpenBSD, BSD/OS
16 #LIBDIR=/usr/local/lib/isdn
17 #FreeBSD 3.1 and up
18 LIBDIR=/usr/share/isdn
19
20 LOGFILE=/tmp/answer.log
21 NCALLFILE=${VARDIR}/ncall
22 DATE=`date +%d%H`
23 DF=0
24 dF=0
25 sF=0
26
27 if ! set -- `getopt D:d:s: $*`; then
28         echo 'Usage: answer -D device -d destination -s source'
29         exit 1
30 fi
31
32 for i ; do
33         case ${i} in
34         -D)
35                 DEVICE=$2
36                 DF=1
37                 shift
38                 shift
39                 ;;
40         -d)
41                 DEST=$2
42                 dF=1
43                 shift
44                 shift
45                 ;;
46         -s)
47                 SRC=$2
48                 sF=1
49                 shift
50                 shift
51                 ;;
52         --)
53                 shift
54                 break
55                 ;;
56         esac
57 done
58
59 echo "" >>${LOGFILE}
60
61 if [ "${DF}" -eq 0 -o "${dF}" -eq 0 -o "${sF}" -eq 0 ]; then
62         echo 'Usage: answer -D device -d destination -s source'
63         exit 1
64 fi
65
66 echo "answer: device ${DEVICE} destination ${DEST} source ${SRC} " >>${LOGFILE}
67
68 if [ -r "${LIBDIR}/beep.al" ]; then
69         dd of=${DEVICE} if=${LIBDIR}/beep.al bs=2k >/dev/null 2>&1
70 fi
71
72 # tell the caller the number he is calling from
73
74 POS=1
75 LENGTH=`expr ${SRC} : '.*'`
76
77 while : ; do
78         DIGIT=`echo ${SRC} | cut -c ${POS}`
79         /bin/dd of=${DEVICE} if=${LIBDIR}/${DIGIT}.al bs=2k >/dev/null 2>&1
80         POS=`expr ${POS} + 1`
81         if [ "${POS}" -gt "${LENGTH}" ]; then
82                 break
83         fi
84 done
85
86 if [ -r "${LIBDIR}/beep.al" ]; then
87         dd of=${DEVICE} if=${LIBDIR}/beep.al bs=2k >/dev/null 2>&1
88 fi
89
90 dd if=${DEVICE} of=${VARDIR}/recorded.msg bs=2k >/dev/null 2>&1