#!/bin/bash
#
# This shell script is used to install bluetooth/wlan drivers and applications, and configure some BlueZ services.
#
# 3DSP corporation
# 2008.11.18
#
#Check the current user is root or not.
if [ "$(whoami)" != 'root' ]; then
echo "You have no permission to run $0 as non-root user!!!"
exit 1
fi
#Check the linux version.
#VERSUPPORT=("2.6.16.21-0.8-smp" "2.6.18-8.el5" "2.6.21-1.3194.fc7" "2.6.25-14.fc9.i686" "2.6.24-16-generic" "2.6.24-19-generic" "2.6.24-23-generic" "2.6.24-24-generic" "2.6.27-7-generic")
VERSUPPORT=("2.6.24-16-generic" "2.6.24-19-generic" "2.6.24-23-generic" "2.6.24-24-generic")
IFSUPPORT=FALSE
VERSION=`uname -r`
for((i=0;i<${#VERSUPPORT
do
if [ ${VERSION} = ${VERSUPPORT[$i]} ]; then
IFSUPPORT=TRUE
break
fi
done
if [ ${IFSUPPORT} = "FALSE" ]; then
echo "3DSP drivers does not support linux ${VERSION} version now!!!"
exit 1
fi
if [ -d applications ]; then
cd applications
if [ ! -e /usr/bin/blueman ]; then
echo "Start to install blueman application..."
sudo dpkg -i python-dbus_0.83.0-1_i386.deb
sudo dpkg -i python-bluez_0.14-1ubuntu1_i386.deb
sudo dpkg -i blueman_0.5-0ubuntu1_i386.deb
sudo cp -f toolbar.py /usr/lib/python2.5/site-packages/blueman/Gui/; sudo chmod 644 /usr/lib/python2.5/site-packages/blueman/Gui/toolbar.py
fi
if [ -e 3dsp-wifi-radar.tar.gz ]; then
echo "Start to install wifi-radar application..."
tar zxvf 3dsp-wifi-radar.tar.gz
cd 3dsp-wifi-radar
sudo make install
cp -f wifi-radar.desktop /usr/share/applications/
cd ..
rm -rf 3dsp-wifi-radar
fi
cd ..
fi
echo "Start to install 3DSP BT/WLAN drivers......"
#Install 3dsp drivers
[ -d drivers ] || mkdir drivers
[ -d wbtool ] || mkdir wbtool
[ -d drivers/${VERSION} ] || mkdir drivers/${VERSION}
if [ "$1" = "1" ]; then
if [ -d linux_bus_driver ]; then
cd linux_bus_driver; make clean; make; cp -f 3dspbus.ko ../drivers/${VERSION}/; cp -f tdspbus.conf ../wbtool/; cd ..
fi
if [ -d linux_bt_driver ]; then
cd linux_bt_driver; make clean; make; cp -f 3dspbt.ko ../drivers/${VERSION}/; cp -f btcfg.sh ../wbtool/; cd ..
fi
if [ -d linux_wlan_driver ]; then
cd linux_wlan_driver; . env.sh; make clean; make; cp -f 3dspwlan.ko ../drivers/${VERSION}/; cd ..
fi
if [ -d wbcmdtool ]; then
cd wbcmdtool; make clean; make; cp -f wbtool ../wbtool/; cp -f wb.conf ../wbtool/; cd ..
fi
if [ -d wbgui ]; then
cd wbgui; sh autogen.sh; make; cp -f src/wb ../wbtool/; cp -f wb.conf ../wbtool/; cp -f 3dspWB.png ../wbtool/; cp -f 3dspWB.desktop ../wbtool/; cd ..
fi
if [ -d linux_ma ]; then
cd linux_ma; make clean; make; cp -f tdsppcima ../wbtool/; cp -f tdsppcima.desktop ../wbtool/; cd ..
fi
if [ -d linux_drivers_update ]; then
cd linux_drivers_update; cp -f wb-pre ../wbtool/; cp -f wbdriverupdate.bin ../wbtool/; cd ..
fi
fi
sudo insmod drivers/${VERSION}/3dspbus.ko
echo "install bt driver..."; sudo sleep 1
sudo insmod drivers/${VERSION}/3dspbt.ko
echo "install wlan driver..."; sudo sleep 1
sudo insmod drivers/${VERSION}/3dspwlan.ko
sudo sleep 1
sudo mknod /dev/tdspbus c `cat /proc/devices | grep 3dspbus | sed 's/ 3dsp.*$//g'` 0
TDSPDIR="/usr/local/3DSP"
[ -d ${TDSPDIR} ] || mkdir ${TDSPDIR}
cd wbtool
cp -f tdspbus.conf ${TDSPDIR}; chmod 666 ${TDSPDIR}/tdspbus.conf
cp -f btcfg.sh ${TDSPDIR}; chmod 444 ${TDSPDIR}/btcfg.sh
cp -f wb.conf ${TDSPDIR}; chmod 666 ${TDSPDIR}/wb.conf
cp -f 3dspWB.desktop /usr/share/applications/
cp -f 3dspWB.png /usr/share/pixmaps/
cp -f tdsppcima.desktop /etc/xdg/autostart/
cp -f tdsppcima /usr/bin/; chmod 755 /usr/bin/tdsppcima
cp -f wbtool /usr/bin/; chmod 755 /usr/bin/wbtool
cp -f wb /usr/bin/; chmod 755 /usr/bin/wb
cp -f wb-pre /usr/bin/; chmod 755 /usr/bin/wb-pre
cp -f wbdriverupdate.bin /usr/bin/; chmod 755 /usr/bin/wbdriverupdate.bin
cd ..
cp -f drivers/${VERSION}/3dspbus.ko ${TDSPDIR}; chmod 644 ${TDSPDIR}/3dspbus.ko
cp -f drivers/${VERSION}/3dspbt.ko ${TDSPDIR}; chmod 644 ${TDSPDIR}/3dspbt.ko
cp -f drivers/${VERSION}/3dspwlan.ko ${TDSPDIR}; chmod 644 ${TDSPDIR}/3dspwlan.ko
#make /etc/init.d/tdspdriver and ln for auto-startup
echo "make file /etc/init.d/tdspdriver..."
echo "#!/bin/bash" > /etc/init.d/tdspdriver
echo "#" >> /etc/init.d/tdspdriver
echo " " >> /etc/init.d/tdspdriver
echo "insmod ${TDSPDIR}/3dspbus.ko" >> /etc/init.d/tdspdriver
echo "sleep 1" >> /etc/init.d/tdspdriver
echo "insmod ${TDSPDIR}/3dspbt.ko" >> /etc/init.d/tdspdriver
echo "sleep 1" >> /etc/init.d/tdspdriver
echo "insmod ${TDSPDIR}/3dspwlan.ko" >> /etc/init.d/tdspdriver
echo "sleep 1" >> /etc/init.d/tdspdriver
echo "mknod /dev/tdspbus c \`cat /proc/devices | grep 3dspbus | sed 's/ 3dsp.*$//g'\` 0" >> /etc/init.d/tdspdriver
chmod 755 /etc/init.d/tdspdriver
ln -sf ../init.d/tdspdriver /etc/rc2.d/S98tdspdriver
ln -sf ../init.d/tdspdriver /etc/rc3.d/S98tdspdriver
ln -sf ../init.d/tdspdriver /etc/rc4.d/S98tdspdriver
ln -sf ../init.d/tdspdriver /etc/rc5.d/S98tdspdriver
echo "3DSP BT/WLAN drivers have been installed, please check......"