extMOHSetter code


#!/bin/bash

# Set Usage string for less typing in param checks.
USAGE="Usage: extMOHSetter extensionList.txt MOHClassName\n\nExample: extMOHSetter /tmp/extList.txt CustomMOHClass\n\n";

## Check and validate parameters section

# Check to see if any params were passed in.
if [[ $# -eq 0 ]]
then
echo "### ERROR: All Arguments Missing.\n\n";
echo "$USAGE";
exit 1;
fi

# Check if extension file list exists.
if [[ ! -f $1 ]]
then
echo "### ERROR: Extension List file does not exist or was not found.\n\n";
echo "$USAGE";
exit 1;
fi

# Check if MOH Class parameter is present.
if [[ -z $2 ]]
then
echo "### ERROR: Missing MOH Class Parameter.\n\n";
echo "$USAGE";
exit 1;
fi

# Set Variables
EXTLISTFILE=$1;
MOHCLASS=$2;
OUTPUTFILE="/etc/asterisk/sip_custom_post.conf";

# Cat out ext list and read into $line.
cat $EXTLISTFILE | while read line
do
# Append data to asterisk config file.
echo $line >> $OUTPUTFILE;
echo mohsuggest=$MOHCLASS >> $OUTPUTFILE;
echo >> $OUTPUTFILE;
done

/var/lib/asterisk/bin/retrieve_conf && /var/lib/asterisk/bin/module_admin reload;