#!/bin/sh

SF_MIRROR="superb-east.dl.sourceforge.net"
#SF_MIRROR="localhost"
#SF_MIRROR="deadinternet.org"
SF_LOC="sourceforge/mingw"

CWD=`pwd`

MINGW_VIRT="/mingw"
FSTAB="/etc/fstab"
FSTAB_CONFIG="c:/msys/mingw		/mingw"

FILES="binutils-2.17.50-20060716-1.tar.gz
gcc-core-3.4.5-20060117-1.tar.gz
gcc-g++-3.4.5-20060117-1.tar.gz
mingw-runtime-3.10.tar.gz
w32api-3.7.tar.gz"

echo "*** Status: Creating $MINGW_VIRT"
if [ -e $MINGW_VIRT ] 
then
    echo "!!! Warning: $MINGW_VIRT already exists"
else
    mkdir $MINGW_VIRT
    echo "*** Status: $MINGW_VIRT created"
fi
cd $MINGW_VIRT

echo ""

echo "*** Status: Downloading required MinGW files"
for file in $FILES
do
    echo "Downloading $file from $SF_MIRROR"
    if [ -e "./$file" ]
    then
        echo "!!! Warning: $file already exists, skipping..."
    else
        wget --quiet http://$SF_MIRROR/$SF_LOC/$file
    fi
done
echo "*** Status: Downloading complete"

echo ""

echo "*** Status: Configuring $FSTAB"
echo $FSTAB_CONFIG > $FSTAB
echo "*** Status: $FSTAB configuration complete"

echo ""

echo "*** Status: Extracting MinGW into $MINGW_VIRT, please be patient"
for file in $FILES
do
    echo "Extracting $file"
    tar zxf $file
done
echo "*** Status: Extraction complete"

echo ""

cd $CWD

echo "MinGW is now installed and integrated with MSYS"
echo "Please close this window and open another MSYS shell"
echo "After doing that, please download and run the script"
echo "./transana_ffmpeg.sh"
