#!/bin/sh

# Must have /usr/sbin in $PATH

FLINT=1000
DATE=`date "+%F %T"`

# Connect the alsa channel as the conference leader.

asterisk -rx "console dial ${FLINT}_admin@conferences"
STATUS=$?

if [ $STATUS -eq 0 ]; then
  MSG="success"
else
  MSG="FAILURE!"
fi

# Give the leader time to join
sleep 5s

# Create call file to connect another member of the conference.  This call
# file originates a call using the Local channel and sets the second leg
# of the call up to send audio to an icecast server using chan_ices.

cat > $HOME/$FLINT.call <<EOF
Channel: Local/$FLINT@conferences
MaxRetries: 2
RetryTime: 60
WaitTime: 30
Context: conferences
Extension: ${FLINT}_ices
Priority: 1
EOF

# Move the call file to the outgoing directory
mv $HOME/$FLINT.call /var/spool/asterisk/outgoing

cat > /tmp/draftfile <<EOF
Subject: LeaderConnect: $FLINT $MSG
To: gentlec

Exit status: $STATUS
$DATE
EOF

mutt -H /tmp/draftfile < /dev/null
