#!/bin/sh -e
## ----------------------------------------------------------------------
## debian/prerm : preremoval script
## ----------------------------------------------------------------------

## ----------------------------------------------------------------------
echo "pre removal $1 $2 $3"

if [ "5" != "5" ]; then 
  echo "Doing a pre-fremantle deinstallation"

  # determine path to use
  if [ "`mount | grep /media/mmc2`" != "" ]; then
    echo "MMC-PATH: mount /media/mmc2"
    MMC_PATH=/media/mmc2
  fi

  if [ "$MMC_PATH" != "" ]; then 
    # hide directory if we are working within a users home dir
    if [ "`echo $MMC_PATH | cut -d / -f-2`" == "/home" ]; then
      # .enigma may already be used by the app itself
      MMC_PATH=$MMC_PATH/.enigma-datadir
    else
      MMC_PATH=$MMC_PATH/enigma
    fi

    echo " memcard location: $MMC_PATH"

    if [ -x $MMC_PATH ]; then
      echo "Enigma data on $MMC_PATH, removing it"
      rm -r $MMC_PATH
    else
      echo "No enigma data on $MMC_PATH"
    fi
  else
    echo "No memcard path found!"
  fi
else
  echo "Doing a fremantle deinstallation"
fi

exit 0