#!/bin/sh
# Script to demonstrate installing ESRI ArcView Gis
# Dan Kegel Feb '07
set -ex

# Edit these if you're not building from git
#WINESRC=$HOME/wine-git/
WINESRC=
#WINEPREFIXCREATE=${WINESRC}tools/wineprefixcreate
WINEPREFIXCREATE=wineprefixcreate

WINE=${WINESRC}wine
WINESERVER=wineserver

# Kill the existing wine installation just to be clean
$WINESERVER -k || true
rm -rf $HOME/.wine

# Download the app's prerequisites
test -f vc6redistsetup_enu.exe || wget http://download.microsoft.com/download/vc60pro/update/1/w9xnt4/en-us/vc6redistsetup_enu.exe

# Grab mfc42u.dll (should have been bundled with app)
if ! test -f vcredist.exe; then
   clear
   echo "** When the GUI comes up, tell it to install to c:\\foo !"
   sleep 2
   $WINE vc6redistsetup_enu.exe
   if ! test -f $HOME/.wine/drive_c/foo/vcredist.exe; then
      echo vcredist.exe not found
      exit 1
   fi
   cp $HOME/.wine/drive_c/foo/vcredist.exe .
fi
rm -rf tmp
mkdir tmp
cd tmp
cabextract ../vcredist.exe
cp mfc42u.dll ..
cd ..
$WINESERVER -k || true
rm -rf $HOME/.wine

# Fake IE per workaround in http://bugs.winehq.org/show_bug.cgi?id=3453
# needed to install arcview
$WINEPREFIXCREATE
$WINESERVER -k || true
cat >> $HOME/.wine/system.reg <<"_EOF_"

[Software\\Microsoft\\Internet Explorer]
"Version"="6.0.2900.2180"
_EOF_

# copy msvc42u.dll from the vc6 runtime package
mkdir -p ~/.wine/drive_c/windows/system32
cp mfc42u.dll ~/.wine/drive_c/windows/system32

# install the app
$WINE /media/cdrom/ESRI.exe


