#!/bin/sh
# 
# inisqueak -- setup a directory for use with Squeak
# 
# @copyright@
# 
# Author: Ian.Piumarta@INRIA.Fr
# 
# Last edited: 2002-06-08 19:05:50 by piumarta on emilia.inria.fr

MAJOR=3
VERSION=3.2-4956

prefix=/opt/squeak
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
imgdir=${prefix}
plgdir=${exec_prefix}/lib

echo "Installing Squeak${VERSION} in `pwd`"

if test "$1" != ""; then
  bindir=${1}/${bindir}
  imgdir=${1}/${imgdir}
  plgdir=${1}/${plgdir}
fi

SQUEAK=${bindir}/squeak

IMAGE=Squeak${VERSION}.image
CHANGES=Squeak${VERSION}.changes
SOURCES=SqueakV${MAJOR}.sources

# Sun's /bin/sh does not understand "test -e", but [/usr]/bin/test does
test="`which test`"

startup="yes"

if test ! -w .; then
  echo "You don't have write permission in this directory." >&2
  exit 1
fi

missing()
{
  echo "The file ${1} is missing." >&2
  echo "Please check your Squeak installation." >&2
  exit 1
}

if test ! -x ${SQUEAK}; then
  missing "${SQUEAK}"
fi

install()
{
  cpy="${1}"
  src="${2}"
  red="${3}"
  dst="${4}"
  if ${test} ! -e ${dst}; then
    if ${test} -e ${src}; then
      echo "+ ${cpy} ${src} ${red} ${dst}"
      eval    ${cpy} ${src} ${red} ${dst}
    else
      missing "${src}"
    fi
  else
    echo "${dst} is already present -- leaving it alone"
    startup="no"
  fi
}

install "ln -s"      "${imgdir}/${SOURCES}" " " "${SOURCES}"
install "cat" "${imgdir}/${IMAGE}" ">"  "squeak.image"
install "cat" "${imgdir}/${CHANGES}" ">" "squeak.changes"

echo "Running ${SQUEAK}"

exec ${SQUEAK}
