#!/bin/bash #------------------------------------------------------------------- # # Asterisk Installation Script # # This script will automatically install: # Dependencies # Asterisk-1.4.17 # Asterisk-Addons-1.4.5 # Zaptel-1.4.8 # LibPRI-1.4.3 # FreePBX-2.3.1 # mySQL to store CDR data # Webmin to administrate your server # phpMyAdmin to administrate your SQL server # # This script was written by Dr. Daniel Ali Aman - Krahenbuhl # E-Mail: daniel@intuitinnovations.com # # Script-Version: 0.1.1 Date: 09. March 2008 # # Installation Instructions: # - You need a running Debian 4r3 (minimal Netinstall) # - Working Internet connection # - Don't run the script in /usr/src (anywhere else is fine) # - Based on your internet connection the installation will take 1-2 hours # # Make sure you edit your sources.list (/etc/apt/sources.list) so your # system is able to download packages / dependencies from a debian mirror (remove the "CD-ROM" part.. !) # Then update the list of available package with the apt-get update command. # # Now you can execute the script. # # ./asterisk-1.4.18-install # # The script must be executable: # chmod +x asterisk-1.4.18-install # #------------------------------------------------------------------- echo "Asterisk Installation Script" DOWNLOAD_DIR1=http://intuitinnovations.com/asterisk/download DOWNLOAD_FILE1=asterisk-1.4.18.tar.gz DOWNLOAD_FILE2=asterisk-addons-1.4.6.tar.gz DOWNLOAD_FILE3=libpri-1.4.3.tar.gz DOWNLOAD_FILE4=zaptel-1.4.9.2.tar.gz DOWNLOAD_FILE5=freepbx-2.4.0.tar.gz DOWNLOAD_FILE6=lame-3.97.tar.gz DOWNLOAD_FILE7=amportal.conf DOWNLOAD_FILE8=webmin_1.380_all.deb DOWNLOAD_FILE9=phpsysinfo-2.5.4.tar.gz DOWNLOAD_FILE10=asterisk_menu_intuit.tar.gz DOWNLOAD_FILE11=zaptel #----------------------------------------------------------------------- # # Install Dependencies # #----------------------------------------------------------------------- echo "Install Debian 4 Depenencies" echo "This can take a while, depending on your internet connection" apt-get install -y build-essential libxml2 libxml2-dev libtiff4 libtiff4-dev php5 php5-cli php5-mysql php5 php5-cli php5-mysql php5-gd mysql-server libmysqlclient15-dev php-pear php-db linux-headers-`uname -r` curl sox apache2 libssl-dev libncurses5-dev bison libaudiofile-dev subversion libnewt-dev libcurl3-dev libnet-ssleay-perl openssl libauthen-pam-perl libio-pty-perl libmd5-perl echo "All Depenencies Successfully Installed" # Download Webmin echo "Webmin download started" WGET_OUTPUT=$(2>&1 wget --progress=dot:mega \ "$DOWNLOAD_DIR1/$DOWNLOAD_FILE8") if [ $? -ne 0 ] then # wget had problems. echo 1>&2 $0: "$WGET_OUTPUT" Exiting. exit 1 else echo "Webmin was downloaded" cp -f "$DOWNLOAD_FILE8" /usr/src/ rm "$DOWNLOAD_FILE8" fi # Download Zaptel config file echo "zaptel config file download started" WGET_OUTPUT=$(2>&1 wget --progress=dot:mega \ "$DOWNLOAD_DIR1/$DOWNLOAD_FILE11") if [ $? -ne 0 ] then # wget had problems. echo 1>&2 $0: "$WGET_OUTPUT" Exiting. exit 1 else echo "zaptel config file was downloaded" cp -f "$DOWNLOAD_FILE11" /usr/src/ rm "$DOWNLOAD_FILE11" fi # Download PHPSysinfo echo "PHPSysinfo download started" WGET_OUTPUT=$(2>&1 wget --progress=dot:mega \ "$DOWNLOAD_DIR1/$DOWNLOAD_FILE9") if [ $? -ne 0 ] then # wget had problems. echo 1>&2 $0: "$WGET_OUTPUT" Exiting. exit 1 else echo "PHPSysinfo was downloaded" cp -f "$DOWNLOAD_FILE9" /usr/src/ rm "$DOWNLOAD_FILE9" fi # Download Simple Admin Page echo "Admin-Page download started" WGET_OUTPUT=$(2>&1 wget --progress=dot:mega \ "$DOWNLOAD_DIR1/$DOWNLOAD_FILE10") if [ $? -ne 0 ] then # wget had problems. echo 1>&2 $0: "$WGET_OUTPUT" Exiting. exit 1 else echo "Admin-Page was downloaded" cp -f "$DOWNLOAD_FILE10" /usr/src/ rm "$DOWNLOAD_FILE10" fi # Download LIBPRI echo "Libpri download started" WGET_OUTPUT=$(2>&1 wget --progress=dot:mega \ "$DOWNLOAD_DIR1/$DOWNLOAD_FILE3") if [ $? -ne 0 ] then # wget had problems. echo 1>&2 $0: "$WGET_OUTPUT" Exiting. exit 1 else echo "Libpri was downloaded" cp -f "$DOWNLOAD_FILE3" /usr/src/ rm "$DOWNLOAD_FILE3" fi # Download Zaptel echo "Zaptel download started" WGET_OUTPUT=$(2>&1 wget --progress=dot:mega \ "$DOWNLOAD_DIR1/$DOWNLOAD_FILE4") if [ $? -ne 0 ] then # wget had problems. echo 1>&2 $0: "$WGET_OUTPUT" Exiting. exit 1 else echo "Zaptel was downloaded" cp -f "$DOWNLOAD_FILE4" /usr/src/ rm "$DOWNLOAD_FILE4" fi # Download Asterisk-Addonsfile echo "Asterisk-Addons download started" WGET_OUTPUT=$(2>&1 wget --progress=dot:mega \ "$DOWNLOAD_DIR1/$DOWNLOAD_FILE2") if [ $? -ne 0 ] then # wget had problems. echo 1>&2 $0: "$WGET_OUTPUT" Exiting. exit 1 else echo "Asterisk-Addons was downloaded" cp -f "$DOWNLOAD_FILE2" /usr/src/ rm "$DOWNLOAD_FILE2" fi # Download Asterisk echo "Asterisk download started" WGET_OUTPUT=$(2>&1 wget --progress=dot:mega \ "$DOWNLOAD_DIR1/$DOWNLOAD_FILE1") if [ $? -ne 0 ] then # wget had problems. echo 1>&2 $0: "$WGET_OUTPUT" Exiting. exit 1 else echo "Asterisk was downloaded" cp -f "$DOWNLOAD_FILE1" /usr/src/ rm "$DOWNLOAD_FILE1" fi # Download FreePBXcp -f "$DOWNLOAD_FILE5" /usr/src/ echo "FreePBX download started" WGET_OUTPUT=$(2>&1 wget --progress=dot:mega \ "$DOWNLOAD_DIR1/$DOWNLOAD_FILE5") if [ $? -ne 0 ] then # wget had problems. echo 1>&2 $0: "$WGET_OUTPUT" Exiting. exit 1 else echo "FreePBX was downloaded" cp -f "$DOWNLOAD_FILE5" /usr/src/ rm "$DOWNLOAD_FILE5" fi # Download LAME echo "LAME download started" WGET_OUTPUT=$(2>&1 wget --progress=dot:mega \ "$DOWNLOAD_DIR1/$DOWNLOAD_FILE6") if [ $? -ne 0 ] then # wget had problems. echo 1>&2 $0: "$WGET_OUTPUT" Exiting. exit 1 else echo "LAME was downloaded" cp -f "$DOWNLOAD_FILE6" /usr/src/ cp -f "$DOWNLOAD_FILE6" rm "$DOWNLOAD_FILE6" fi # Download amportal.conf cd /etc/ echo "amportal.conf download started" WGET_OUTPUT=$(2>&1 wget --progress=dot:mega \ "$DOWNLOAD_DIR1/$DOWNLOAD_FILE7") if [ $? -ne 0 ] then # wget had problems. echo 1>&2 $0: "$WGET_OUTPUT" Exiting. exit 1 else echo "amportal.conf was downloaded" fi echo "Unpacking all downloaded files....." #untar all downloaded files cd /usr/src tar -xzvf $DOWNLOAD_FILE1 tar -xzvf $DOWNLOAD_FILE2 tar -xzvf $DOWNLOAD_FILE3 tar -xzvf $DOWNLOAD_FILE4 tar -xzvf $DOWNLOAD_FILE5 tar -xzvf $DOWNLOAD_FILE6 #delete all downloaded tar files rm $DOWNLOAD_FILE1 rm $DOWNLOAD_FILE2 rm $DOWNLOAD_FILE3 rm $DOWNLOAD_FILE4 rm $DOWNLOAD_FILE5 rm $DOWNLOAD_FILE6 #------------------------------------------------------------------ # # Installing LAME 3.97 # #------------------------------------------------------------------ echo "Configure Makefile for LAME" cd /usr/src/lame-3.97 LAME_CONFIGURE=$(2>&1 ./configure) if [ $? -ne 0 ] then # ./configure had problems. echo 1>&2 $0: "$LAME_CONFIGURE" Exiting. exit 1cp -f "$DOWNLOAD_FILE5" /usr/src/ else echo "Successfully configured LAME Makefile" fi echo "Make and Install LAME" LAME_MAKE=$(2>&1 make && make install) if [ $? -ne 0 ] then # ./make and make install had problems. echo 1>&2 $0: "$LAME_MAKE" Exiting. exit 1 else echo "Lame was successfully installed" fi #------------------------------------------------------------------ # # Installing Zaptel # #------------------------------------------------------------------ echo "Install Zaptel" cd /usr/src/zaptel-1.4.9.2 ZAPTEL_CONFIGURE=$(2>&1 ./configure) if [ $? -ne 0 ] then # ./configure had problems. echo 1>&2 $0: "$ZAPTEL_CONFIGURE" Exiting. exit 1 else echo "Successfully configured ZAPTEL Makefile" fi echo "Make and Install Zaptel" Zaptel_MAKE=$(2>&1 make && make install) if [ $? -ne 0 ] then # ./make and make install had problems. echo 1>&2 $0: "$Zaptel_MAKE" Exiting. exit 1 else echo "Zaptel was successfully installed" fi echo "Configure Zaptel" Zaptel_Configure=$(2>&1 make config) if [ $? -ne 0 ] then # ./make and make install had problems. echo 1>&2 $0: "$Zaptel_Configure" Exiting. exit 1sed "1i\test" ld.so.conf > ld.so.conf.tmp else echo "Zaptel was successfully configured" fi echo "Load Zaptel Module" Zaptel_Load=$(2>&1 modprobe zaptel) if [ $? -ne 0 ] then # ./make and make install had problems. echo 1>&2 $0: "$Zaptel_Load" Exiting. exit 1 else echo "Zaptel was successfully loaded" fi #------------------------------------------------------------------ # # Installing LibPRI # #------------------------------------------------------------------ echo "Install LIBPRI" cd /usr/src/libpri-1.4.3 LibPRI_MAKE=$(2>&1 make && make install) if [ $? -ne 0 ] then # ./make and make install had problems.able 'asterisk.notifications' doesn't exist echo 1>&2 $0: "$LibPRI_MAKE" Exiting. exit 1 else echo "LIBPRI was successfully installed" fi #---------------------------------------------------------------- # # Various # #---------------------------------------------------------------- echo "Add Asterisk Group" groupadd asterisk echo "Add Asterisk User" useradd -c "asterisk PBX" -d /var/lib/asterisk -g asterisk asterisk echo "Create /var/run/asterisk directory" mkdir /var/run/asterisk echo "Change the owner of /var/run/astrisk to asterisk user" chown asterisk:asterisk /var/run/asterisk echo "Change the owner of /var/lib/php5 to asterisk user" chown -R asterisk /var/lib/php5 echo "Force Apache2 to run as the asterisk user" sed -i 's!^User www-data!User asterisk!' /etc/apache2/apache2.conf sed -i 's!^Group www-data!Group asterisk!' /etc/apache2/apache2.conf echo "Change Apache directive" cd /etc/apache2/sites-enabled/ sed '12s/AllowOverride None/AllowOverride All/g' 000-default > 000-default.tmp mv 000-default.tmp 000-default echo "Restart Apache2" /etc/init.d/apache2 restart echo "Apache2 re-started" #------------------------------------------------------------------ # # Installing Asterisk # #------------------------------------------------------------------ echo "Install Asterisk" cd /usr/src/asterisk-1.4.18 ASTERISK_CONFIGURE=$(2>&1 ./configure) if [ $? -ne 0 ] then # ./configure had problems. echo 1>&2 $0: "$ASTERISK_CONFIGURE" Exiting. exit 1 else echo "Successfully configured Asterisk Makefile" fi echo "Make and install Asterisk" Asterisk_MAKE=$(2>&1 make && make install) if [ $? -ne 0 ] then # ./make and make install had problems. echo 1>&2 $0: "$Asterisk_MAKE" Exiting. exit 1 else echo "Asterisk was successfully installed" fi echo "Install Asterisk-Samples" Asterisk_Samples=$(2>&1 make samples) if [ $? -ne 0 ] then # ./make and make install had problems. echo 1>&2 $0: "$Asterisk_Samples" Exiting. exit 1 else echo "Asterisk-Samples successfully installed" fi #------------------------------------------------------------------ # # Installing Asterisk-Addons # #------------------------------------------------------------------ echo "Install Asterisk-Addons" cd /usr/src/asterisk-addons-1.4.6 Asterisk_Addons_CONFIGURE=$(2>&1 ./configure) if [ $? -ne 0 ] then # ./configure had problems. echo 1>&2 $0: "$Asterisk_Addons_CONFIGURE" Exiting. exit 1 else echo "Successfully configured Asterisk_Addons Makefile" fi Asterisk_Addons=$(2>&1 make && make install) if [ $? -ne 0 ] then # ./make and make install had problems. echo 1>&2 $0: "$Asterisk_Addons" Exiting. exit 1 else echo "Asterisk-Addons successfully installed" fi make samples #------------------------------------------------------------------ # # Prepare MySQL # #------------------------------------------------------------------ echo "Install MySQL DB" /usr/bin/mysql_install_db echo "Restart MySQL" /etc/init.d/mysql restart echo "Set MySQL root user password to 002006 " mysqladmin -u root password '002006' echo "Create asteriscdrdb" echo "Enter the MySQL root password" mysqladmin create asteriskcdrdb -h localhost -u root -p'002006' echo "Create CDR tables in asteriskcdrdb database" mysql --user=root --password=002006 asteriskcdrdb < /usr/src/freepbx-2.4.0/SQL/cdr_mysql_table.sql echo "Enter the MySQL root password" mysqladmin create asterisk -h localhost -u root -p'002006' echo "Create asterisk tables in asterisk database" mysql --user root --password=002006 asterisk < /usr/src/freepbx-2.4.0/SQL/newinstall.sql mysql -h localhost -u root -p'002006' mysql --execute="GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';" mysql -h localhost -u root -p'002006' mysql --execute="GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';" #------------------------------------------------------------------ # # Change asterisk.conf # #------------------------------------------------------------------ echo "Change Asterisk Run Directory" cd /etc/asterisk/ sed '8s/var\/run/var\/run\/asterisk/g' asterisk.conf > asterisk.tmp mv asterisk.tmp asterisk.conf #------------------------------------------------------------------ # # Install FreePBX # #------------------------------------------------------------------ asterisk cd /usr/src/freepbx-2.4.0 ./install_amp cd /etc chown asterisk:asterisk amportal.conf amportal restart chmod 755 -R /var/www/html ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3 #------------------------------------------------------------------ # # Install phpMYAdmin # #------------------------------------------------------------------ echo "Install phpMyAdmin" phpmyadmin=$(2>&1 apt-get install -y phpmyadmin) if [ $? -ne 0 ] then echo 1>&2 $0: "$phpmyadmin" Exiting. exit 1 else echo "phpMyAdmin successfully installed" fi cd /etc/phpmyadmin/ sed '39a\$cfg['blowfish_secret'] ="asterisk";' config.inc.php > config.inc.tmp mv config.inc.tmp config.inc.php #------------------------------------------------------------------ # # Install Webmin # #------------------------------------------------------------------ echo "Install Webmin" cd /usr/src/ webmin=$(2>&1 dpkg -i webmin_1.380_all.deb) if [ $? -ne 0 ] then echo 1>&2 $0: "$webmin" Exiting. exit 1 else echo "Webmin successfully installed" fi #------------------------------------------------------------------ # # Install Munin # #------------------------------------------------------------------ echo "Install Munin" munin=$(2>&1 apt-get install -y munin munin-node) if [ $? -ne 0 ] then echo 1>&2 $0: "$munin" Exiting. exit 1 else echo "Munin successfully installed" fi #------------------------------------------------------------------ # # Install phpSysInfo # #------------------------------------------------------------------ cd /usr/src tar -xzvf phpsysinfo-2.5.4.tar.gz cp -R phpsysinfo /var/www/ cd /var/www chmod 755 -R phpsysinfo cd phpsysinfo cp config.php.new config.php echo "PHPSysInfo successfully installed" #------------------------------------------------------------------ # # Install Simple Administration Page # #------------------------------------------------------------------ cd /usr/src/ tar -xzvf asterisk_menu_intuit.tar.gz cp -R asterisk /var/www/ cd /etc/apache2/sites-enabled/ sed '17c\ RedirectMatch ^/$ /asterisk/' 000-default > 000-default.tmp mv 000-default.tmp 000-default /etc/init.d/apache2 restart #------------------------------------------------------------------ # # Configure Zaptel / ZTDUMMY # #------------------------------------------------------------------ echo "Configuring ZTDUMMY" rm /etc/default/zaptel cd /usr/src/ cp zaptel /etc/default/ modprobe zaptel modprobe ztdummy ztcfg -vvvv ztcfg cd /etc/init.d/ update-rc.d zaptel defaults echo "ZTDUMMY successfully configured" ip=$(ifconfig | grep --after-context=1 "eth0 " | grep inet | cut -d: -f2 | cut -f1 -d' ') # Start AMPORTAL on boot-time" echo '#!/bin/bash' > /etc/init.d/amportal-start chmod +x /etc/init.d/amportal-start update-rc.d amportal-start start 99 2 3 4 5 . echo '/usr/local/sbin/amportal start' >> /etc/init.d/amportal-start echo "-----------------------------------------------------------------------" echo "" echo " Done! You installed a complete Asterisk system." echo "" echo " You can access your system by simply key in http://$ip" echo " into your browser" echo "" echo "------------------------------------------------------------------------"