#!/bin/sh
#
# IEs 4 Linux
# Developed by: Sergio Luis Lopes Junior <slopes at gmail dot com>
# Project site: http://tatanka.com.br/ies4linux
#
# Released under the GNU GPL. See LICENSE for more information

# Discover ies4linux installation folder
IES4LINUX=`dirname $0`
cd $IES4LINUX
IES4LINUX=`pwd` 
export IES4LINUX

# Create log file
# mkdir -p "$HOME"/.ies4linux
# touch "$HOME"/.ies4linux/log
# LOG="$HOME/.ies4linux/log"

# Instantiate variables
INSTALLIE6=1
INSTALLIE55=0
INSTALLIE5=0
INSTALLFLASH=1
CREATE_ICON=1
BASEDIR="$HOME/.ies4linux"
DOWNLOADDIR="$BASEDIR/downloads"
BINDIR="$HOME/bin"
WGETFLAGS="--continue"

IE6_LOCALE="EN-US"
IE6_LOCALES="EN-US PT-BR DE FR ES IT NL SV JA KO NO DA CN TW FI PL HU AR HE CS PT RU EL TR"

# Get some command-line options
while [ $# -gt 0 ]; do
	case "$1" in 
		--install-ie6 ) INSTALLIE6=1 ; shift ;;
		--install-ie55 ) INSTALLIE55=1 ; shift ;;
		--install-ie5 ) INSTALLIE5=1 ; shift ;;
		
		--basedir ) BASEDIR=$2 ; shift 2 ;;
		--bindir ) BINDIR=$2 ; shift 2 ;;
		--downloaddir ) DOWNLOADDIR=$2 ; shift 2 ;;
		
		--wget-flags ) WGETFLAGS=$2 ; shift 2 ;;
		* ) shift 1 ;;
	esac
done

# Basic imports
source lib/functions.sh
source lib/terminal.sh
source lib/messages.sh

# Check for wine and cabextract
wine --version &> /dev/null || error $MSG_ERROR_INSTALL_WINE
cabextract --version &> /dev/null || error $MSG_ERROR_INSTALL_CABEXTRACT
cabextract --version | grep "1." &> /dev/null || error $MSG_ERROR_UPDATE_CABEXTRACT
[ "$(whoami)" = "root" ] && warning $MSG_WARNING_ROOT

# Asks what user wants to install
initAndConfigure

# Prepare folders
DOWNLOADDIR="$BASEDIR/downloads"
mkdir -p "$BINDIR"
mkdir -p "$BASEDIR/tmp/"
rm -rf "$BASEDIR"/tmp/*
mkdir -p "$DOWNLOADDIR"
mkdir -p "$BINDIR"

# Copy svg icon
cp "$IES4LINUX/lib/ies4linux.svg" "$BASEDIR"

# Load modules
source "$IES4LINUX/lib/download.sh"
source "$IES4LINUX/lib/install.sh"

rm -rf "$BASEDIR/tmp"

# Last messages
section $MSG_INSTALLATIONS_FINISHED
echo

run_ies
echo

ask_for_translation


