#!/bin/bash

ubuntu_version=`lsb_release -a 2>&1 | grep Release: | sed 's/\s\s*/ /' | sed 's/\.//g' | cut -f2 -d" "`

if [ "`uname -a | grep x86_64`" != "" ]; then

	#64bit install
	
	cd /tmp
	echo Get 3rd party tools
	wget http://www.hildoersystems.com/linux/packages/getlibs-all.deb
	sudo dpkg -i getlibs-all.deb
	rm -rf getlibs-all.deb
	echo '*********************'
	echo
	
	echo Removing existing flash installs
	sudo aptitude -y purge flashplugin-nonfree gnash gnash-common mozilla-plugin-gnash swfdec-mozilla libflashsupport nspluginwrapper 
	sudo rm -f /usr/lib/mozilla/plugins/*flash*
	sudo rm -rfd /usr/lib/nspluginwrapper
	sudo rm -f /usr/lib/firefox/plugins/*flash*
	sudo rm -f ~/.mozilla/plugins/*flash*
	sudo rm -f /usr/lib/firefox-addons/plugins/*flash*
	echo '*********************'
	echo
	
	echo Installing dependencies
	sudo aptitude -y install nspluginwrapper 
	sudo getlibs -y -p libcurl3
	sudo getlibs -y -p libnss3-1d
	sudo getlibs -y -p libnspr4-0d
	echo '*********************'
	echo
	
	echo Install Flash
	cd /tmp
	wget http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player_10_linux.tar.gz
	tar -xzf install_flash_player_10_linux.tar.gz
	if [ -f install_flash_player_10_linux/libflashplayer.so ]; then
		sudo cp install_flash_player_10_linux/libflashplayer.so /usr/lib/mozilla/plugins/
	fi 
	if [ -f libflashplayer.so ]; then
		sudo cp libflashplayer.so /usr/lib/mozilla/plugins/
	fi
	rm -rf /tmp/install_flash_player_10_linux/
	echo '*********************'
	echo
	
	echo Applying nspluginwrapper
	sudo nspluginwrapper -i /usr/lib/mozilla/plugins/libflashplayer.so
	echo '*********************'
	echo
	
	
	
	echo Link to plugins from firefox
	sudo ln -sf /usr/lib/nspluginwrapper/plugins/npwrapper.libflashplayer.so /usr/lib/mozilla/plugins/
	sudo ln -sf /usr/lib/nspluginwrapper/plugins/npwrapper.libflashplayer.so /usr/lib/firefox-addons/plugins/
	echo '*********************'
	echo

else 
	#32 bit install

	# try adobe first
	if [ $ubuntu_version -ge 804 ]; then
		wget http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player_10_linux.deb
		sudo dpkg -i install_flash_player_10_linux.deb
		rm -rf install_flash_player_10_linux.deb
	else 
		sudo aptitude -y install flashplugin-nonfree libflashsupport nspluginwrapper
	fi 
fi	

echo Close ALL firefox instances for changes to take effect.
echo '*********************'
echo
echo Done.


