Script SIp and Voicemail creation

does anyone have a shell script that does this?

I currently have this code, but it has one issue it doesn’t know how to insert the voicemail line in the correct spot above the [other] tag, and it puts the [extn] at the bottom of the file I wouldn’t think would be a issue. I just need to figure out how to handle the voicemail part. Anyone got a suggestion or am I recreating the wheel?

[code]
#!/bin/bash

Asterisk User Creaion Script

@author Richard ‘Moose’ Genthner rgenthner@symplicity.com

@date 07/14/2009

@version 1 reveision 2

fullname=$2
extension=$1
nat=$3
mac=$5
email=$4
dir=/etc/asterisk/
echo “Creating User ${fullname}'s Phone extension"
echo “updating sip.conf"
echo “” >> ${dir}sip.conf
echo “[${extension}]” >> ${dir}sip.conf
echo “type=friend” >> ${dir}sip.conf
echo “secert=${extension}” >> ${dir}sip.conf
echo “host=dynamic” >> ${dir}sip.conf
echo “dtmfmode=rfc2833” >> ${dir}sip.conf
echo “nat=${nat}” >> ${dir}sip.conf
echo “callerid=”${fullname} <${extension}>”” >> ${dir}sip.conf
echo “mailbox=${extension}” >> ${dir}sip.conf
echo “canreinvite=no” >> ${dir}sip.conf
echo "…Done!"
echo "Creating users voicemail box"
echo "updating voicemail.conf…"
echo “${extension} => ${extension},${fullname},${email},|tz=${timezone}\n” >> ${dir}voicemail.conf
echo "…Done!"
if [ -z $mac ];then
echo "Issuing Asterisk reload Please Stand by"
asterisk -rx "reload"
echo "…Done!"
echo "Asterisk Configuration Complete. Please test call the Extension."
exit 1
else
echo "Creating Phone Home Directory"
cp -R /home/phone_template /home/phone${extension}
echo "…Done!"
echo "Updating Files "
mv /home/phone${extension}/phoneEXTN.cfg /home/phone${extension}/phone${extension}.cfg
mv /home/phone${extension}/0004f20_mac_addr.cfg /home/phone${extension}/${mac}.cfg
sed -e “s/extn/${extension}/g” /home/phone${extension}/phone${extension}.cfg
echo "Phone${extension}.cfg Updated [OK]"
sed -e “s/EMPLOYEES NAME/${fullname}/g” /home/phone${extension}/sip.cfg
echo "Phone${extension}.cfg Updated [OK]"
sed -e “s/password in sip.cfg/${extension}/g” /home/phone${extension}/sip.cfg
echo "Phone${extension}.cfg Updated [OK]"
sed -e “s/EXTN/${extension}/g” /home/phone${extension}/${mac}.cfg
echo "Phone${extension}.cfg Updated [OK]"
echo "…Done! updating Files"
echo "Issue Asterisk a reload Please Stand By"
asterisk -rx "reload"
echo "…Done!"
echo "Making User for phone"
adduser ${extension}
echo -e “${extension}\n${extension}” | (passwd --stdin ${extension})
echo "Phones username: ${extension} password: ${extension}"
chown -R phone${extension}:phone${extension} /home/phone${extension}
echo "…Done! Please update ${fullname}'s Phone with the correct information"
echo "Asterisk Configuration Complete. Please test call the extension."
fi[/code]