Mac OS X and the Mac Mini

Setting Up Asterisk on a Mac Mini

Why a Mac Mini?

The Mac Mini, while it does not have PCI slots for any T1 or FXO/FXS cards, is a great compact system for Asterisk, tftp server, light duty file server, and overall tiny platform you can stick in an environment with minimal obtrusiveness. Think of it as one of the only server platform for people with studio apartments.

If you’re lucky enough to have an Intel Mac Mini, you are able to benefit from much larger Serial ATA disks getting up to 320GB easily available as of this writing (February 2008).

Why OS X as a Host OS?

OS X is increasingly used in businesses and home and 10.5 can be configured and automated from the command line. Leopard also includes an excellent improved Macintalk voice called “Alex” that can be called via AGI easily.


Software Platform Prerequisites:

  • OS X 10.5.2 - You may use earlier, but this is current and stable
  • XCode 3.0.1 - This is needed to get access to compilers, install packages, etc.
  • Asterisk 1.4.X sources - Of course you’ll need these. I started on Asterisk 1.6 beta 3, but decided to go with a production-tested version
  • macports 1.6.0 - Use the macports port system to quickly install the supplemental packages:
  • mpg321, mpg123, doxygen, fortune, sox, wget, links, tcpdump, fortune, wireshark

Hardware Platform Prerequisites:

Mac Mini G4 1.25ghz / Intel Core Duo or above
40GB HD is fine, but bigger is always better if you are going to use this for more than just a telephone server. I upgraded my 1.25ghz G4 Mini to a faster 7200RPM 120GB drive.
Network Router that can advertise tftp servers (OpenWRT on a Linksys WRT54G will be my example for the home network)

Initial setup:

Install OS X, install XCode, macports, disable energy savings. If you are concerned about security, add in an asterisk user and group that the daemon can run under. Update OS X with Software Update.

Open up Terminal run the command
/opt/local/bin/port install mpg321 mpg123 fortune sox wget tcpdump doxygen wireshark

NOTE: This procedure may take a REALLY LONG time especially if you’re on the older G4 platform. It might be worthwhile to run GNU screen to easily scroll back on compliation errors. There are times when the source may require something in
/Developer/usr/bin or /opt/local/bin to be installed/linked in /usr/bin instead.

Macports/Xcode add their own PATH structure, so I like to add the appropriate paths into the appropriate files:
/etc/paths:
/opt/local/bin
/opt/local/sbin
/Developer/usr/bin

/etc/manpaths:
/opt/local/man
/opt/local/share/man
/Developer/usr/share/man
/Developer/usr/X11/man

Be sure to open up a new shell so it acquires the new paths. Grab the asterisk source and stick it in /tmp:

cd /tmp

curl -o asterisk.tar.gz http://downloads.digium.com/pub/asterisk/asterisk-1.4-current.tar.gz

tar xzvf asterisk.tar.gz

cd asterisk-*

./configure

This process should take a little while. By the time it ends, you should see a giant ASCII version of the Asterisk logo and some info about the platform you just built on. You’re close to making this a reality.

Let’s compile the source!

Run make if you have a Core Solo or G4 machine. If you have a Core Duo or Core 2 Duo Mac Mini, you can try make -j 2 which should spawn off two compile jobs at a time, taking advantage of the two cores.

Run make install and it should install in the default sections. I encourage you to make samples and make progdocs if you went ahead and installed doxygen from the port command above. More documentation is always better of course.

Since we used the default install location from the Makefile, the asterisk binary was installed in /usr/sbin/asterisk .

Create /Library/LaunchDaemons/com.asterisk.org.asterisk with the following content:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Disabled</key>
        <false/>
        <key>Label</key>
        <string>com.asterisk.org.asterisk</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/sbin/asterisk</string>
                <string>-f</string>
        </array>
        <key>UserName</key>
        <string>root</string>
        <key>GroupName</key>
        <string>wheel</string>
        <key>OnDemand</key>
        <false/>
        <key>ServiceDescription</key>
        <string>Asterisk PBX</string>
</dict>
</plist>


And if you want to start the daemon:

sudo launchctl load -w /Library/LaunchDaemons/com.asterisk.org.asterisk

And it should show it is running by grepping for the asterisk process:

ps auxwww | grep asterisk should show something like:

root 32427 0.0 0.7 90096 7404 ?? Ss 9:47PM 0:00.42 /usr/sbin/asterisk -f

Alright! So we’ve installed asterisk, we’ve installed the startup process, now we can start playing with dialplans, etc. I am not going to go into setting up asterisk with extensions and sip accounts here, as that is specific to asterisk. My favorite tutorial on explaining the basics is Practical Asterisk 1.4 at
http://www.the-asterisk-book.com/unstable/ .

MacOS-specific enhancements like Macintalk:

Create /var/lib/asterisk/agi-bin/macintalk with executable permissions:


#!/bin/bash
trap 'rm /tmp/agi$$_*; exit' INT TERM HUP
#declare -a array
while read -e ARG && [ "$ARG" ] ; do :; done # variables not needed
#        array=(` echo $ARG | sed -e 's/://' -e 's/"//g'`)
#       varname=${array[0]}
#        unset array[0]
#       export $varname="${array[*]}"
#done
unqarg=` echo $1 | sed -e 's/"//g'`

checkresults() {
        while read line
        do
        case ${line:0:4} in
        "200 " ) echo $line >&2
                 return;;
        "510 " ) echo $line >&2
                 return;;
        "520 " ) echo $line >&2
                 return;;
        *      ) echo $line >&2;;       #keep on reading those Invlid command
                                        #command syntax until "520 End ..."
        esac
        done
}

say -v Alex -o /tmp/agi$$_1.aiff "$unqarg"
/opt/local/bin/sox /tmp/agi$$_1.aiff -r 8000 -t ul /tmp/agi$$_2.ulaw
echo "EXEC Playback /tmp/agi$$_2"
checkresults

rm /tmp/agi$$_*


Note the line that starts with “say -v Alex” that I am specifying Alex as the voice. You can change this to other voices, and possibly third party Macintalk voices.

In extensions.conf, add in the following in an appropriate extension like this:

exten => 555,1,agi,macintalk|"Welcome to Asterisk. Isn’t my voice excellent?"

A fun challenge for the reader to try out would be to change the script into something that might invoke a short fortune cookie saying by invoking /opt/local/bin/fortune -s instead:



#!/bin/bash
trap 'rm /tmp/agi$$_*; exit' INT TERM HUP
#declare -a array
while read -e ARG && [ "$ARG" ] ; do :; done # variables not needed
#        array=(` echo $ARG | sed -e 's/://' -e 's/"//g'`)
#       varname=${array[0]}
#        unset array[0]
#       export $varname="${array[*]}"
#done
unqarg=`/opt/local/bin/fortune -s`
checkresults() {
        while read line
        do
        case ${line:0:4} in
        "200 " ) echo $line >&2
                 return;;
        "510 " ) echo $line >&2
                 return;;
        "520 " ) echo $line >&2
                 return;;
        *      ) echo $line >&2;;       #keep on reading those Invlid command
                                        #command syntax until "520 End ..."
        esac
        done
}

say -v Alex -o /tmp/agi$$_1.aiff "$unqarg"
/opt/local/bin/sox /tmp/agi$$_1.aiff -r 8000 -t ul /tmp/agi$$_2.ulaw
echo "EXEC Playback /tmp/agi$$_2"
checkresults

rm /tmp/agi$$_*



Macintalk makes things quite nice, but you may want to practice with pronunciation of certain complicated words or names.

If your Mac Mini Asterisk server grows and grows to the point that you need an actual T1, you’ll have to get an external terminator such as the RedFone foneBridge2 or another system that can terminate a T1 using the zaptel driver and a zapata-compatible T1 card.

If you have the ability to make the Mac Mini your default tftp server via telephone configuration menu or via DHCP, running the tftp server will provide useful, so go to this Apple Support Document.

While it only mentions OS X Server, this also applies to the standard OS X distribution as well. I like to also run ln -s /private/tftpboot /tftpboot to make the path similar to other UNIX variants.

If you’re running OpenWRT or another DHCP/DNS server running dnsmasq, edit the
/etc/dnsmasq.conf file and add the lines

dhcp-option=66,"192.168.0.60"
dhcp-boot=/tftpboot/pxelinux.0,boothost,192.168.0.60

where 192.168.0.60 gets substituted for the IP address of your OS X box. The second line isn’t necessarily required, but very helpful in case you ever decide to run a Linux PXE bootloader for any clients on the network. You can also setup an OS X NetBoot environment, but you should look elsewhere for that.

In my /private/tftpboot, I have a D-Link ATA configuration file, Cisco firmware for the 7940/7960 platform, configuration files for the Cisco, and customized ringtones. It works out pretty well this way.

Many of these scripts have been taken and modified from various sources on the Internet. Most of the sources came from voip-info, nerd-vittles , or just from the web.



What about security?

I didn’t claim for this to be secure. you can easily change the ownership of the Asterisk daemon and run it as the special user, or do what seems to be best practice in typically securing Asterisk. I take no responsibilities if you are lazy enough to let a cracker get into your system.... :-)

Created by: kraptv, Last modification: Fri 05 of Nov, 2010 (23:22 UTC) by admin


Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+

Page Changes | Comments

 

Featured -

Search: