#!/bin/sh
##############################################################################
# Configuration
##############################################################################
product="TomTom GO"
fstype="vfat"
fsdevs="ttsd mmcblk0 hda"
mntopt="rw,sync,exec,noatime,nodev,nosuid"
devbase="/dev"
sdmnt="/mnt/sdcard"
flashdir="/mnt/flash"
ttnapp="ttn"
ttndir="/bin"
ttpnpdapp="ttpnpd"
ttpnpddir="/bin"

#Change for GL gps receiver
gl_baudrate="115200"
gl_asic="/dev/gpsdata"
flash_gl=/mnt/flash/extra_settings

##############################################################################
# Functions
##############################################################################

start_clm() {
  # Determine whether we want to start up the CLM daemon
  if test "${hw_gpsephemeris}" = "1"; then
    if test -f /var/run/sirfreset.pid; then
      echo "* Waiting for application to finish..."
      wait $(cat /var/run/sirfreset.pid)
      echo "*  ...finished"
    fi
    # Check the clmdata file and copy to ramdisk
    if test -f /mnt/sdcard/clmdata; then
      cp /mnt/sdcard/clmdata /var/run/
      sync
    fi
    echo "* Starting clmapp"
    clmapp &
  fi
}

start_ttn() {
  if test "${hw_gldetected}" = "0"; then
    if test "${hw_gpsephemeris}" = "0" -a -f /var/run/sirfreset.pid; then
      echo "* Waiting for application to finish..."
      wait $(cat /var/run/sirfreset.pid)
      echo "*  ...finished"
    fi
  fi
  if test -f /etc/debug; then
    appdir=${ttndir}
    echo "* Starting ${appdir}/${ttnapp}"
    ${appdir}/${ttnapp} &
  else
    echo "* Starting ${product}"
    ${ttndir}/${ttnapp} </dev/null >/dev/null 2>&1 &
  fi
}

##############################################################################

# Launch ttMaps
if test -d /mnt/sdcard/ttMaps; then
	cd /mnt/sdcard/ttmaps/
	PROJ_LIB=/mnt/sdcard/ttMaps/proj GCONV_PATH=/mnt/sdcard/ttMaps LOCPATH=/mnt/sdcard/ttMaps /mnt/sdcard/ttMaps/ttmaps >>ttmaps.log 2>&1
else
	if test -d /mnt/movinand/ttMaps; then
		cd /mnt/movinand/ttMaps/
		PROJ_LIB=/mnt/movinand/ttMaps/proj GCONV_PATH=/mnt/movinand/ttMaps LOCPATH=/mnt/movinand/ttMaps /mnt/movinand/ttMaps/ttmaps >>ttmaps.log 2>&1
	fi
fi
if [ "$?" = 33 ] ; then
	ln -s /sbin/sysreboot /bin/poweroff
	/bin/poweroff
else
	start_ttn
fi
