#!/bin/sh

# Must have /usr/sbin in $PATH

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

# The confbridge.conf file is configured to kick all participants when the
# leader leaves.  This should take care of our ices caller too.

asterisk -rx "console hangup"
STATUS=$?

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

# Restart just to clean up in case the conference room didn't disappear.
#asterisk -rx "core restart gracefully"

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

Exit status: $STATUS
$DATE
EOF

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