Build guide for SheevaPlug disk image


We’ve been asked to provide details on how to built and Put together the SheevaPlug disk image.

While I have not had time to ‘write out’ this entire script, I’ve noted what steps and bugs I’ve found along the way below and how we got around them. Its not pretty in spots, and we hope to get some insight into some of the compiling dirty tricks we’ve used below.

The Majority of this is executable shell scripting in Linux, but don’t copy/paste this into a terminal and expect it to run.

Its really dirty. To be honest, we have two dreams. A pre-built disk image someone can flash and boot from, or a Shell Script that power users can run from a base Debian system in their Sheeva that will download, build, compile, install and configure their system.

We can’t do it alone, so please help out if you can fix/patch/improve what we’ve started below! Reach out to us, anyone who has kung fu we’ll happily give out access to alter content on the website!

Update:  Read somewhere to Edit makeopts, find PROC=armv5tejl and change to PROC=arm, save and exit to have error free compilation of Asterisk…Have yet to try


# Most portions used from Stephen Brown's Debian Lenny Script -
# Other portinons from Dr. Peter N. Steinmetz -
# Preston Moore -
# Must be run with superuser privileges.
# There is no error checking here, but it is known to work on a base sheeva plug install (debian squeeze)
# Install the Latest 'safe' version of Asterisk 1.6
# asterisk-1.6.1-current.tar.gz
# asterisk-addons-1.6.1
# freepbx-2.5.2           (via wget)
# libpri-         (via wget)
# dahdi/dahdi-tools       (package dahdi-linux-complete)
# If it Breaks, be sure to share fixes / updates
# "I'm gonna go build my own theme park! With blackjack and hookers! In fact, forget the park!" - Bender
# script functions
# random password generator function
# this may not be the most secure method as it makes use of /dev/urandom but can generate random passwords nonetheless  
function passwd ()
	echo "# Make sure to keep these in a safe place!!!" > /root/passwords
	echo "MySQL root password is: $MYSQL_ROOT_PW" >> /root/passwords
	echo "Asterisk database password is: $ASTERISK_DB_PW" >> /root/passwords
	echo "Asterisk manager portal password is: $ASTERISK_MGR_PW" >> /root/passwords
	echo "ARI password is: $ARI_PW" >> /root/passwords
	echo "Random passwords generated..."
# yes/no function for script interaction
function promptyn ()
        echo -n "$1 [y/N]? "
        read ANSWER
	if [ ! -z $ANSWER ]
       		if [ $ANSWER = Y ] || [ $ANSWER = y ]
# password generation
echo "Passwords for all applications will now be generated and placed in /root/passwords Please move or copy this file to a safe place!"
echo "Press enter to continue: " ;read input
# ensure package directory up to date and system upgraded
promptyn "Preparing to run package updates. Would you like to install the OpenSSH server and client?"
	if [ "$ANSWER" = "N" ] ; then
		echo "OpenSSH server will NOT be installed, press enter to continue" ;read input
apt-get -y update
apt-get -y dist-upgrade
# variables
IP_ADRESS=`ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
# retrieve utilities and set debconf to noninteractive front-end
apt-get -y install debconf-utils
debconf-set-selections < < /etc/init.d/asterisk < <-END_STARTUP
set -e
set -a
test -x $DAEMON || exit 0
d_start() {
	amportal start
d_stop() {
	amportal stop
d_reload() {
	amportal restart
case "$1" in
	echo -n "Starting $DESC: $NAME"
	echo "."
	echo -n "Stopping $DESC: $NAME"
	echo "."
	echo -n "Restarting $DESC: $NAME"
	sleep 10
	echo "."
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 3
exit 0
chmod 755 /etc/init.d/asterisk
update-rc.d asterisk defaults 90 10
# configure freepbx
cd freepbx-${FREEPBX_VERSION}
# setup databases for freepbx use
mysqladmin -u root -p${MYSQL_ROOT_PW} create asterisk
mysqladmin -u root -p${MYSQL_ROOT_PW} create asteriskcdrdb
mysql -u root -p${MYSQL_ROOT_PW} asterisk < SQL/newinstall.sql
mysql -u root -p${MYSQL_ROOT_PW} asteriskcdrdb < SQL/cdr_mysql_table.sql
mysql -u root -p${MYSQL_ROOT_PW} <<-END_PRIVS
        GRANT ALL PRIVILEGES ON asterisk.* TO [email protected] IDENTIFIED BY "${ASTERISK_DB_PW}";
        GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO [email protected] IDENTIFIED BY "${ASTERISK_DB_PW}";
        flush privileges;
# reconfigure php for freepbx
cp /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini-orig
sed -i "s/(upload_max_filesize *= *)(.*)/120M/" /etc/php5/apache2/php.ini
sed -i "s/(memory_limit *= *)(.*)/1100M/" /etc/php5/apache2/php.ini
sed -i "s/(magic_quotes_gpc *= *)(.*)/1Off/" /etc/php5/apache2/php.ini
# fix up directory use and permissions for asterisk
mkdir /var/run/asterisk
chown asterisk:asterisk /var/run/asterisk
chown asterisk:asterisk -R /etc/asterisk
chown asterisk:asterisk -R /var/lib/asterisk
# chmod a+x /var/lib/asterisk/bin/*
chown asterisk:asterisk -R /var/log/asterisk
chown asterisk:asterisk -R /var/spool/asterisk
chown asterisk:asterisk -R /var/www
sed -i "s/[directories](!) .*/[directories]/" /etc/asterisk/asterisk.conf
sed -i "s|astrundir *=> */var/run|astrundir => /var/run/asterisk|" /etc/asterisk/asterisk.conf
#fix mohmp3
mkdir /var/lib/asterisk/mohmp3
chmod 775 /var/lib/asterisk/mohmp3
chown asterisk:asterisk /var/lib/asterisk/mohmp3
# start asterisk
./start_asterisk start
# configure amportal
cp amportal.conf /etc/amportal.conf
# Username should come before password in cdr_mysql.cof - seems to cause issues, you might have to manually edit after fact and invert entry order
sed -i "s/# (AMPDBUSER=asteriskuser) */1/" /etc/amportal.conf
sed -i "s/# (AMPDBPASS=).*/1${ASTERISK_DB_PW}/" /etc/amportal.conf
sed -i "s|(AMPWEBROOT=)/var/www/html|1/var/www|" /etc/amportal.conf
sed -i "s|(FOPWEBROOT=)/var/www/html/panel|1/var/www/panel|" /etc/amportal.conf
#sed -i "/#AMPWEBADDRESS=/d" /etc/amportal.conf
sed -i "s/AMPWEBADDRESS=/AMPWEBADDRESS=${IP_ADDRESS}/" /etc/amportal.conf
#Fix corrupted Pear PHP Channels and Fault Symlink present in PHP 5.9+?
#I found corrupted .channels and the bad symlink created by pear fucked over install DB module
# Freshen Up PHP install
apt-get remove php-pear
apt-get install php-pear
# Blow away bad channels and repair
rm -f /usr/share/php/.channels
pear update-channels
#Fix the bad symlink
rm -f /usr/share/php/doc
ln -s /usr/share/doc/php-pear/ doc
#Install the needed pear DB module for FreePBX Installer
pear install DB
cd /usr/src/freepbx-${FREEPBX_VERSION}
# install amp
# Fix Hold music screwup ???
cp /var/lib/asterisk/moh/*.wav  /var/lib/asterisk/mohmp3/
# need to make SED statement to re-populate the hold music abs. path?
# start apache web server
/etc/init.d/apache2 restart
# start amportal
amportal start
# set ARI admin password
sed -i "s/ari_password/${ARI_PW}/" /var/www/recordings/includes/main.conf.php
echo "Complete. You can access FreePBX at $IP_ADDRESS"</pre>


Leave a comment

You must be logged in to post a comment.