#!/bin/sh

if test -z "$1"; then
  echo "Usage: install-bin <install-path> [bin-path]"
  exit 1
fi

if test -d $1; then
  echo -n "Warning directory $1 exists.  Overwrite? (y/n): "
  read overwrite
  if test $overwrite != y; then exit -1; fi
fi

mkdir $1

WD=`pwd`

cd $1

IDIR=`pwd`

gunzip -c $WD/bin.tar.gz | tar xf -

cat << --- > bin/aspell
#!/bin/sh
ASPELL_CONF="$ASPELL_CONF;conf-dir $IDIR/etc"
export ASPELL_CONF
exec $IDIR/bin/aspell.bin "\$@"
---

cat << --- > bin/run-with-aspell
#!/bin/sh
PATH=$IDIR:\$PATH
export PATH
exec \$@
---

chmod 755 bin/aspell bin/run-with-aspell

mkdir etc

cat << --- > etc/aspell.conf
data-dir $IDIR/data
dict-dir $IDIR/dict
---

echo "Aspell Installed in $IDIR. "

if test -n "$2"; then
  cp bin/aspell bin/run-with-aspell $2/
  chmod 755 $2/aspell $2/run-with-aspell	
  echo "Aspell binaries Installed in $2"
fi


