#! /bin/bash

if [ $(whoami) = "root" ]
then
    thunderbirds are go
else 
  clear
  echo "                                                     "
  echo "$(logname) You must login this terminal as root su -."
  echo "                                                     "
  exit 1
fi

typeset -r YUM="`which yum`"
typeset -r RPM="`which rpm`"
typeset -r PERL="`which perl`"

DUMP_PATH="/temp"

WELCOME="1"

TOPL="-geometry 96x25+0+0"
TOPR="-geometry 96x25-0+0"

CHOICES="1 2 3 4 5 6 7 8 9"
	
function menu {
  clear
  echo -en "\033[0;40;32m"
  clear
  echo Hello $(logname) 
  echo "#################################DANGERMOUSE#################################"
  echo "###                     What would you like to do ?                       ###"
  echo "###    1) Abode Flash Plugin and Abode repository                         ###"
  echo "###    2) Drivers  all sorts (wireless,display,webcams,etc)               ###"
  echo "###    3) Abodereader                                                     ###"
  echo "###    4) Java 6u3                                                        ###"
  echo "###    5) Spare                                                           ###"
  echo "###    6) Limewire or Frostwire or RealPlayerGold10                       ###"
  echo "###    7) Personal                                                        ###"
  echo "###    8) Dvd playback + extra codecs / plugins                           ###"
  echo "###    9) Exits This Script                                               ###"
  echo "##################################DANGERMOUSE################################"
}

function dvd {
$RPM -Uvh http://rpm.livna.org/livna-release-7.rpm
$RPM -e --nodeps totem-plparser.x86_64  totem-plparser.i386 totem totem-mozplugin
$YUM -y install yum-protectbase
$PERL -i -pe "s/(\[.*\])/\1\nprotect=yes/" /etc/yum.repos.d/{fedora*,livna*}
$YUM -y install totem-xine totem-xine-plparser totem-xine-mozplugin gstreamer-plugins-bad gstreamer-plugins-bad-extras gstreamer-plugins-good gstreamer-plugins-ugly mozplugger mplayerplug-in nspliginwrapper
$YUM -y install libdvdcss xine*
wget www1.mplayerhq.hu/MPlayer/releases/codecs/all-20071007.tar.bz2
tar -jxvf all-20071007.tar.bz2
mkdir -p /usr/local/lib/codecs
cp all-20071007/* /usr/local/lib/codecs
ln -sf /usr/local/lib/codecs /usr/lib/codecs && ln -sf /usr/local/lib/codecs /usr/local/lib/win32 && ln -sf /usr/local/lib/codecs /usr/lib/win32
cd $DUMP_PATH
}

function abode {
$RPM -Uvh http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm
$YUM -y install flash-plugin 
cd $DUMP_PATH
}

function abodereader {
wget http://ardownload.adobe.com/pub/adobe/reader/unix/7x/7.0.9/enu/AdobeReader_enu-7.0.9-1.i386.rpm 
$RPM -Uvh --nodeps AdobeReader_enu-7.0.9-1.i386.rpm
cd $DUMP_PATH
}



function madwifi {
rm -rf /lib/modules/$(uname -r)/kernel/drivers/net/wireless/ath5k; depmod
xterm $TOPL  -bg "#000000" -fg "#99CCFF" -title "DOWNLOADING AND INSTALLING MADWIFI" -e "$YUM -y install gcc kernel-devel-$(uname -r) && wget http://www.freewebs.com/dnmouse/madwifi-0.9.3.2.tar.gz && tar -xvf /temp/madwifi-0.9.3.2.tar.gz && cd /temp/madwifi-0.9.3.2 && make && make install && modprobe ath_pci"
cd $DUMP_PATH
}

function wireless {
while true; do
  clear
  echo "###################################################################"
  echo "###           Select which wireless driver to install           ###"
  echo "###                                                             ###"
  echo "###   1) Broadcom 43xx      (recomend restart afterwards)       ###"
  echo "###   2) Madwifi/Atheros                                        ###"
  echo "###   3) Back to main menu                                      ###"
  echo "###################################################################"
  read yn
  case $yn in
    1 ) broadcom ; break ;;
    2 ) madwifi ; break ;;
    3 ) menu ; break ;;
    * ) echo "unknown response. Try again" ;;
  esac
done 
}

function nvidiafx {
$RPM -Uvh http://rpm.livna.org/livna-release-7.rpm
$YUM -y install yum-protectbase
$PERL -i -pe "s/(\[.*\])/\1\nprotect=yes/" /etc/yum.repos.d/{fedora*,livna*}
$YUM -y install kmod-nvidia xorg-x11-drv-nvidia-libs-32bit
cd $DUMP_PATH
}

function nvidiamx {
$RPM -Uvh http://rpm.livna.org/livna-release-7.rpm
$YUM -y install yum-protectbase
$PERL -i -pe "s/(\[.*\])/\1\nprotect=yes/" /etc/yum.repos.d/{fedora*,livna*}
$YUM -y install kmod-nvidia-96xx xorg-x11-drv-nvidia-96xx-libs-32bit
cd $DUMP_PATH
}

function personal {
while true; do
  clear
  echo -e '\E[31;40m'
  echo "####################################################################"
  echo "###     This is for personal use, use at your own risk !!!!!     ###"
  echo "###                                                              ###"
  echo "###   1) Repo's Livna,abode,freshrpms,protectbase                ###"
  echo "###   2) Install most programs i use                             ###"
  echo "###   3) Prism54                                                 ###"
  echo "###   4) rt61                                                    ###"
  echo "###   5) rt73                                                    ###"
  echo "###   6) Exit to main menu                                       ###"
  echo "###                                                              ###"
  echo "####################################################################"
  read yn
  case $yn in
    1 ) repos ; break ;;
    2 ) most  ; break ;;
    3 ) prism54  ; break ;;
    4 ) rt61 ; break ;;
    5 ) rt73 ; break ;;
    6 ) menu ; break ;;
    * ) echo "unknown response. Try again" ;;
  esac
done 
}

function java {
clear
$YUM -y install compat-libstdc++-33 compat-libstdc++-296
wget http://javadl.sun.com/webapps/download/AutoDL?BundleId=12790
sh jre-6u3*.bin
ln -sf "$(rpm -ql jre|grep plugin|grep ns7/|grep \\.so$)" /usr/lib/mozilla/plugins/libjavaplugin_oji.so & /usr/sbin/alternatives --install /usr/bin/java java $(rpm -ql jre | grep bin/java$) 2
xterm $TOPL  -bg "#000000" -fg "#99CCFF" -title "CHOOSE YOUR DEFAULT VERSION" -e /usr/sbin/alternatives --config java
cd $DUMP_PATH
}

function repos {
$RPM -Uvh http://rpm.livna.org/livna-release-7.rpm
$RPM -Uvh http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm
$RPM -Uvh http://ftp.freshrpms.net/pub/freshrpms/fedora/linux/7/freshrpms-release/freshrpms-release-1.1-1.fc.noarch.rpm
$YUM -y install yum-protectbase
$PERL -i -pe "s/(\[.*\])/\1\nprotect=yes/" /etc/yum.repos.d/{fedora*,livna*}
cd $DUMP_PATH
}

function most {
$YUM -y install streamtuner streamripper k3b-extras-nonfree  dvdstyler mencoder devede gdesklets gtweakui istanbul gnome-applet-netspeed dvdauthor ktorrent amule glunarclock nautilus-search-tool nautilus-open-terminal nautilus-image-converter unixODBC-devel gstreamer-plugins-good gstreamer-plugins-ugly gstreamer-plugins-bad unrar lame soundconverter vnc macchanger gdesklets vlc gdeskcal system-config-boot gwget firefox-32 audio-convert-mod
cd $DUMP_PATH
}

function cam {
clear
$YUM -y install gcc kernel-devel-$(uname -r) camstream
wget http://www.freewebs.com/dnmouse/gspcav1-20070110.tar.gz
wget http://www.freewebs.com/dnmouse/trunk.tar.gz
wget http://www.freewebs.com/dnmouse/sn9c1xx-1.48.tar.gz
tar -xvf sn9c1xx-1.48.tar.gz
tar -xvf trunk.tar.gz
tar -xvf gspcav1-20070110.tar.gz
cd gspcav1-20070110
make && make install
cd $DUMP_PATH
cd trunk
make && make install
cd $DUMP_PATH
cd sn9c1xx-1.48
make && make install
cd $DUMP_PATH
}

function mixed {
while true; do
  clear
  echo "###################################################################"
  echo "###                Select which one to install                  ###"
  echo "###   1) Limewire                                               ###"
  echo "###   2) Frostwire                                              ###"
  echo "###   3) RealPlayerGold10                                       ###"         
  echo "###   4) back to main menu                                      ###"
  echo "###################################################################"
  read yn
  case $yn in
    1 ) limewire ; break ;;
    2 ) frostwire ; break ;;
    3 ) realplayer ; break ;;
    4 ) menu ; break ;;
    * ) echo "unknown response. Try again" ;;
  esac
done 
}

function realplayer {
clear
$YUM -y install compat-libstdc++-33 compat-libstdc++-296 nspluginwrapper
wget http://www.real.com/realcom/R?href=http%3A%2F%2Fforms%2Ereal%2Ecom%2Freal%2Fplayer%2Fdownload%2Ehtml%3Ff%3Dunix%2FRealPlayer10GOLD%2Erpm
$RPM -Uvh RealPlayer10GOLD.rpm
mozilla-plugin-config
cd $DUMP_PATH
}

function limewire {
clear
$YUM -y install libXp compat-libstdc++-33 compat-libstdc++-296
wget http://www.limewire.com/LimeWireSoftLinux
$RPM -Uvh --nodeps LimeWireLinux.rpm
cd $DUMP_PATH
}

function frostwire {
clear
$YUM -y install libXp compat-libstdc++-33 compat-libstdc++-296
wget http://www.freewebs.com/dnmouse/frostwire-4.13.3.noarch.rpm
$RPM -Uvh --nodeps frostwire*.rpm
cd $DUMP_PATH
}

function rt61 {
$YUM -y install gcc kernel-devel-$(uname -r)
wget http://rt2x00.serialmonkey.com/rt61-cvs-daily.tar.gz
tar xvfz rt61-cvs-daily.tar.gz
cd rt61-cvs-*
cd Module
make
make install
modprobe rt73
cd $DUMP_PATH
}

function rt73 {
$YUM -y install gcc kernel-devel-$(uname -r)
wget http://rt2x00.serialmonkey.com/rt73-cvs-daily.tar.gz
tar xvfz rt73-cvs-daily.tar.gz
cd rt73-cvs-*
cd Module
make
make install
modprobe rt73
cd $DUMP_PATH
}

function prism54 {
$YUM -y install gcc kernel-devel-$(uname -r)
rmmod prism54
wget "http://svnweb.tuxfamily.org/dl.php?repname=prism54+%28prism54%29&path=%2Ftrunk%2F&rev=531&isdir=1" -O prism54_r531.tar.gz
wget http://patches.aircrack-ng.org/prism54-svn-20050724.patch
tar -xvzf prism54_r531.tar.gz
cd trunk
patch -Np1 -i ../prism54-svn-20050724.patch
make modules && make install
wget http://prism54.org/firmware/1.0.4.3.arm
mkdir -p /usr/lib/hotplug/firmware
mkdir -p /lib/firmware
cp 1.0.4.3.arm /usr/lib/hotplug/firmware/isl3890
mv 1.0.4.3.arm /lib/firmware/isl3890
depmod -a
modprobe prism54
cd $DUMP_PATH
}



function nvidia {
while true; do
  clear
  echo "###################################################################"
  echo "###           Select which driver to install                    ###"
  echo "###                                                             ###"
  echo "###   1) Nvidia FX          (recomend restart afterwards)       ###"
  echo "###   2) Nvidia MX          (recomend restart afterwards)       ###"
  echo "###   3) Back to main menu                                      ###"
  echo "###################################################################"
  read yn
  case $yn in
    1 ) nvidiafx ; break ;;
    2 ) nvidiamx ; break ;;
    3 ) menu ; break ;;
    * ) echo "unknown response. Try again" ;;
  esac
done 
}

function drivers {
while true; do
  clear
  echo "###################################################################"
  echo "###           Select which driver to install                    ###"
  echo "###                                                             ###"
  echo "###   1) Nvidia  graphics drivers                               ###"
  echo "###   2) Wireless drivers                                       ###"
  echo "###   3) Webcam drivers                                         ###"
  echo "###   4) Back to main menu                                      ###"
  echo "###################################################################"
  read yn
  case $yn in
    1 ) nvidia ; break ;;
    2 ) wireless ; break ;;
    3 ) cam ; break ;;
    4 ) menu ; break ;;
    * ) echo "unknown response. Try again" ;;
  esac
done 
}

function broadcom {
xterm $TOPL  -bg "#000000" -fg "#99CCFF" -title "INSTALLING BROADCOM 43xx DRIVER" -e "$YUM -y install b43-fwcutter --nogpgcheck && wget http://www.freewebs.com/dnmouse/broadcom-wl-4.80.53.0.tar.bz2 && tar xvf /temp/broadcom-wl-4.80.53.0.tar.bz2 && cd /temp/broadcom* && cd /temp/broadcom*/kmod && /usr/bin/b43-fwcutter -w /lib/firmware wl_apsta.o"
cd $DUMP_PATH
}

function message {
if [ $WELCOME = 1 ]
	then
echo  Hello $(logname) 
echo "W E L C O M E   T O   M Y  S C R I P T"
echo    "T H I S  I S  F O R  F 7  O N L Y"
echo             "By Dangermouse"
echo        "www.freewebs.com/dnmouse/"
sleep 5
	else
		echo "no welcome msg for you" 
fi
}
	
        clear
        message
	mkdir $DUMP_PATH
	cd $DUMP_PATH
	menu	
select choix in $CHOICES; do					
	if [ "$choix" = "1" ]; then
	abode
	menu			
	elif [ "$choix" = "2" ]; then
	drivers
	menu					
	elif [ "$choix" = "3" ]; then
	menu
        menu
        elif [ "$choix" = "4" ]; then
	java
        menu
        elif [ "$choix" = "5" ]; then
	menu
        menu
        elif [ "$choix" = "6" ]; then
	mixed
        menu
        elif [ "$choix" = "7" ]; then
	personal
        menu
        elif [ "$choix" = "8" ]; then
	dvd
	menu	
	elif [ "$choix" = "9" ]; then
        echo -e "\033[0m"
        clear
	echo Script terminated good bye $(logname) 
        exit 		
	else
	clear
	menu
        echo "################################################################"
        echo "###               Try again wrong number                     ###"
	fi
done
#END
