#!/bin/bash
#
#	Gmail's Voice and Video plugin script for ubuntu linux
# 	using Firefox 3 + Wine
#
#	Note: I'm not affiliated with Google
#	Author: Alex Eftimie
#	Date: 2009-01-15
#	Version: 0.1
#	Tutorial: http://alex.eftimie.ro/2008/11/18/howto-gmail-voice-and-video-chat-on-ubuntu-linux/
#

base_url="http://eftimie.ro/store/";
base_dir1="$HOME/.wine/drive_c/windows/profiles/$USER/Local Settings/Application Data/Google/Google Talk Plugin/"
base_dir2="$HOME/.wine/drive_c/windows/profiles/$USER/Application Data/Mozilla/plugins/";
ff_location="$HOME/.wine/drive_c/Program Files/Mozilla Firefox/firefox.exe"
ff_wine_loc="c:/Program Files/Mozilla Firefox/firefox.exe"

echo "This script will put in place the required files for Gmail Voice and Video plugin to work with Firefox installed in wine"
echo "Prior to this, you must install wine, firefox for windows and adobe flash player"

has_wine=`COLUMNS=250 dpkg --list | awk '/^ii/{print $2}' | grep ^wine$`
has_ff=`test -f "$ff_location" && echo ok`
#has_ff=`locate firefox.exe`

if [ "$has_wine" == "" ]
then
	echo "Error: Wine not found."
	echo "Type sudo apt-get install wine"
	exit -1
fi

if [ "$has_ff" == "" ]
then
	echo "Error: Firefox 3 for Windows not found."
	echo "You can download and install it from: http://www.mozilla.com/en-US/firefox/all.html"
	exit -2
fi

## Step 1: download files
wget $base_url"gmailvv.tar.gz" || ( echo "Error downloading file" && exit -2 )
# A little ping
wget $base_url"gvvping.php" 2> /dev/null

## Step 2: extracting
tar xf gmailvv.tar.gz

## Step 3: registry 
sed "s/alex/$USER/g" gmailvv/gmail.reg > temp.reg
wine regedit.exe temp.reg

# Step 4: dll's
mkdir -p "$base_dir1"
mkdir -p "$base_dir2"
cp gmailvv/google*.dll gmailvv/google*.exe "$base_dir1"
cp gmailvv/npgoogletalk.dll "$base_dir2"

# Step 5: done and cleanup
echo "Done!"
rm -rf temp.reg gmailvv gmailvv.tar.gz gvvping.php
wine "$ff_wine_loc" &
