#!/bin/bash #------------------------------------------------------------------- # V- 1.4.29 Update 29 by SanjayW 12:11am 22-01-10 (version update for asterisk, use FreePBX 2.6.0 ) # Asterisk Installation Script # # This script will automatically install: # Debian / Asterisk Dependencies # Asterisk 1.4.29 # Extra-Sounds English GSM # Addons 1.4.10 # Zaptel 1.4.12.1 # Libpri 1.4.10.2 # Freepbx-2.6.0 # mySQL to store CDR data # Webmin to administer your Debian # phpMyAdmin to administer your SQL server # phpsysinfo to generally see whats up # Munin for some performance graphs # Additional CLI tools # Enables SSL on Apache as default # ntp server and client # # This script was written by Dr. Daniel Ali Aman - Krahenbuhl/SanjayW # E-Mail: daniel@intuitinnovations.com/sanjay@intuitinnovations.com # # # MUST READ NOW!!! # THIS SCRIPT IS ONLY FOR FRESH BARE METAL DEBIAN 5 INSTALLS ONLY. # ================================================================ # * You need a running Debian 5 (minimal Netinstall) # * Working Internet connection # * Pls. don't run the script in /usr/src (anywhere else is fine) # * Based on your internet connection the installation will take 1-2 hours # * This script updates/upgrades all your packages if they aren't already # # Make sure you edit your sources.list (/etc/apt/sources.list) so your # system is able to download packages / dependencies from a debian mirror # Then update the list of available package with the apt-get update command. # # Now you can execute the script. # The script must be executable: # chmod +x asterisk1.4.2-A-install # ./asterisk1.4.2-A-install # # example # ./asterisk1.4.2-A-install passw0rd # # Installed cli tools # iftop # tcpdump # iptraf # ngrep # strace # ltrace # lsof # htop # sysstat # nmap # dstat # powertop #------------------------------------------------------------------- echo "Asterisk Installation Script" echo "check current run dir" echo "---------------------" currdir=`pwd` if [[ "$currdir" == "/usr/src" ]] ; then clear tput bel tput bel tput bel echo "Exiting" echo "-------" echo "Do not run this script in /usr/src" exit fi echo "Check if you enter password" echo "---------------------------" tmpvar=$1 mysqlpwd=$tmpvar if [[ "$mysqlpwd" == "" ]] ; then clear tput bel tput bel tput bel echo "Exiting" echo "-------" echo "No MySQL password given" echo "Usage #asterisk1.4.xx " echo "For password, DO NOT keyin special characters or use a openinverted commas or qoutes" echo "" echo "Example: ./asterisk.1.4.2 MySQLP" exit else DOWNLOAD_DIR1=http://210.5.42.12/downloads/asterisk DOWNLOAD_FILE1=asterisk-1.4.29.tar.gz DOWNLOAD_FILE2=asterisk-addons-1.4.10.tar.gz DOWNLOAD_FILE3=libpri-1.4.10.2.tar.gz DOWNLOAD_FILE4=zaptel-1.4.12.1.tar.gz DOWNLOAD_FILE5=freepbx-2.6.0.tar.gz DOWNLOAD_FILE6=lame-3.97.tar.gz DOWNLOAD_FILE9=phpsysinfo-2.5.4.tar.gz DOWNLOAD_FILE10=asterisk_menu_intuit.tar.gz DOWNLOAD_FILE12=asterisk-extra-sounds-en-gsm-current.tar.gz #----------------------------------------------------------------------- # # Install Dependencies and some cli tools # #----------------------------------------------------------------------- echo "Install Debian 5 Depenencies and Cli Tools" echo "This can take a while, depending on your internet connection" # Update and upgrade apt-get -y update apt-get -y update apt-get -y upgrade apt-get install --force-yes build-essential libxml2 libxml2-dev libtiff4 libtiff4-dev php5 php5-cli php5-mysql php5 php5-cli php5-mysql php5-gd 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 munin vim iftop tcpdump iptraf ngrep strace ltrace lsof htop sysstat nmap dstat powertop php5-cgi phpsysinfo ntpdate ntp ssh mpg123 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient15off libnet-daemon-perl libplrpc-perl libterm-readkey-perl mysql-client-5.0 mysql-common psmisc -y echo "All Depenencies and Tools Successfully Installed" # 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 FreePBX 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/ rm "$DOWNLOAD_FILE6" fi # Download Extra Sound Files cd /usr/src echo "Extra-Sound-Files download started" WGET_OUTPUT=$(2>&1 wget --progress=dot:mega \ "$DOWNLOAD_DIR1/$DOWNLOAD_FILE12") if [ $? -ne 0 ] then # wget had problems. echo 1>&2 $0: "$WGET_OUTPUT" Exiting. exit 1 else echo "Extra-Sound-Files are 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 1 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.12.1 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.10.2 LibPRI_MAKE=$(2>&1 make && make install) if [ $? -ne 0 ] then # ./make and make install had problems. 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 chown -R asterisk:asterisk /var/run/asterisk echo "Force Apache2 to run as the asterisk user" cd /etc/apache2 mv envvars envvars.old echo "export APACHE_RUN_USER=asterisk" >> envvars echo "export APACHE_RUN_GROUP=asterisk" >> envvars echo "export APACHE_PID_FILE=/var/run/apache2.pid" >> envvars chown -R asterisk:asterisk /var/lib/php5 /etc/init.d/apache2 restart #------------------------------------------------------------------ # # Installing Asterisk # #------------------------------------------------------------------ echo "Install Asterisk" cd /usr/src/asterisk-1.4.29 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.10 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 #------------------------------------------------------------------ # # Installing additional Asterisk sound files (GSM Format) # Needed for Conference, Login/Log-Off etc.... # #------------------------------------------------------------------ echo "Install additional Asterisk sound files" cd /usr/src cp asterisk-extra-sounds-en-gsm-current.tar.gz /var/lib/asterisk/sounds cd /var/lib/asterisk/sounds tar -xzvf asterisk-extra-sounds-en-gsm-current.tar.gz echo "Asterisk additional sound files are installed." #------------------------------------------------------------------ # # Install, configure MySQL and FreePBX's MySQL tables # #------------------------------------------------------------------ clear echo --------------------------------------------------------------------- echo Remember, MySQL password is the password you keyed in the script echo --------------------------------------------------------------------- # We install MySQL only now when we actually use it export DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server unset DEBIAN_FRONTEND /usr/bin/mysql_install_db mysqladmin -u root password $mysqlpwd # We get on the business of populating MySQL /etc/init.d/mysql restart echo --------------------------------------------------------------------- echo Remember, MySQL password is the password you keyed in the script echo --------------------------------------------------------------------- echo "Create asteriscdrdb" mysqladmin create asteriskcdrdb -h localhost -u root -p$mysqlpwd echo "Create CDR tables in asteriskcdrdb database" mysql -u root -p$mysqlpwd asteriskcdrdb < /usr/src/freepbx-2.6.0/SQL/cdr_mysql_table.sql echo "Enter the MySQL root password" mysqladmin create asterisk -h localhost -u root -p$mysqlpwd echo "Create asterisk tables in asterisk database" mysql -u root -p$mysqlpwd asterisk < /usr/src/freepbx-2.6.0/SQL/newinstall.sql mysql -h localhost -u root -p$mysqlpwd mysql --execute="GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';" mysql -h localhost -u root -p$mysqlpwd mysql --execute="GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';" #------------------------------------------------------------------ # # Setup phpmyadmin # #------------------------------------------------------------------ echo -------------------------------- echo PHPMyadmin Installation echo Select Apache2 and Apache SSL echo -------------------------------- tput bel tput bel export DEBIAN_FRONTEND=noninteractive apt-get install -y phpmyadmin unset DEBIAN_FRONTEND cp -r /usr/share/phpmyadmin/ /var/www/ chmod 775 /var/www/phpmyadmin/ chown -R asterisk:asterisk /var/www/phpmyadmin/ cd /etc/phpmyadmin/ sed '39a\$cfg['blowfish_secret'] ="asterisk";' config.inc.php > config.inc.tmp mv config.inc.tmp config.inc.php #------------------------------------------------------------------ # # Modify asterisk.conf to use FreePBX # #------------------------------------------------------------------ cp /etc/asterisk/asterisk.conf /etc/asterisk/asterisk.conf.orig sed -i "s/\(astrundir *=> *\)\(.*\)/\1\/var\/run\/asterisk/" /etc/asterisk/asterisk.conf #------------------------------------------------------------------ # # Install FreePBX # #------------------------------------------------------------------ # Start Asterisk /usr/sbin/asterisk # Pre configure some FreePBX related stuff cp /usr/src/freepbx-2.6.0/install_amp /usr/src/freepbx-2.6.0/install_amp-orig sed -i "s/\(^\$webroot*\)\(.*\)/\1 = \"\/var\/www\";/" /usr/src/freepbx-2.6.0/install_amp chmod 755 /usr/src/freepbx-2.6.0/install_amp # Pre configure amportal cp /usr/src/freepbx-2.6.0/amportal.conf /etc/amportal.conf chown asterisk:asterisk /etc/amportal.conf cd /etc/ #AMP DB Connection sed -i "s/# AMPDBUSER=asteriskuser/AMPDBUSER=asteriskuser/g" "/etc/amportal.conf" sed -i "s/# AMPDBPASS=amp109/AMPDBPASS=amp109/g" "/etc/amportal.conf" #Uncommenting below will disable FOP, default enabled #sed -i "s/FOPRUN=true/FOPRUN=false/g" "/etc/amportal.conf" #FOP PID setup sed -i "s/\/var\/run\/op_panel.pid/\/var\/run\/asterisk\/op_panel.pid/g" "/var/www/html/panel/op_server.pl" echo "AMPDBNAME=asterisk" >> amportal.conf echo "ASTETCDIR=/etc/asterisk" >> amportal.conf echo "ASTMODDIR=/usr/lib/asterisk/modules" >> amportal.conf echo "ASTVARLIBDIR=/var/lib/asterisk" >> amportal.conf echo "ASTAGIDIR=/var/lib/asterisk/agi-bin" >> amportal.conf echo "ASTSPOOLDIR=/var/spool/asterisk" >> amportal.conf echo "ASTRUNDIR=/var/run/asterisk" >> amportal.conf echo "ASTLOGDIR=/var/log/asterisk" >> amportal.conf echo "AMPDEVUSER=asterisk" >> amportal.conf echo "AMPDEVGROUP=asterisk" >> amportal.conf echo "AMPASTERISKUSER=asterisk" >> amportal.conf echo "AMPASTERISKGROUP=asterisk" >> amportal.conf echo "AUTHTYPE=database" >> amportal.conf echo "AMPASTERISKWEBUSER=asterisk" >> amportal.conf echo "AMPASTERISKWEBGROUP=asterisk" >> amportal.conf # To enable FreePBX related updates/upgrades chmod 775 /var/www/html/_asterisk/ cd /usr/src/freepbx-2.6.0 ./install_amp ./apply_conf.sh # MOH symbolic link ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3 # Log unique ID echo "loguniqueid=yes" >> /etc/asterisk/cdr_mysql.conf # Start FreePBX amportal restart #------------------------------------------------------------------ # # Install Webmin # #------------------------------------------------------------------ echo "Install Webmin" cd /usr/src/ wget http://210.5.42.12/downloads/asterisk/webmin_1.490_all.deb dpkg -i webmin_1.490_all.deb #------------------------------------------------------------------ # # Install Simple Administration Page # #------------------------------------------------------------------ cd /usr/src/ tar -xzvf asterisk_menu_intuit.tar.gz cp -R asterisk_menu_intuit/asterisk /var/www/ /etc/init.d/apache2 restart # 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/sbin/amportal start' >> /etc/init.d/amportal-start # Modify permissions # ================================== chown -R asterisk:asterisk /etc/asterisk chmod 770 /etc/asterisk/ chown -R asterisk:asterisk /var/lib/asterisk/ chmod 770 /var/lib/asterisk/ chown -R asterisk:asterisk /var/www/html chmod 755 -R /var/www/html # Copy some missing images cp /var/www/html/admin/modules/dashboard/images/notify_* /var/www/html/admin/images/ #Reinstate perms chown asterisk:asterisk -R /var/run/asterisk/ chown asterisk:asterisk -R /etc/asterisk chown asterisk:asterisk -R /var/lib/asterisk chown asterisk:asterisk -R /dev/zap chown asterisk:asterisk -R /var/log/asterisk chown asterisk:asterisk -R /var/spool/asterisk chown asterisk:asterisk -R /var/www/html chown asterisk:asterisk -R /var/www/html/panel #Php fix #======= cp /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini-orig sed -i "s/upload_max_filesize = 20M/upload_max_filesize = 120M/" /etc/php5/apache2/php.ini sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 120M/" /etc/php5/apache2/php.ini sed -i "s/magic_quotes_gpc = On/magic_quotes_gpc = Off/" /etc/php5/apache2/php.ini sed -i "s/memory_limit = 16M/memory_limit = 100M/" /etc/php5/apache2/php.ini sed -i "s/memory_limit = 32M/memory_limit = 100M/" /etc/php5/apache2/php.ini /etc/init.d/apache2 restart #Asterisk Process Priority #======================== sed -i "s/PRIORITY=0/PRIORITY=10/" /usr/sbin/safe_asterisk amportal stop # Make sure Asterisk is dead asteriskPID=$(cat /var/run/asterisk/asterisk.pid) kill -9 $(cat /var/run/asterisk/asterisk.pid) # Loading zaptel and ztdummy will automatically be used! amportal restart #----------------------------------------------------------------------- # # HTTPs it # #---------------------------------------------------------------------- # Get some values ip=$(ifconfig | grep --after-context=1 "eth0 " | grep inet | cut -d: -f2 | cut -f1 -d' ') echo Make sure the mods exist cd /etc/apache2 a2enmod ssl /etc/init.d/apache2 restart echo OK! clear echo Lets generate our certs and store them in a file cd /etc/apache2/ openssl genrsa -out server.key 1024 openssl req -new -key server.key -out server.csr -batch openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt cp server.crt /etc/ssl/certs/ cp server.key /etc/ssl/private/ echo OK echo Lets enable it on the default directory and get the default config cd /etc/apache2/sites-available cp default-ssl default-ssl.bak wget "http://210.5.42.12/downloads/asterisk/default-ssl.ssl" mv default-ssl.ssl default-ssl a2ensite default-ssl # Force listen on SSL only cd /etc/apache2 mv ports.conf ports.conf.old touch ports.conf echo "" >> ports.conf echo "Listen 443" >> ports.conf echo "" >> ports.conf # Ship out some leftovers cd /etc/apache2/sites-enabled/ mv 000-default* /usr/src/000-default # Fix FOP cd /var/www/html/panel/ ./op_server.pl -d # Restart Apache /etc/init.d/apache2 restart clear echo "---------------------------------------------------------------------" echo "Clear bash histories as the password got exposed" echo "---------------------------------------------------------------------" history -c tput bel echo "--------------------------------------------------------------------" echo "" echo " Done! You installed a complete Asterisk system." echo "" echo " You can access your system by simply key in https://$ip/asterisk" echo " into your browser" echo " MAKE SURE TO UPGRADE/UPDATE ALL YOUR FREEPBX MODULES AND CLICK APPLY" echo "--------------------------------------------------------------------" fi