#!/bin/bash

SVN_URL="http://opengnsys.es/svn"
[ -z $SVN_DIR] && SVN_DIR="/tmp/opengnsys-svn"

[ -z $PREFIX ] && PREFIX="/"

for dir in \
    "$PREFIX"\
    "$PREFIX/opt"\
    "$PREFIX/opt/opengnsys"\
    "$PREFIX/opt/opengnsys/bin"\
    "$PREFIX/opt/opengnsys/etc" \
    "$PREFIX/opt/opengnsys/etc/init" \
    "$PREFIX/opt/opengnsys/lib"
do
    [ -d "$dir" ] || (mkdir -p $dir && echo "Creating dir: $dir")
done

if [ ! -d $SVN_DIR ]
then
    echo "Getting the new engine"
    svn export -q $SVN_URL/branches/version2 $SVN_DIR
else
    echo "Updating engine"
    cd $SVN_DIR
    svn update -q
    cd "$OLDPWD"
fi

echo "Copying browser"
cp -rf $SVN_DIR/browser/bin/browser $PREFIX/opt/opengnsys/bin
cp -rf $SVN_DIR/browser/init/tty1.conf $PREFIX/opt/opengnsys/etc/init
cp -rf $SVN_DIR/browser/fonts $PREFIX/opt/opengnsys/lib
mkdir -p $PREFIX/usr/local/QtEmbedded-4.6.3/lib
ln -s $PREFIX/opt/opengnsys/lib/fonts $PREFIX/usr/local/QtEmbedded-4.6.3/lib/fonts
