#! /bin/bash

bi_this_dir=`pwd`
bi_src_base=$bi_this_dir
bi_crosstools_dir=/opt/toolchains/uclibc-crosstools-gcc-4.4.2-1


clear
echo ""
echo "This script installs BCM963xx DSL 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 ""
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 DSL 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 DSL 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 * .*
                cd $bi_this_dir
            else
                echo "The directory $bi_src_dir does not exist."
                echo "The BCM963xx DSL router source files were not installed."
            fi
        else
            echo "The BCM963xx DSL router source files were not installed."
        fi
        echo ""
        ;;
    uclibc-crosstools*.tar.bz2)
        echo ""
        echo "The BCM963xx DSL router toolchain is ready to be installed at $bi_crosstools_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 ""
            echo "Installing files from $bi_this_dir/$f."
            echo ""
            tar xPfj $bi_this_dir/$f
        else
            echo "The BCM963xx toolchain was not installed."
        fi
        echo ""
        ;;
    esac
done


