Asterisk for Raspberry Pi on ArchLinux
If you don't want to follow these instructions and would prefer to download an image you can do so by downloading the image from Asterisk for Raspberry Pi Image.
The following instructions are based on Arch Linux ARM (archlinux-hf-2012-09-18.zip)
Write Image to SD Card
Using Win32DiskImager and the latest version of Arch Linux ARM from Raspberry Pi write the image to the SD card.
Once the image is written insert the SD card into the Raspberry Pi and boot. The device will get an IP address from DHCP.
Expand Partition
Now that the device has booted log on and change the default partition from 2 GB to the maximum partition of your SD card.
fdisk /dev/mmcblk0 d (delete) 2 (partition 2) n (new) p (primary partition) 2 (partition 2 as previously deleted) enter (accept default start sector) enter (accept default end sector) w (write changes) reboot
Once the rPi has rebooted
resize2fs /dev/mmcblk0p2 reboot
Swap File
As the rPi has limited RAM, either 256 or 512 depending on your version we'll create a swap file to allow application to use higher memory if required.
I would recommend allocating the size of the swap file to be that equal to the RAM size.
fallocate -l 256M /swapfile chmod 600 /swapfile mkswap /swapfile swapon /swapfile
The swap file is now active. We now need to ensure that it is used at boot.
vi /etc/fstab
add the line to the file
/swapfile none swap defaults 0 0
RAM Sizes
The RAM can be slipt between the CPU and GPU as follows:
for 256MB version, 240/16, 224/32, 192/64, 128/128 for 512MB version, 496/16, 384/128, 256/256
The default for the 256MB version is 224/32. As we don't need any GPU power we'll change this to 240/16.
vi /boot/config.txt
add a line at the bottom
gpu_mem=16
Update OS
pacman-key --init pacman -Syu --noconfirm reboot
Utilities
Install utilities to help with setup/administration
pacman -S initscripts vim mlocate zip unzip
vi to vim
pacman -R vi ln -s /usr/bin/vim /usr/bin/vi
Create ll alias
vi /root/.profile
add the line
alias ll="ls -la --color"
Enable Sound Card
vi /etc/rc.conf
add the line
MODULES=(snd-bcm2835)
Regional settings
Enable all AU and US entries, 4 lines
vi /etc/locale.gen
vi /etc/rc.conf locale-gen
Time Synchronisation
ln -s /usr/share/zoneinfo/Australia/Brisbane /etc/localtime pacman -R openntpd pacman -S ntp ntpdate ntp.bri.connect.com.au
vi /etc/rc.conf
remove hwclock and add ntpdate
Hostname
vi /etc/hostname vi /etc/hosts
vi /etc/dhcpcd.conf
add the line: nohook resolv.conf
remove the line: nohook lookup-hostname
Network
vi /etc/conf.d/network
add the lines
interface=eth0 address=192.168.1.1 netmask=255.255.255.0 broadcast=192.168.0.255 gateway=192.168.1.254
vi /etc/systemd/system/network.service
add the lines
[Unit] Description=Network Connectivity Wants=network.target Before=network.target [Service] Type=oneshot RemainAfterExit=yes EnvironmentFile=/etc/conf.d/network ExecStart=/sbin/ip link set dev ${interface} up ExecStart=/sbin/ip addr add ${address}/${netmask} broadcast ${broadcast} dev ${interface} ExecStart=/sbin/ip route add default via ${gateway} ExecStop=/sbin/ip addr flush dev ${interface} ExecStop=/sbin/ip link set dev ${interface} down [Install] WantedBy=multi-user.target
systemctl disable dhcpcd@eth0.service systemctl enable network.service reboot
vi /etc/resolv.conf
add the lines
domain mydomain.com search mydomain.com nameserver 192.168.1.254
Asterisk Packages
pacman -S gcc make hgsvn libxml2 libnewt sqlite subversion mysql spandsp speex systemctl enable mysqld.service systemctl start mysqld.service
Secure mysql
/usr/bin/mysql_secure_installation
Free Memory
So Asterisk will compile we need to free as many applications as possible from memory
systemctl stop ntpd.service systemctl stop mysqld.service
Install Asterisk
Download and install Asterisk. You can refer to Asterisk Install if required, but only Asterisk is required.
Set Asterisk to Automatic
vi /etc/rc.conf
and add asterisk to DEAMONS
logrotate
/etc/logrotate.d/asterisk
add the following lines to the file
/var/log/asterisk/messages /var/log/asterisk/*log { missingok notifempty rotate 12 weekly create 0640 root root postrotate /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null endscript }
logger
vi /etc/asterisk/logger.conf
change from:
;dateformat=%F %T
to
dateformat=%F %T %Z
Sendmail
pacman -R heirloom-mailx rm /etc/mail.rc.pacsave pacman -S ssmtp
vi /etc/ssmtp/ssmtp.conf
and add the lines
mailhub=192.168.13.3 hostname=rpi.klaverstyn.com FromLineOverride=yes
Edit aliases if required
vi /etc/ssmtp/revaliases
Install Apache
pacman -S apache php-apache php php-gd
vi /etc/httpd/conf/httpd.conf
and modify the following
AllowOverride All DirectoryIndex index.php index.html index.htm index.html.var
systemctl enable httpd.service
Configure php
vi /etc/php/php.ini
uncomment
extension=mysqli.so extension=mysql.so
vi /etc/httpd/conf/httpd.conf
add the following lines in thier respective sections
LoadModule php5_module modules/libphp5.so Include conf/extra/php5_module.conf AddHandler application/x-httpd-php .php
uncomment the following lines
TypesConfig conf/mime.types MIMEMagicFile conf/magic
vi /etc/httpd/conf/mime.types
add the following line
application/x-httpd-php5 php php5
systemctl start httpd.service
Note: The web root is /srv/http/
CDR
Refer to the Call Detail Records page which will allow Asterisk to write the CDR records to the database.
aCDR
aCDR is a web appliction that allows you to search throught your CDR records. View the aCDR page on installation.
Backup Script
Refer to Asterisk Backup Shell Script for the script itself.
pacman -S smbclient
perl
NOTE: To install the perl module requires more RAM that what is available on the 256MB model of the rPi. Make sure you have a swap file otherwise this section will fail.
pacman -S perl cpan libyaml perl-yaml libyaml perl-libwww sox mpg123
Text to Speech
perl -MCPAN -e "install Bundle::LWP" perl -MCPAN -e "install CGI::Util"
wget https://github.com/zaf/asterisk-googletts/blob/master/googletts.agi mv googletts.agi /var/lib/asterisk/agi-bin/ chmod 755 /var/lib/asterisk/agi-bin/googletts.agi
fax2mail
cd /usr/src wget http://search.cpan.org/CPAN/authors/id/R/RO/ROSCH/mime-construct-1.11.tar.gz tar xzvf mime-construct-1.11.tar.gz rm -f mime-construct-1.11.tar.gz cd mime-construct-1.11 perl Makefile.PL make install cd..
perl -MCPAN -e "install Bundle::LWP" perl -MCPAN -e "install Proc::WaitStat" perl -MCPAN -e "install MIME::Types"
wget http://www.klaverstyn.com.au/david/asterisk/files/fax2mail mv fax2mail /usr/sbin/ chmod 755 /usr/sbin/fax2mail mkdir /var/spool/asterisk/fax/
Reference
http://wiki.archlinux.org/index.php/Systemd
http://wiki.archlinux.org/index.php/Configuring_Network
http://wiki.archlinux.org/index.php/Beginners%27_Guide
http://wiki.archlinux.org/index.php/LAMP#PHP
http://raw.github.com/Evilpaul/RPi-config/master/config.txt