#!/bin/bash
# Script  created by
# Romeo-Adrian Cioaba romeo.cioaba@spotonearth.com
# Super minor updates by jason.melton[at]gmail[dot]com
# Updates by Alejandro Cuervo 3[at]cuervo[dot]net
# Released under GPL
# 
# Updated on Oct. 14, 2009 by Digimer (Madison Kelly, mkelly@alteeve.ca)
# - Found and copied getlibs-all.deb to the AN!Wiki as the old link was dead.
# - Added pause and warned the user to close their browser before kill -9'ing.
# - Added an initial check to see if the effective UID is 0 and removed 'sudo'
#   calls.
# - Added the -y switch to the ia32-libs and nspluginwrapper install line.
# - Removed the 'cd ~' because I'd rather all downloaded files stay in the
#   execution directory.
#

# Checking if the user has (effective) root access.
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run via 'sudo' as the 'root' user." 1>&2
   exit 1
fi

echo "Please close Firefox. Pressing any key will continue the install which"
echo "will kill any left over running firefox proceses!"
echo ""
echo "Press the <enter> key when ready."
read $GO

killall -9 firefox
echo "Any Firefox instances have been closed."

echo "Downloading and instaling Getlibs for required libraries"
wget http://wiki.alteeve.ca/local/x86_flash/getlibs-all.deb
dpkg -i getlibs-all.deb

echo "Removing previous installs of flash:"
apt-get remove -y --purge flashplugin-nonfree gnash gnash-common mozilla-plugin-gnash swfdec-mozilla libflashsupport nspluginwrapper
rm -f /usr/lib/mozilla/plugins/*flash*
rm -f ~/.mozilla/plugins/*flash*
rm -f /usr/lib/firefox/plugins/*flash*
rm -f /usr/lib/firefox-addons/plugins/*flash*
rm -rfd /usr/lib/nspluginwrapper

echo "Installing ia32-libs and nspluginwrapper"
apt-get -y install ia32-libs nspluginwrapper

echo "Getting libs"
getlibs -p libcurl3
getlibs -p libnss3-1d
getlibs -p libnspr4-0d

echo "Installing Flash Player 10"
wget http://wiki.alteeve.ca/local/x86_flash/install_flash_player_10_linux.tar.gz
tar zxvf install_flash_player_10_linux.tar.gz
mv libflashplayer.so /usr/lib/mozilla/plugins/
nspluginwrapper -i /usr/lib/mozilla/plugins/libflashplayer.so

echo "Linking the libraries so that firefox can see them."
ln -sf /usr/lib/nspluginwrapper/plugins/npwrapper.libflashplayer.so /usr/lib/mozilla/plugins/
ln -sf /usr/lib/nspluginwrapper/plugins/npwrapper.libflashplayer.so /usr/lib/firefox-addons/plugins/

echo "Done :-)"
echo "You may re-start Firefox now"


