Solid Asterisk install Script

Hello Everyone,

I have posted before about some difficulties with compiling asterisk and its asterisk sound componenet, using Ubuntu.  I've been building virtual installations over and over and over, with the same error message during the build. I believe it all comes down to installing the extra packages that apt-get suggests. And somewhere in the mix, compiles fail. 

But I came across a blog for installing Asterisk, Asterisk-sound, Zaptel, (Dahdi tools and kernel can be easily applied).

prestonmoore.com/archives/51 … s-5.3.html

In a nutshell, what the author did was create a script that installs the required dependencies, asterisk components and Freepbx and databases and tables. The only requirement is that you run yum updates or apt-get updates and reboot prior to running script. After downloading script, you need to make script executable (chmod 754) and run as root.

I tested the Centos install and it was perfect. I changed the script to work for a new Ubuntu install. I am building an asterisk pbx that will provide media services (voicemail), while use Openser as front end sip engine. I attached my version of script for review. I use aptitude -R (ubuntu) for package install, because it does not install packages I don’t need. Hope this helps.

[code]
#!/bin/bash

This script to install the Zaptel drivers, Asterisk and FreePBX

on a new install of Ubuntu

Must be run with superuser privileges.

There is no error checking here, but it is known to work on a base

install as of 01 Jun 2009, with downloaded versions:

asterisk-1.4.25

asterisk-addons-1.4.8

freepbx-2.5.1

libpri-1.4.10

zaptel-1.4.12.1

Sections of this script originally written for Ubuntu by Dr. Peter N. Steinmetz

Preston Moore - www.prestonmoore.com

Don’t forget to “apt-get update” and REBOOT before executing the script!

definitions of items to possibly change

export ASTERISK_DB_PW=asteriskpbX
export ASTERISK_MGR_PW=asteriskpbX

install packages needed beyond base install

aptitude -R -y install linux-kernel-dev build-essential linux-source linux-image-$(uname -r)
aptitude -R -y install make bison flex linux-libc-dev libgtk2.0-dev
aptitude -R -y install php5-cli php-pear php5-mysql php-pear php5-gd curl
aptitude -R -y install sox libncurses5-dev libssl-dev libmysqlclient15-dev libmysql+±dev

install pear DB module

pear install db

place source packages in standard place

cd /usr/src

download, make and install XML library for Google Talk

aptitude -R -y install libgnutls-dev
wget http://iksemel.googlecode.com/files/iksemel-1.3.tar.gz
tar xfz iksemel-1.3.tar.gz
cd iksemel-1.3
./configure
make
make install
cd …

download, make and install Speex codec

aptitude -R -y install libogg-dev
wget http://downloads.xiph.org/releases/speex/speex-1.2rc1.tar.gz
tar xfz speex-1.2rc1.tar.gz
cd speex-1.2rc1
./configure
make
make install
cd …

download, make, install, and configure zaptel drivers

wget http://downloads.digium.com/pub/zaptel/zaptel-1.4-current.tar.gz
tar xfz zaptel-1.4-current.tar.gz
cd find . -name "zaptel-1.4.*" -print
./configure
make
make install
make config
cd …

download, make and install libpri

wget http://downloads.digium.com/pub/libpri/libpri-1.4-current.tar.gz
tar xfvz libpri-1.4-current.tar.gz
cd find . -name "libpri-1.4.*" -print
make
make install
cd …

download, make and install asterisk and configuration files

wget http://downloads.digium.com/pub/asterisk/asterisk-1.4-current.tar.gz
tar xfvz asterisk-1.4-current.tar.gz
cd find . -name "asterisk-1.4.*" -print
sed -i “s/char uniqueid[80]/char uniqueid[128]/” ./apps/app_voicemail.c
./configure
make
make install
make samples
cd …

download, make and install asterisk-addons

wget http://downloads.digium.com/pub/asterisk/asterisk-addons-1.4-current.tar.gz
tar xfvz asterisk-addons-1.4-current.tar.gz
cd find . -name "asterisk-addons-1.4.*" -print
./configure
make
make install
cd …

download and install extra asterisk sounds

mkdir asterisk-sounds
cd asterisk-sounds
wget http://downloads.digium.com/pub/telephony/sounds/asterisk-extra-sounds-en-gsm-current.tar.gz
tar -zxf asterisk-extra-sounds-en-gsm-current.tar.gz
cp -rf * /var/lib/asterisk/sounds
cd …

create asterisk user and group for apache server

useradd -c “Asterisk PBX” -d /var/lib/asterisk asterisk

fix up apache configuration to run as asterisk user

chown asterisk /var/lib/php/session/
cp -v /etc/apache2/envvars /etc/apache2/envvars.original
sed -i “s/User=www-data/User=asterisk/” /etc/apache2/envvars
sed -i “s/Group=www-data/Group=asterisk/” /etc/apache2/envvars

add dummy timing device for asterisk

modprobe ztdummy

#mysqladmin -u root -p${MYSQL_ROOT_PW} create asterisk
#mysql -u root -p${MYSQL_ROOT_PW} <<-END_PRIVS

GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY “${ASTERISK_DB_PW}”;

GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@’%’ IDENTIFIED BY “${ASTERISK_DB_PW}”;

#END_PRIVS

#configure asterisk extconfig.conf
sed -i “s/;sipusers => odbc,asterisk/sipusers => mysql,asterisk,sip/” /etc/asterisk/extconfig.conf
sed -i “s/;sippeers => odbc,asterisk/sippeers => mysql,asterisk,sip/” /etc/asterisk/extconfig.conf
sed -i “s/;voicemail => odbc,asterisk/voicemail => mysql,asterisk,voicemail/” /etc/asterisk/extconfig.conf

cp /usr/src/asterisk-addons-1.4.9/configs/res_mysql.conf.sample /etc/asterisk/res_mysql.conf

#configure res_mysql.conf
sed -i “s/;dbhost = 127.0.0.1/dbhost = 192.168.2.60/” /etc/asterisk/res_mysql.conf
sed -i “s/;dbuser = myuser/dbuser = asterisk/” /etc/asterisk/res_mysql.conf
sed -i “s/;dbpass = mypass/dbpass = asteriskpbX/” /etc/asterisk/res_mysql.conf
sed -i “s/;dbport = 3306/dbport = 3306/” /etc/asterisk/res_mysql.conf
sed -i “s/;dbsock = /tmp/mysql.sock/dbsock = /tmp/mysql.sock/” /etc/asterisk/res_mysql.conf

fix up directory use and permissions for asterisk

mkdir /var/run/asterisk
chown asterisk:asterisk -Rv /var/run/asterisk
chown asterisk:asterisk -Rv /etc/asterisk
chown asterisk:asterisk -Rv /var/lib/asterisk
chown asterisk:asterisk -Rv /dev/zap
chown asterisk:asterisk -Rv /var/log/asterisk
chown asterisk:asterisk -Rv /var/spool/asterisk
chown asterisk:asterisk -Rv /var/www/html
sed -i “s|astrundir *=> */var/run|astrundir => /var/run/asterisk|” /etc/asterisk/asterisk.conf
[/code][/code]