#!/bin/sh
# $Revision: 1.4 $
# Sun Packaging Request script for Media Manager
INSTALL_VM_DIR="/opt"
OLD_VM_LEVEL=0
# Prepend /usr/5bin to PATH on Suns to get System V behaviour from echo.
PATH=/usr/5bin:$PATH
test_yn ()
{
case $1 in
  Y*|y*) return 0 ;;
  *)	return 1 ;;
esac
}
exit_err=0
DIR=""
VM_DIR=/usr/openv/volmgr
if [ -f ${VM_DIR}/version ] ; then
  OLD_VM_LEVEL=`tail +2 ${VM_DIR}/version | head -1 | cut -f4 -d" "`
  echo "
      Media Manager is currently installed at release level $OLD_VM_LEVEL.
      This package will install release level $VERSION."
  ans=`ckyorn -d y \
  -p "\tDo you want to reinstall Media Manager? (y)" ` || exit $?
  test_yn $ans
  if [ $? = 1 ] ; then
    exit_err=3
  else
    if [ -h /usr/openv ] ; then
      HEREIAM=`pwd`
      cd /usr/openv
      DIR=`pwd`
      cd ${HEREIAM}
      INSTALL_VM_DIR=`dirname ${DIR}`
      echo "\n\n\tMedia Manager is currently installed in ${INSTALL_VM_DIR}."
      echo "\tThe new binaries will be reinstalled there.\n\n"
    else
      echo "\n\n\tA directory /usr/openv already exists."
      echo "\tPlease move this to a location other than /usr"
      echo "\t and create a soft-link from /usr/openv,"
      echo "\tbefore you attempt to reinstall.\n\n"
      exit_err=3
    fi # if linked else directory
  fi # if no reinstall, else yes reinstall 
else
  if [ -h /usr/openv ] || [ -d /usr/openv ] ; then
    HEREIAM=`pwd`
    cd /usr/openv
    DIR=`pwd`
    cd ${HEREIAM}
    INSTALL_VM_DIR=`dirname ${DIR}`
    echo "\n\n\tAn openv directory was found in $INSTALL_VM_DIR."
    echo "\tMedia Manager will be installed in $INSTALL_VM_DIR/openv/volmgr,"
    ans=`ckyorn -d y \
        -p "\tis this okay? (y)"` || exit $?
    test_yn $ans
    if [ $? = 1 ] ; then
      exit_err=1
      echo "\n\n\tThere can only be one soft-link from /usr/openv"
      echo "\tInstallation can not continue.\n\n"
    fi
  fi
fi # volmgr/version exists

if [ $exit_err -eq 0 ] && [ "X${DIR}" = "X" ] ; then
  ans=`ckyorn -d y -p "\tDefault location is /opt/openv/volmgr, is this okay? (y)"` || exit $?
  test_yn $ans
  if [ $? = 1 ] ; then
    INSTALL_VM_DIR=`ckpath -aoy \
    -p "\tWhere do you want the ./openv/volmgr directory?"` || exit $?

    HEREIAM=`pwd`
    cd ${INSTALL_VM_DIR}
    USER_DIR=`pwd`
    cd ${HEREIAM}

    if [ "${USER_DIR}" = "/usr" ] || [ "${USER_DIR}" = "/" ] ; then
      echo "\n\n\n\t Installation in /usr or /, is not allowed.\n\n"
      INSTALL_VM_DIR="/opt"
      exit_err=3
    fi
  fi 
fi 
#
# make parameters available to preinstall/postinstall scripts
cat > $1 <<!
INSTALL_VM_DIR='$INSTALL_VM_DIR'
BASEDIR='$INSTALL_VM_DIR'
OLD_VM_LEVEL='$OLD_VM_LEVEL'
!
exit $exit_err
