#!/bin/bash # This is a shell script to automatically check out and build a # FreePBX image to run on the WARP. It will do all the work to # check out the code required. Once the script is run, you should # have a working set of images to burn to your WARP that have working # FreePBX in it. # # Note that this script must be run in the root of a checked out pads # # # Declare variables we need BASE_DIR=`pwd` PADS_SVN_VERSION="2.0.14.5" BUILD_DIR="$BASE_DIR/$PADS_SVN_VERSION" FREEPBX_PACKAGE_DIR="$BASE_DIR/packages" PREBUILD_FILE="prebuild_steps.sh" # Set filenames for protection against multiple runs VERIFY_COMPLETE="$BASE_DIR/.verify_complete" BUILD_QUESTIONS="$BUILD_DIR/.build_questions" # Set variables for database passwords DEFAULT_SQL_PASSWORD="amp109" NEW_SQL_PASSWORD="amp109" # Check out a stock version of pads if not already done if [[ ( ! -d $BUILD_DIR ) ]]; then svn export http://svn.pikatech.com/pads/distro/tags/$PADS_SVN_VERSION $BUILD_DIR # Copy the prebuild file into the checkout cp $PREBUILD_FILE $BUILD_DIR fi # # Check if the build directory is already there. In this case # they have already answered questions so do not ask again. # if [[ ( ! -d $BUILD_DIR ) ]]; then # # Certain aspects of building PADS require you to be the root user # so we check it. # if [ $USER = "root" ]; then echo "" else echo "" echo "!!!!! WARNING !!!!!" echo "You must be root to compile PADS and FreePBX! If you have used the su" echo "command to become root you may already be root or if you used sudo you" echo "may have root privileges. If you are not root, you will get errors in" echo "running this script. Do you wish to continue (Y/n)" read choice if [[ ( "$choice" == "n" ) || ( "$choice" == "N" ) ]]; then echo "Exiting. Please rerun this script as root user or with sudo." exit 0 fi fi # Do verification of system to see if it has all the tools we need if [[ ( ! -f $VERIFY_COMPLETE ) ]]; then echo "The build of PADS and FreePBX requires several applications" echo "be installed on your computer. The stock PADS requires the" echo "items listed here: " echo "" echo "http://outgoingftp.pikatech.com/appliance/1.1/Docs/html/pads_user_guide/PADS_SystemSetup.html" echo "" echo "In addition to that, the FreePBX additions require several" echo "other items to be installed. We will now run a script to" echo "verify these items are installed." echo "" VERIFY_SYSTEM=`./verify_system.sh` echo "The result of testing your system for correct tools is:" echo "" echo "$VERIFY_SYSTEM" echo "" if [[ ! $VERIFY_SYSTEM = "SUCCESS" ]]; then echo "There appears to be missing components on your host build system." echo "It is recommended that you fix those issues before running this" echo "script again. These issues may have been detected in error. If" echo "you know these components to be installed please select Y below." echo "If your build fails, please refer to the listed errors for cause." echo "Do you wish to continue (Y/n)" read choice if [[ ( "$choice" == "n" ) || ( "$choice" == "N" ) ]]; then echo "Exiting. Please rerun this script after you have installed" echo "the required components listed above." exit 0 fi fi if [[ $VERIFY_SYSTEM = "SUCCESS" ]]; then touch $VERIFY_COMPLETE fi fi # Do a simple check we are in the base of a FreePBX checkout if [[ ( ! -d ./packages/freepbx ) ]]; then echo "We cannot detect being in base of a FreePBX checkout" echo "Do you want to try and continue (y/n)" read choice if [[ ( "$choice" == "n" ) || ( "$choice" == "N" ) ]]; then echo "Exiting. Please rerun script in the base of a FreePBX folder" exit 0 fi fi fi #################################################################### # Let's ask a few questions of users here to enable some automatic # enhancements of the FreePBX code #################################################################### if [[ ( ! -f $BUILD_QUESTIONS ) ]]; then echo "" echo "" echo "" echo "????????????????????????????????????????????????????????????" echo "" echo "FREEPBX ON WARP CUSTOMIZATION OPTIONS" echo "" echo "Some additional features can be added to the FreePBX build. " echo "Please answer the questions below. " echo "" echo "????????????????????????????????????????????????????????????" echo "" # Ask if they want to prep add extra modules to default FreePBX echo "" echo "Do you want the build to add some additional modules for FreePBX" echo "that are not included in the default image. The extra modules are" echo "conference, backup, manager, ivr and followme." echo "Do you want to enable this (Y/n) " echo "" read choice if [[ ( "$choice" == "n" ) || ( "$choice" == "N" ) ]]; then echo "NOT! Including additional modules for FreePBX!" else echo "Including additional modules for FreePBX!" sed -i "s|EXTRAFREEPBX=\"no\"|EXTRAFREEPBX=\"yes\"|" $BUILD_DIR/$PREBUILD_FILE fi echo "" # Ask if they want to prep for using the PIKA supplied # warpsystemtools module for FreePBX echo "" echo "Do you want the build to enable the custom PIKA warpsystemtools" echo "module for FreePBX. Doing this will change the permissions on a" echo "couple of previously root only writeable files so that the asterisk" echo "user can write to them. This is a small security risk to your system." echo "Do you want to enable this (Y/n) " echo "" read choice if [[ ( "$choice" == "n" ) || ( "$choice" == "N" ) ]]; then echo "NOT! enabling warpsystemtools module!" else echo "Enabled warpsystemtools module!" sed -i "s|WARPSYSTEMTOOLS=\"no\"|WARPSYSTEMTOOLS=\"yes\"|" $BUILD_DIR/$PREBUILD_FILE fi echo "" # Ask if they want to prep for using the PIKA supplied # warpfax module for FreePBX echo "" echo "Do you want the build to enable the custom PIKA warpfax module" echo "for FreePBX. This module will allow users to upload a file using" echo "the FreePBX GUI and have the phone system send it. " echo "Do you want to enable this (Y/n) " echo "" read choice if [[ ( "$choice" == "n" ) || ( "$choice" == "N" ) ]]; then echo "NOT! enabling warpfax module!" else echo "Enabled warpfax module!" sed -i "s|WARPFAX=\"no\"|WARPFAX=\"yes\"|" $BUILD_DIR/$PREBUILD_FILE # Ask if they want to enable the ability to convert pdf files to # tiff in the warpfax module for FreePBX echo "" echo "Do you want the custom PIKA warpfax module for FreePBX to have the" echo "ability to convert pdf files to tiff for faxing. This will allow " echo "users to upload a pdf file for faxing to the FreePBX GUI. Enabling" echo "this feature will consume an extra 18MB of space in the persistent" echo "partition so only enable this if you have space. An unmodified " echo "version of FreePBX for the WARP has plenty of room." echo "Do you want to enable this (Y/n) " echo "" read choice if [[ ( "$choice" == "n" ) || ( "$choice" == "N" ) ]]; then echo "NOT! enabling pdf to tiff for warpfax module!" else echo "Enabled pdf to tiff for warpfax module!" sed -i "s|TIFF2PDF=\"no\"|TIFF2PDF=\"yes\"|" $BUILD_DIR/$PREBUILD_FILE fi echo "" fi echo "" # Ask if they want to enable the script that automatically moves Files # to the SD card if there is one in the WARP echo "" echo "Do you want the build to enable the usage of the autorun file that" echo "automatically transfers files to the SD card if one is detected in " echo "the WARP when it starts (Y/n) " echo "" read choice if [[ ( "$choice" == "n" ) || ( "$choice" == "N" ) ]]; then echo "NOT! enabling sd card transfer mechanism!" else echo "Enabled sd card transfer mechanism!" sed -i "s|SDTRANSFER=\"no\"|SDTRANSFER=\"yes\"|" $BUILD_DIR/$PREBUILD_FILE fi echo "" # Ask if they want to enable the script that automatically converts # the translation (po and mo) files that are used in the FreePBX GUI echo "" echo "The FreePBX GUI has the ability to change the language it displays" echo "by selecting the drop down box in the top right. In order to enable" echo "this feature, on install, all the translation files need to be " echo "regenerated to work on PPC. This adds about 15 minutes to the initial" echo "start time of the WARP on first boot. If you do not need any language" echo "but English supported, select NO here, otherwise select YES." echo "Do you want the build to enable the regeneration of language " echo "translation files on the WARP when it starts (Y/n) " echo "" read choice if [[ ( "$choice" == "n" ) || ( "$choice" == "N" ) ]]; then echo "NO! language translation !!!" else echo "Enabled language translation mechanism!" sed -i "s|LANGUAGETRANSLATION=\"no\"|LANGUAGETRANSLATION=\"yes\"|" $BUILD_DIR/$PREBUILD_FILE fi echo "" # Ask if they want to change the default password for the MySQL # database used in the FreePBX GUI echo "" echo "The FreePBX GUI has a default password of \"amp109\" that is used" echo "to access both the GUI as \"asterisk\" user and for accessing the" echo "MySQL databases on the WARP. Please enter a new password here if you" echo "want to change that to something else. Hitting eneter will maintain" echo "the current default password. NOTE: You should not use characters in" echo "your paasword. Only letters and digits. If you select something else," echo "make sure you remember it. Password for databases (amp109) " echo "" read choice if [[ ( "$choice" == "" ) ]]; then echo "Current default database password of \"amp109\" used !!!" NEW_SQL_PASSWORD="amp109" else echo "Default database password changed to $choice" NEW_SQL_PASSWORD="$choice" fi echo "" # Ask if they want to add FOP2 echo "" echo "The FOP2 operator panel can be added to your image. Do you" echo "want the build to include it (y/N) " echo "" read choice if [[ ( "$choice" == "y" ) || ( "$choice" == "Y" ) ]]; then echo "Enabled FOP2!" sed -i "s|FOP2=\"no\"|FOP2=\"yes\"|" $BUILD_DIR/$PREBUILD_FILE else echo "FOP2 has NOT! been enabled !!!" fi echo "" # Ask if they want to add the nagios client echo "" echo "The nagois client can be added to your image. Do you want the build to" echo "include the nagios client (y/N) " echo "" read choice if [[ ( "$choice" == "y" ) || ( "$choice" == "Y" ) ]]; then echo "Enabled the nagios client!" sed -i "s|NAGIOS=\"no\"|NAGIOS=\"yes\"|" $BUILD_DIR/$PREBUILD_FILE else echo "The nagios client has NOT! been enabled !!!" fi echo "" # Already modified for questions touch $BUILD_QUESTIONS fi #################################################################### # End of enhancements of the FreePBX code question #################################################################### cd $BUILD_DIR # Build it if not already done if [[ ( ! -f $BUILD_DIR/images/uRamdisk ) ]]; then # See if menuconfig has been run already and don't do it again if [[ ( ! -f $BUILD_DIR/.config ) ]]; then patch -p0 < $FREEPBX_PACKAGE_DIR/patches/Makefile.patch make menuconfig fi make # Check if all packages made, if zoneinfo folder is there then # they did as it is last to be built, let's clean up & make images if [[ -d $BUILD_DIR/build_warp/zoneinfo-1.0.0 ]]; then # busybox has no man application so delete man pages rm -rf $BUILD_DIR/build_warp/root/usr/man rm -rf $BUILD_DIR/build_warp/root/usr/share/man rm -rf $BUILD_DIR/build_warp/root/usr/share/info rm -rf $BUILD_DIR/build_warp/root/usr/share/emacs rm -rf $BUILD_DIR/build_warp/root/usr/share/gtk-doc rm -rf $BUILD_DIR/build_warp/root/usr/share/doc rm -rf $BUILD_DIR/build_warp/root/usr/local/share/man # You could remove headers and other unnecessary runtime # files at this point if you wanted to # Change default password if requested if [[ ( "$NEW_SQL_PASSWORD" != "$DEFAULT_SQL_PASSWORD" ) ]]; then sed -i "s|amp109|$NEW_SQL_PASSWORD|" $BUILD_DIR/build_warp/root/persistent/etc/amportal.conf sed -i "s|amp109|$NEW_SQL_PASSWORD|" $BUILD_DIR/build_warp/root/persistent/autorun/S65freepbx sed -i "s|amp109|$NEW_SQL_PASSWORD|" $BUILD_DIR/build_warp/root/persistent2/usr/src/freepbx-2.5.1/create_mysql_freepbx.sh sed -i "s|amp109|$NEW_SQL_PASSWORD|" $BUILD_DIR/build_warp/root/persistent2/mysql/scripts/create_mysql_freepbx.sh sed -i "s|amp109|$NEW_SQL_PASSWORD|" $BUILD_DIR/build_warp/root/persistent2/mysql/scripts/chpaswd.sh fi # temporarily move the include folder before make image then restore it after # in case people want to build stuff again mv $BUILD_DIR/build_warp/root/usr/include $BUILD_DIR/ make image mv $BUILD_DIR/include $BUILD_DIR/build_warp/root/usr/ # Let's copy the autoflash burn file to images directory cp $FREEPBX_PACKAGE_DIR/patches/autoflash/autorun $BUILD_DIR/images/ fi fi # Output some final comments only if we think it succeeded in image creation if [[ ( -f $BUILD_DIR/images/uRamdisk ) ]]; then echo "" echo "You should now have a set of images that you can flash to your" echo "PIKA WARP appliance located in $BUILD_DIR/images." echo "To flash these images to your WARP, you can follow the" echo "instructions here:" echo "" echo "http://outgoingftp.pikatech.com/appliance/2.0/docs_2.0.6/html/pads_user_guide/PADS_BurningToFlash.html" echo "" echo "The FreePBX images use all three persistent partitions and all" echo "three of them must be flashed. For additional details on flashing" echo "persistent1 and persistent2, please read instructions here:" echo "" echo "http://outgoingftp.pikatech.com/appliance/2.0/docs_2.0.6/html/pads_user_guide/PADS_OtherPersistent.html" echo "" echo "Once you have flashed the partitions, you will need to reboot" echo "your WARP. On the first boot FreePBX will run some configuration" echo "and then reboot again. After this reboot your FreePBX WARP is" echo "ready to run." echo "" echo "If your WARP does not have access to the net and DNS servers you" echo "will not be able to update it." echo "" echo "Have fun and enjoy. If you have any issues please contact support at:" echo "support@pikatech.com" echo "" fi