#! /bin/bash

bi_src_base=/opt
bi_crosstools_inst_dir=$bi_src_base/toolchains
bi_this_dir=`pwd`

clear
echo ""
echo "This script installs BCM963xx WiMAX router components onto your Linux PC.  The"
echo "installation will overwrite existing files.  You will be prompted before a"
echo "component is installed."
echo ""
echo "This script may create directories and overwrite existing files.  Therefore,"
echo "you will need to have root privilages to run this script."
echo ""
read -p "Press 'y' to continue: " -n 1 dr_continue
echo ""
if [ "$dr_continue" != "y" ] ; then
    echo "";
    echo "exiting script";
    echo "";
    exit
fi

for f in *
do
    case $f in
    bcm963*_consumer.tar.gz)
        bi_src_dir=$bi_src_base/bcm963xx_router
        echo ""
        echo "The bcm963xx WiMAX router source files are ready to be installed at "
        echo "$bi_src_dir. Existing source files, in any, will be overwritten. "
        echo ""
        read -p "Press 'y' to install the bcm963xx WiMAX router source files: " -n 1 dr_continue
        echo ""
        echo ""
        if [ "$dr_continue" == "y" ] ; then
            echo ""
            if ! [ -d $bi_src_dir ] ; then
                echo "Creating directory $bi_src_dir."
                echo ""
                mkdir -p $bi_src_dir
            fi
            if [ -d $bi_src_dir ] ; then
                echo "Installing files from $bi_this_dir/$f."
                echo ""
                cd $bi_src_dir
                tar xfz $bi_this_dir/$f
                chmod -R 777 * .*
            else
                echo "The directory $bi_src_dir does not exist."
                echo "The BCM963xx WiMAX router source files were not installed."
            fi
        else
            echo "The BCM963xx WiMAX router source files were not installed."
        fi
        echo ""
        ;;
    bcm963*_uclibc_crosstools*.tar.gz)
        echo ""
        echo "The BCM963xx WiMAX router toolchain is ready to be installed at $bi_crosstools_inst_dir."
        echo "Existing toolchain files, if any, will be overwritten."
        echo ""
        read -p "Press 'y' to install the BCM963xx toolchain: " -n 1 dr_continue
        echo ""
        echo ""
        if [ "$dr_continue" == "y" ] ; then
            echo ""
            if ! [ -d $bi_src_base ] ; then
                echo "Creating directory $bi_src_base."
                echo ""
                mkdir -p $bi_src_base
            fi
            if [ -d $bi_src_base ] ; then
                echo "Installing files from $bi_this_dir/$f."
                echo ""
                #cd $bi_this_dir
                #tar xfzv $f
                #rpm -ivh uclibc-crosstools*.rpm
                cd $bi_src_base
                tar xfzv $bi_this_dir/$f
            else
                echo "The directory $bi_src_base does not exist."
                echo "The BCM963xx toolchain was not installed."
            fi
        else
            echo "The BCM963xx toolchain was not installed."
        fi
        echo ""
        ;;
    esac
done

cd $bi_this_dir

