#!/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 # # DIRECTORY paths BASE_DIR=`pwd` PADS_VERSION="1.2.0-67" PADS_SVN_VERSION="1.2.0.67" 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" # # 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" ) ]]; 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" ) ]]; 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" ) ]]; then echo "Exiting. Please rerun script in the base of a FreePBX folder" exit 0 fi fi # Check out a stock version of pads if not already done if [[ ( ! -d $BUILD_DIR ) ]]; then mkdir -p $BUILD_DIR svn co http://svn.pikatech.com/pads/distro/tags/$PADS_SVN_VERSION $BUILD_DIR fi # Copy the file that adds FreePBX to the stock PADS and modify with # the correct versions from this file. if [[ ( ! -f $BUILD_DIR/$PREBUILD_FILE ) ]]; then cp $PREBUILD_FILE $BUILD_DIR fi if [[ ( `cat $BUILD_DIR/$PREBUILD_FILE | grep "PADS_VERSION= " | grep $PADS_VERSION` ) ]]; then CURRENT_PADS_VERSION=`cat $BUILD_DIR/$PREBUILD_FILE | grep PADS_VERSION= | awk '/PADS_VERSION/ { print $2 }' | sed -e s/\"// | sed -e s/\"//` sed -i "s|$CURRENT_PADS_VERSION|$PADS_VERSION|" $BUILD_DIR/$PREBUILD_FILE sed -i "s|PADS_VERSION= |PADS_VERSION=|" $BUILD_DIR/$PREBUILD_FILE fi # Build it if not already done if [[ ( ! -f $BUILD_DIR/images/uRamdisk ) ]]; then cd $BUILD_DIR # See if menuconfig has been run already and don't do it again if [[ ( ! -f $BUILD_DIR/menuselect.makeopts ) ]]; 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/share/man rm -rf $BUILD_DIR/build_warp/root/usr/local/share/man make image 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/1.1/Docs/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/1.1/Docs/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