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