#! /bin/sh

function installfs() {
 if [ -e $FSDIR/$1 ] ; then
  if alert --warn "A version of '$1' is already installed -- Do you really want to replace it?" "NO!" "Yes, please" ; then
  alert "Filesystem will not be installed"
  return ; fi
 fi
  mv -f filesys/$1 $FSDIR
}

function install() {
 if alert "This will install the Psion 3 and 5 FileSystems -- Proceed?" NO OK ; then
  alert "Filesystems will not be installed"
  exit ; fi
 installfs psion5fs 
 installfs psion3fs 
 mv Install Uninstall
 alert "Put a link to the PsiONtrack app on the Desktop?" "No, thanks" OK ||
   ln -s -f $(pwd)/PsiONtrack ~/Desktop;
 alert "OK... Installation complete"
}

function remove() {
 if alert "Really uninstall the Psion FileSystems?" NO "Yes, please" ; then
	alert "Filesystems will not be removed"
  exit ; fi
  if [ -e filesys/psion5fs ] ; then rm -f $FSDIR/psion5fs
 	else mv $FSDIR/psion5fs filesys/
  fi
  if [ -e filesys/psion3fs ] ; then rm -f $FSDIR/psion3fs
 	else mv $FSDIR/psion3fs filesys/
  fi
 if [ -L ~/Desktop/PsiONtrack ] ; then rm ~/Desktop/PsiONtrack; fi
 mv Uninstall Install
 alert "Filesystems have been removed"
}

wdir=$(dirname "$0")
cd "$wdir"
FSDIR="/boot/home/config/add-ons/kernel/file_systems"
if [ $(basename "$0") = "Uninstall" ] ; then remove;
else install; fi

