#!/bin/sh
#
# Free Pascal installation script for Solaris
# Copyright 1996-2002 Michael Van Canneyt and Peter Vreman
#
# Don't edit this file. 
# Everything can be set when the script is run.
#

# Release Version
VERSION=2.6.0
FPCBIN=ppcx64
FPC_FULL_TARGET=x86_64-solaris

# some useful functions
# ask displays 1st parameter, and ask new value for variable, whose name is
# in the second parameter.
ask ()
{
askvar=$2
eval old=\$$askvar
eval echo -n \""$1 [$old] : "\" 
read $askvar
eval test -z \"\$$askvar\" && eval $askvar=\'$old\'
}
# yesno gives 1 on no, 0 on yes $1 gives text to display.
yesno ()
{
  while true; do
  echo -n "$1 (Y/n) ? "
  read ans
  case X$ans in
   X|Xy|XY) return 0;;
   Xn|XN) return 1;;
  esac
  done
}

# Untar files ($3,optional) from  file ($1) to the given directory ($2)
unztar ()
{
 gzip -d $HERE/$1.tar.gz
 gtar -xvf $HERE/$1.tar --directory $2 $3
}

# Make all the necessary directories to get $1
makedirhierarch ()
{
  OLDDIR=`pwd`
  case $1 in
    /*) cd /;;
  esac
  OLDIFS=$IFS;IFS=/;eval set $1; IFS=$OLDIFS
  for i
  do
    test -d $i || mkdir $i || break
    cd $i ||break
  done
  cd $OLDDIR
}

# check to see if something is in the path
checkpath ()
{
 ARG=$1
 OLDIFS=$IFS; IFS=":";eval set $PATH;IFS=$OLDIFS
 for i
 do
   if [ $i = $ARG ]; then
     return 0
   fi
 done 
 return 1
}

# --------------------------------------------------------------------------
# welcome message.
#

clear
echo "This shell script will attempt to install the Free Pascal Compiler"
echo "version $VERSION with the items you select"
echo 

# Here we start the thing.
HERE=`pwd`

# Install in /usr/local or /usr ?
if checkpath /usr/local/bin; then
    PREFIX=/usr/local
else
    PREFIX=/usr
fi
ask "Install prefix (/usr or /usr/local) " PREFIX
makedirhierarch $PREFIX

# Set some defaults.
LIBDIR=$PREFIX/lib/fpc
SRCDIR=$PREFIX/src/fpc
DOCDIR=$PREFIX/doc/fpc
DEMODIR=$DOCDIR/examples
EXECDIR=$PREFIX/bin

# Install compiler/RTL. Mandatory.
echo Unpacking ...
unztar fpc-$VERSION.$FPC_FULL_TARGET  $PREFIX
rm -f $EXECDIR/$FPCBIN
ln -sf $LIBDIR/$VERSION/$FPCBIN $EXECDIR/$FPCBIN
# rm -f *.tar.gz
echo Done.
echo

# Install /etc/fpc.cfg, this is done using the samplecfg script
$LIBDIR/$VERSION/samplecfg $LIBDIR/$VERSION

# The End
echo
echo End of installation. 
echo
echo Note: The installation file was not removed.
echo
echo Refer to the documentation for more information.
echo
