#!/bin/bash
function Build() {
    echo Building...
    cd ${HOME}/tmw/mainline
    autoreconf -i
    ./configure --prefix=${HOME}/tmw/ --without-opengl
    make install
}

if [ -d ${HOME}/tmw/mainline ]; then
    echo Updating...
    cd ${HOME}/tmw/mainline
    if git pull | grep -q "Already up-to-date."; then
        echo Already up-to-date.
    else
        Build
    fi
else
    echo This is the first time your run this script. Installing dependancies...
    sudo apt-get install build-essential libcurl4-openssl-dev libguichan-dev libphysfs-dev libpng12-dev libpthread-stubs0-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-net1.2-dev libsdl-ttf2.0-dev libxml2-dev libtool zlib1g-dev gettext git-core autoconf automake cvs
    mkdir ${HOME}/tmw
    cd ${HOME}/tmw
    git clone git://gitorious.org/tmw/mainline.git mainline
    Build
fi
echo You will now want to run ${HOME}/tmw/bin/tmw

