Skip to content

Instantly share code, notes, and snippets.

Created Dec 9, 2014
What would you like to do?
# Install latest stable Asterisk and latest FreePBX 2.11.x on SME Server (
# Script by Hsing-Foo Wang -
echo "Installing Asterisk and FreePBX..."
# Check if asterisk is already installed, and if not, enable epel repo if required and install latest stable 1.8.x asterisk
# The epel repo is named asterisk-epel, for it could well be that the regular epel repo has (user specified) includes/excludes
# and we do not want to override existing carefully crafted repo's
ASTERISK_INSTALLED=$(rpm -q asterisk)
if [[ ! $ASTERISK_INSTALLED == *rpm* ]];then
echo "Checking for the epel-asterisk repository..."
EPEL_ASTERISK_SET=$(/sbin/e-smith/db yum_repositories gettype epel-asterisk)
if [[ $EPEL_ASTERISK_SET == *repository* ]];then
echo "epel repository already exists, nothing to do"
/sbin/e-smith/db yum_repositories set epel-asterisk \
repository Name 'Epel-asterisk - EL6' \
BaseUrl '$basearch' \
MirrorList '$basearch' \
EnableGroups no GPGCheck yes GPGKey Visible no status disabled
signal-event yum-modify
echo "epel-asterisk repository added"
echo "Installing latest stable asterisk 1.8 version and dependencies from the epel repository"
yum -y install iksemel speex spandsp asterisk asterisk-mysql asterisk-sounds-core-en-ulaw php-posix asterisk-calendar asterisk-fax asterisk-jabber asterisk-ldap asterisk-snmp asterisk-voicemail --enablerepo=epel-asterisk
echo "Get the additional sound files, unpack and symlink to /var/lib/asterisk/sounds/en. Then remove the tgz archive"
wget -P /usr/share/asterisk/sounds
tar zxvf /usr/share/asterisk/sounds/asterisk-extra-sounds-en-ulaw-current.tar.gz -C /usr/share/asterisk/sounds
rm -f /usr/share/asterisk/sounds/asterisk-extra-sounds-en-ulaw-current.tar.gz
# create a symbolic link to the sounds directory, still need to find out why /etc/asterisk/asterisk.conf astdatadir is not working
# changed the template so astdatadir is now set to /usr.share/asterisk. What's the difference if any?
ln -sfn /usr/share/asterisk/sounds/ /var/lib/asterisk/sounds/en
echo "Asterisk version $ASTERISK_INSTALLED already installed, assuming the rest of the asterisk RPM's too..."
# Done with the easy bit...
echo "Download and install FreePBX (The hugely hacky way for the time being)"
#Create the install directory, and make sure there is no old version for the script will stop
mkdir -p /usr/share/freepbx/sources
rm -f /usr/share/freepbx/sources/freepbx-$FREEPBX_VERSION.tgz
# FreePBX stable version 2.11.x for use with Asterisk 1.8. FPBX version 2.12.x is a different beast, don't even try it!
wget -P /usr/share/freepbx/sources$FREEPBX_VERSION.tgz
tar zxvf /usr/share/freepbx/sources/freepbx-$FREEPBX_VERSION.tgz -C /usr/share/freepbx/sources
#ln -s /usr/share/freepbx/sources/freepbx /usr/share/freepbx/sources/freepbx
# Correct path to php-asmanager.php /etc/e-smith/events/actions/freepbx-dump-astdb refers to an old path on line 18
# require_once($amp_conf['AMPWEBROOT']."/admin/libraries/php-asmanager.php"); thus replacing /common/ with /libraries/
sed -i 's/common/libraries/g' /etc/e-smith/events/actions/freepbx-dump-astdb #NOT WORKING!
echo "Get the SME FreePBX contrib and only extract actions, events and templates"
wget -P /.
cd / && rpm2cpio /smeserver-freepbx-0.1-32.el4.sme.noarch.rpm | cpio -idmvu
rm -f /smeserver-freepbx-0.1-32.el4.sme.noarch.rpm
# Remove Flash Operator Panel stuff
rm -f /etc/e-smith/web/functions/fop
rm -f /etc/e-smith/web/panels/manager/cgi-bin/fop
rm -f -r /opt/freepbx/panel
rm -f /etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/90FreePBX40Panel
config delete fop
sed -i '13 a\ Allow from' /etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/90FreePBX30Admin
# Change astdatadir to /usr/share/asterisk in /etc/asterisk/asterisk.conf generated by a template
sed -i 's/astdatadir => \/var\/lib\/asterisk/astdatadir => \/usr\/share\/asterisk/g' /etc/e-smith/templates/etc/asterisk/asterisk.conf/10dirs
# Add freePBX log rotation to /etc/logrotate.d/asterisk (Hacky! I know....)
sed -i 's/\/asterisk\/messages/\/asterisk\/messages \/var\/log\/asterisk\/freepbx*/' /etc/e-smith/templates/etc/logrotate.d/asterisk/All
# Symlink httpd-fpbx to deamontools in /etc/rc.d/init.d
ln -sfn /etc/rc.d/init.d/daemontools /etc/rc.d/init.d/httpd-fpbx
# Remove previous installation leftovers including databases!!! Contrib templates will remain in place tho.
mysqladmin -f drop freepbxdb
mysqladmin -f drop asteriskcdrdb
config delete freepbx
config delete dahdi
config delete httpd-fpbx
rm -f /etc/freepbx.conf
rm -f /etc/amportal.conf
rm -r -f /opt/freepbx
echo ""
echo "If you see warnings above, no worries, this is your first install so nothing to delete from a previous install"
echo ""
echo "Configuring FreePBX and doing some test which can take up to several minutes, please be patient...."
sed -i '/install_amp/c echo "a" | ./install_amp --webroot /opt/freepbx --dbname freepbxdb --debug >> /root/freepbx_install.log 2>&1' /etc/e-smith/events/actions/freepbx-checkinstall
#Fix chattr issue
# /var/lib/asterisk/bin/freepbx_engine line 296 (about). change from chattr -i $AMPWEBROOT/* 2>&1 >/dev/null to chattr -i $AMPWEBROOT/* 2>/dev/null !!!!Not working from the script but does work from the command line. WHY??
sed -i 's/2>&1/2/g' /var/lib/asterisk/bin/freepbx_engine
# This is the real FreePBX install command. freepbx-checkinstall comes from templates and starts the FreePBX installer
signal-event console-save
expand-template /etc/amportal.conf
signal-event freepbx-update
config setprop freepbx access public
signal-event remoteaccess-update
chown -R asterisk:asterisk /var/lib/php/fpbx-session
# Change FreePBX database settings that should have come from /etc/amportal.conf, but that needs a new e-smith template for FreePBX > 1.9
$FPBX_SETTING_PATH ARI_ADMIN_PASSWORD $(/sbin/e-smith/db configuration getprop freepbx AriPassword)
$FPBX_SETTING_PATH AMPMGRPASS $(/sbin/e-smith/db configuration getprop freepbx ManagerPassword)
#remove the default asterisk config files and replace them with symbolic links to FreePBX's own config files
CONF_FILES=(features.conf iax.conf logger.conf sip.conf sip_notify.conf ccss.conf extensions.conf confbridge.conf)
for symlink in "${CONF_FILES[@]}"
rm -f /etc/asterisk/$symlink
ln -s /opt/freepbx/admin/modules/core/etc/$symlink /etc/asterisk/$symlink
ln -sfn /opt/freepbx/admin/modules/cdr/etc/cel.conf /etc/asterisk/cel.conf
ln -sfn /opt/freepbx/admin/modules/cdr/etc/cel_odbc.conf /etc/asterisk/cel_odbc.conf
touch /etc/asterisk/cel_general_additional.conf
touch /etc/asterisk/cel_general_custom.conf
touch /etc/asterisk/cel_custom_post.conf
echo "Download and install most of the FreePBX modules."
# -f forces modules to install ignoring dependencies. There are dependencies, but all are satisfied with this list."
ALL_MODULES=(recordings framework findmefollow directory donotdisturb parking queues ringgroups setcid timeconditions vmblast printextensions weakpasswords fax iaxsettings outroutemsg pinsets manager customappsreg userman daynight pbdirectory phonebook dictate disa miscapps miscdests phpinfo queueprio speeddial contactdir customcontexts extensionsettings languages paging restart ivr backup accountcodepreserve presencestate announcement bulkdids bulkextensions callback callforward callwaiting conferences asteriskinfo campon hotelwakeup asterisk-cli blacklist cidlookup endpointman)
for fpbx_module in "${ALL_MODULES[@]}"
sudo -u asterisk /var/lib/asterisk/bin/module_admin -f --repos standard,extended,unsupported upgrade $fpbx_module
sudo -u asterisk /var/lib/asterisk/bin/retrieve_conf
sudo -u asterisk /var/lib/asterisk/bin/module_admin reload
amportal chown
# FreePBX sets ownership of /tmp to asterisk:asterisk. We do not want that. Needs a better fix then this. Find the root cause.
chown -R root:root /tmp
echo "************************************************************************"
echo "All done. The install log is over at /root/freepbx_install.log"
echo "You can now go to the Server Manager to configure FreePBX"
echo "May the dial tone be with you."
exit 0
# TO DO:
# Check CDR's, it seems CDR's are not logged correctly yet. MySQL issue?
# Check email for notifications, it's not working
# Check no repo's specified message from cron
$If you see warnings above, no worries, this is your first install so nothing to delete from a previous install
#Configuring FreePBX and doing some test which can take up to several minutes, please be patient....
#sed: can't read /var/lib/asterisk/bin/freepbx_engine: No such file or directory
#Please wait...
#chattr: Operation not supported while reading flags on /opt/freepbx/provisioning
#Permissions OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment