#!/bin/sh

##################################################
#
#		This script is originally created to fix
#		flash-player for Mozilla Firefox at
#		Ubuntu amd64 systems.
#		
#		Written by: orrie <code@orrie.org>
#		Web: http://projects.orrie.org
#		Contact: http://www.orrie.no/contact/
#
##################################################

# create an install function for the newest version
function install-jaunty
{
	cd $HOME;
	if [ ! -d "script_temporary" ]; then
		mkdir script_temporary;
	fi
	cd script_temporary/;
	wget http://pub.orrie.org/ubuntu/packages/flashplayer/libflashplayer-10.0.22.87.linux-x86_64.so.tar.gz
	if [ -f "libflashplayer-10.0.22.87.linux-x86_64.so.tar.gz" ]; then
		tar -zxf libflashplayer-10.0.22.87.linux-x86_64.so.tar.gz;
	fi

	if [ ! -d "$HOME/.mozilla/plugins" ]; then
		mkdir "$HOME/.mozilla/plugins";
	fi

	mv libflashplayer.so $HOME/.mozilla/plugins/;
	cd $HOME;
	rm -rf $HOME/script_temporary/;

	if [ ! -f "$HOME/.mozilla/plugins/libflashplayer.so" ]; then
		echo	"An error has occurred.";
	else
		echo	"The flash-player for Firefox should now work.\nRestart your Firefox ;)\nIf any problems, report it on http://www.orrie.no\nPerhaps you get credits by reporting the fault ;)";
	fi
	exit
};

# create an install function for those versions that can use apt
function install-apt {
	sudo apt-get install flashplugin-nonfree
	echo	"The flash-player for Firefox should now work.\nRestart your Firefox ;)\nIf any problems, report it on http://www.orrie.no\nPerhaps you get credits by reporting the fault ;)"
	exit
};


# create an install function for the old versions
function install-old-versions {
	cd $HOME
	if [ ! -d "script_temporary" ]; then
		mkdir script_temporary
	fi
	cd script_temporary/
	wget http://pub.orrie.org/ubuntu/packages/nspluginwrapper/nspluginwrapper-1.2.2-1.x86_64.rpm
	wget http://pub.orrie.org/ubuntu/packages/nspluginwrapper/nspluginwrapper-i386-1.2.2-1.x86_64.rpm
	wget http://pub.orrie.org/ubuntu/packages/flashplayer/install_flash_player_10_linux.tar.gz
	if [ -f "install_flash_player_10_linux.tar.gz" && -f "nspluginwrapper-1.2.2-1.x86_64.rpm" && -f "nspluginwrapper-i386-1.2.2-1.x86_64.rpm" ]; then
		tar -zxf install_flash_player_10_linux.tar.gz
		sudo apt-get install ia32-libs lib32asound2 lib32ncurses5 ia32-libs-sdl ia32-libs-gtk gsfonts gsfonts-x11 linux32
		sudo apt-get install alien
		sudo ln -s /usr/lib/nspluginwrapper/x86_64/npconfig /usr/bin/nspluginwrapper
		sudo alien -d nspluginwrapper*.rpm
		sudo dpkg -i nspluginwrapper*.deb
		if [ ! -d "/usr/lib/mozilla/plugins32" ]; then
			sudo mkdir /usr/lib/mozilla/plugins32
		fi
		sudo mv	install_flash_player_10_linux/libflashplayer.so /usr/lib/mozilla/plugins32
		sudo nspluginwrapper -i /usr/lib/mozilla/plugins32/libflashplayer.so
		if ! -d "/usr/lib/mozilla-firefox" ]; then
			sudo mkdir /usr/lib/mozilla-firefox
		fi

		sudo ln -s /usr/lib/mozilla/plugins/npwrapper.so /usr/lib/mozilla-firefox/plugins/
		sudo ln -s /usr/lib/mozilla/plugins/npwrapper.libflashplayer.so /usr/lib/mozilla-firefox/plugins/

		if [ -d "install_flash_player_10_linux" ]; then
			sudo rm -R install_flash_player_10_linux
		fi

		if [ -d "install_flash_player_10_linux.tar.gz" ]; then
			sudo rm install_flash_player_10_linux.tar.gz
		fi

		if [ -n "`ls nspluginwrapper*`" ]; then
			sudo rm nspluginwrapper*
		fi

		cd $HOME
		if [ -d "script_temporary" ]; then
			rmdir script_temporary
		fi

		echo	"The flash-player for Firefox should now work.\nRestart your Firefox ;)\nIf any problems, report it on http://www.orrie.no\nPerhaps you get credits by reporting the fault ;)"
	else
		cd $HOME
		if [ -d "script_temporary" ]; then
			rmdir script_temporary
		fi
		echo	"An error has occured.\nReport your problem at http://www.orrie.no\nPerhaps you get credits by reporting the fault ;)/"
	fi
};

# karmic (9.10)
if [ -n "`cat /etc/*release | grep karmic`" ]; then
	echo	"This version (9.10 Karmic Koala) is not supported by this script yet."

# jaunty (9.04)
elif [ -n "`cat /etc/*release | grep jaunty`" ]; then
	install-jaunty

# intrepid (8.10)
elif [ -n "`cat /etc/*release | grep intrepid`" ]; then
	install-apt

# hardy (8.04)
elif [ -n "`cat /etc/*release | grep hardy`" ]; then
	install-apt

# gutsy (7.10)
elif [ -n "`cat /etc/*release | grep gutsy`" ]; then
	install-old-versions	

# feisty (7.04)
elif [ -n "`cat /etc/*release | grep feisty`" ]; then
	install-old-versions	

# edgy (6.10)
elif [ -n "`cat /etc/*release | grep edgy`" ]; then
	install-old-versions	

# dapper (6.04)
elif [ -n "`cat /etc/*release | grep dapper`" ]; then
	install-old-versions	

# breezy (5.10)
#elif [ -n "`cat /etc/*release | grep breezy`" ]; then
#	and so on..

# hoary (5.04)
#elif [ -n "`cat /etc/*release | grep hoary`" ]; then
#	and so on..

# warty (4.10)
#elif [ -n "`cat /etc/*release | grep warty`" ]; then
#	and so on..

else
	echo	"This is probably not Ubuntu.\nIf it is, report the error on http://www.orrie.no\nPerhaps you get credits by reporting the fault ;)/"
fi

