#!/bin/sh
#
# MOBAC startscript
#
#---As mobac insists in having application, cache and data all at one single place,
#---we need to do some light-weight installation at program start time.
#---You can set the environment variable MOBAC_HOME to set a custom home for mobac:
mobacdir="${MOBAC_HOME:-$HOME/MOBAC}"
mkdir -vp "$mobacdir" || exit 1
cd "$mobacdir"
echo "Executing mobac in directory $mobacdir."
echo "You may change location by setting the environment variable MOBAC_HOME."
if [ -L "$mobacdir/Mobile_Atlas_Creator.jar" ]; then rm "$mobacdir/Mobile_Atlas_Creator.jar"; fi
cp -au "/usr/share/mobac/Mobile_Atlas_Creator.jar" .
ln -sf "/usr/share/mobac/sqlite-jdbc-3.16.1.jar" .
ln -sf "/usr/share/mobac/world.map" .
ln -sf "/usr/share/mobac/mobac.icns" .
ln -sf "/usr/share/mobac/README.HTM" .
#---We create a physical mapsources directory, so we can add custom entries if desired.
#---Content of the installation mapsources is symlinked to the user mapsources directory.
if [ ! -d "$mobacdir/mapsources" ]; then
  mkdir -p "$mobacdir/mapsources"
fi
if [ -d "$mobacdir/mapsources" -a ! -L "$mobacdir/mapsources" ]; then
  pushd "$mobacdir/mapsources" > /dev/null
  for item in "/usr/share/mobac/mapsources/"*; do
    ln -sf "$item" .
  done
  popd > /dev/null
fi

java -Xms64m -Xmx1024M -jar "$mobacdir/Mobile_Atlas_Creator.jar" "$@"
