Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2014 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/41e98af7f5955b46e843 to your computer and use it in GitHub Desktop.
Save anonymous/41e98af7f5955b46e843 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Install latest stable Asterisk and latest FreePBX 2.11.x on SME Server (http://contribs.org)
# Script by Hsing-Foo Wang - hsingfoo@gmail.com
#
clear
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"
else
/sbin/e-smith/db yum_repositories set epel-asterisk \
repository Name 'Epel-asterisk - EL6' \
BaseUrl 'http://download.fedoraproject.org/pub/epel/6/$basearch' \
MirrorList 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=$basearch' \
EnableGroups no GPGCheck yes GPGKey http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL Visible no status disabled
signal-event yum-modify
echo "epel-asterisk repository added"
fi
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 http://downloads.asterisk.org/pub/telephony/sounds/asterisk-extra-sounds-en-ulaw-current.tar.gz
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
else
echo "Asterisk version $ASTERISK_INSTALLED already installed, assuming the rest of the asterisk RPM's too..."
fi
#
# 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
FREEPBX_VERSION="2.11.0.38"
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 http://mirror.freepbx.org/freepbx-$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 /. http://mirror.contribs.org/releases/obsolete/7.6/smecontribs/x86_64/RPMS/smeserver-freepbx-0.1-32.el4.sme.noarch.rpm
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 127.0.0.1' /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="/var/lib/asterisk/bin/freepbx_setting"
$FPBX_SETTING_PATH DISABLE_CSS_AUTOGEN 1
$FPBX_SETTING_PATH CHECKREFERER 0
$FPBX_SETTING_PATH AUTHTYPE none
$FPBX_SETTING_PATH AMPEXTENSIONS deviceanduser
$FPBX_SETTING_PATH AMPWEBROOT /opt/freepbx
$FPBX_SETTING_PATH MODULEADMINWGET 1
$FPBX_SETTING_PATH DYNAMICHINTS 1
$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[@]}"
do
rm -f /etc/asterisk/$symlink
ln -s /opt/freepbx/admin/modules/core/etc/$symlink /etc/asterisk/$symlink
done
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[@]}"
do
sudo -u asterisk /var/lib/asterisk/bin/module_admin -f --repos standard,extended,unsupported upgrade $fpbx_module
done
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 "************************************************************************"
echo "All done. The install log is over at /root/freepbx_install.log"
echo
echo "You can now go to the Server Manager to configure FreePBX"
echo
echo "May the dial tone be with you."
echo
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...
#SETTING FILE PERMISSIONS
#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