#!/bin/sh
# Copyright (C) 1996 The Santa Cruz Operation. All Rights Reserved.
# this script is designed to install VisionFS.
# $Id: setup.sh,v 1.24 1996/09/06 13:39:34 duncans Exp $

# This is a generic product script used to establish an environment
# before starting/stopping a product or component.
# This script was built from shell library
#   $Id: startup.shlib,v 10.46 1996/10/22 10:23:32 stevent Exp $
# This script has to run on every platform we support.  Any suggestions
# for improvement are welcome (but must be portable!)
# You can set an environment variable trace (NB lower case) to the value
# true to get a trace of actions.

# Version numbers
PRODUCT_VERSION="1.13"
PRODUCT_VERSION_FULL="1.13.901"
PRODUCT_VERSION_MAJOR=1
PRODUCT_VERSION_FEATURE=1
PRODUCT_VERSION_BUG=3
PRODUCT_VERSION_BUILD=901

# Product names
PRODUCT_FULL_NAME="SCO VisionFS"
PRODUCT_SHORT_NAME="VisionFS"
PRODUCT_LOCKD_NAME="SCO VisionFS Lock Daemon"
PRODUCT_COMPONENTS_NAME="VisionFS Architecture"


# be paranoid about the current path
if [ -d /bin ]; then
  PATH=/bin:$PATH
fi
if [ -d /sbin ]; then
  PATH=/sbin:$PATH
fi
if [ -d /usr/bin ]; then
  PATH=/usr/bin:$PATH
fi
if [ -d /usr/sbin ]; then
  PATH=/usr/sbin:$PATH
fi
if [ -d /etc ]; then
  PATH=/etc:$PATH
fi
export PATH

u="`LANG=C LC_ALL=C id | sed 's/.*uid=\([0-9][0-9]*\).*/\1/'`"
if [ $trace ]; then echo "      trace user id number is: $u" ; fi
if [ "$u" = "0" ]
then
  : # all is okay
else
  echo "!15! You must be root to run this program"
  exit 15
fi

hostname="`uname -n | sed 's@^\([^\.]*\).*@\1@'`"

N=""
C=""
if echo -n | grep n > /dev/null
then
  C="\c"
else
  N="-n"
fi


# This is a generic product script used to access the /etc/vision.inst file
# This script was built from shell library
#   $Id: install.shlib,v 10.5 1996/06/17 10:07:05 duncans Exp $

VISION_FILE=/etc/vision.inst


INST_PRODUCT=VISIONFS
INST_EXTENSION=vfs
INST_BINSPACE=6000
INST_DATASPACE=10000

## displayable strings

l_welcome="--------------------------------------------------------------------------
Welcome to SCO VisionFS $PRODUCT_VERSION Setup
--------------------------------------------------------------------------

VisionFS Setup has two stages: installing the VisionFS files, and
configuring the VisionFS server and your system to work together.

For each stage, Setup will suggest the best way to install and set up
VisionFS. You can accept the answers, or choose a custom installation.

--------------------------------------------------------------------------
"
p_license="
To use VisionFS you must agree to be bound by the terms of the
VisionFS Software License Agreement.
  Y - I have read, and accept the terms of the license agreement
  N - I do not accept the terms of the license agreement
  V - View the license agreement
"
l_license="Accept terms of VisionFS Software License Agreement"

l_createdir="[CREATE]"
l_deldir="[REPLACE]"
l_owdir="[OVERLAY]"
l_updir="[UPGRADE]"

l_mkdir="The directory doesn't exist, create it"
l_isafile="There is a file of that name in the way"
l_rmdir="Delete the existing directory first"
l_rmfile="Delete the file of that name first"
l_crdir="Directory doesn't exist, create it"

p_architecture="
--------------------------------------------------------------------------
WARNING: Unrecognized architecture
--------------------------------------------------------------------------
VisionFS Setup can't install VisionFS for your system, as the
distribution doesn't contain the correct files for this flavor of UNIX.

However, you can choose a version to install on this system, for example
if you know that your flavor of UNIX is binary compatible with one of
the supported VisionFS platforms.

Type one of the following 8-character codes to install that version:
"
l_architecture="Version to install"

p_gshared="
--------------------------------------------------------------------------
Vision Family shared directory
--------------------------------------------------------------------------
Type the name of the UNIX directory used for your Vision Family products.
"
l_gshared="Shared directory"

p_insttype="
--------------------------------------------------------------------------
Installation type
--------------------------------------------------------------------------
How would you like to install VisionFS?
  O - Overwrite existing version with this one
  P - Alongside existing version, with a new configuration
  C - Alongside existing version, with a copy of the old configuration
"
l_insttype="Installation type"
l_insttypeb="Updating VisionFS 1.1 Beta"
l_insttypeo="Overwriting existing version"
l_insttypen="New installation"
l_insttypep="Alongside, new configuration"
l_insttypec="Alongside, copying old configuration"
l_insttypex="Unknown"

p_instname="
--------------------------------------------------------------------------
Installation name
--------------------------------------------------------------------------
Type a short name to use for this installation.
"
l_instname="Installation name"

p_instdesc="
--------------------------------------------------------------------------
Installation description
--------------------------------------------------------------------------
Type a description for this installation, that identifies it
from other installations.
"
l_instdesc="Installation description"

p_instbin="
--------------------------------------------------------------------------
Binaries directory
--------------------------------------------------------------------------
Type the directory in which to install the main binaries.
Recommended disk space: ${INST_BINSPACE}K
"
l_instbin="Main installation directory"
l_recommended="Recommended disk space"
l_available="Available"
p_instetc="
--------------------------------------------------------------------------
Configuration directory
--------------------------------------------------------------------------
Type the directory to use for configuration files.

This directory should be on a disk local to this machine.
"
l_instetc="Configuration directory"

p_instdata="
--------------------------------------------------------------------------
Data directory
--------------------------------------------------------------------------
Type the directory to use for dynamic data files, such as print spools.
Recommended disk space: ${INST_DATASPACE}K
"
l_instdata="Data directory"

l_summary="
--------------------------------------------------------------------------
Installation - Summary
--------------------------------------------------------------------------
"

p_continue="Are these answers OK?
  Y - Yes, install now
  N - No, let me change the answers
  Q - Quit, making no changes"
l_continue="Install with above answers"
l_quit="
--------------------------------------------------------------------------
Quitting. No files have been installed. Your system is unaltered.
--------------------------------------------------------------------------
"
l_custom="
--------------------------------------------------------------------------
Custom installation
--------------------------------------------------------------------------

 - You can press [Ctrl]-C at any time to exit Setup without making
   any more changes.

 - For each question, press [Return] to accept the default answer,
   shown in [square brackets].

--------------------------------------------------------------------------
"

l_attemptstop="
There is a server running from a directory you are about to replace
or overlay.
Attempting to stop the server..."
l_install="
Setup is now installing the VisionFS files.
The next stage, configuring VisionFS to work with your system, will
start in a moment..."

lf_badarg="Invalid argument"
lf_notar="Unable to locate tar file for current architecture.
Try setting the SCOARCH environment variable to an architecture string."
lf_noarches="Unable to locate any platform dependent tar files"
lf_nolic="Unable to locate license file"
lf_nocd="Unable to cd to install location"
lf_shared="Failed to create top level shared directory"
lf_etcdir="Failed to create shared configuration directory"
lf_bindir="Failed to create shared bin directory"
lf_licencef="Failed to create shared license file"
lf_instbin="Failed to create installation's bin directory"
lf_tarfile="Failed to extract tar file"
lf_instetc="Failed to create installation's configuration directory"
lf_curetc="Failed to copy old installation's configuration directory"
lf_instdata="Failed to create installation's data directory"
lf_badexec="Failed to exec stage 2 setup script"
lf_noglobbin="Failed to retrieve global script from newly installed tree"
lf_badglobbin="Failed to install new script "

## parse the arguments

# defaults
pa_custom=false
#pa_licence=""

# what was passed through
while [ ! -z "$1" ]; do
  if [ "$1" = "--custom" ]; then
    pa_custom=true
  else
    echo "$0: $lf_badarg $1" 1>&2
    exit 1
  fi
  shift
done


## make sure they're licensed
if [ "$pa_custom" != "true" ]; then
  echo "$l_welcome"

  # force them to type in an answer
  c_license=""
if [ -z "$0" ]; then
  c_licfile=.
else
  c_licfile=`expr "$0/" : '\(/\)/*[^/]*//*$'  \| \
    "$0/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

  c_licfile=`ls $c_licfile/license* $c_licfile/LICENSE* 2>/dev/null`
  if [ ! -f "$c_licfile" ]; then
    echo "$0: $lf_nolic $c_licfile" 1>&2
    exit 2
  fi
  while [ -z "$c_license" ]; do
echo "$p_license"
_valid=false
while [ $_valid = false ]
do
  echo $N "$l_license [$c_license]? $C"
  read _answer
  if [ $trace ] ; then echo "	trace: answer read in is \"$_answer\"" ; fi
  if [ -z "$_answer" ]
  then
    _answer="$c_license"   # default
  fi
  case $_answer in [yYvVnN]) _valid=true;;esac
done
if [ $trace ] ; then echo "	trace: answer accepted is \"$_answer\"" ; fi
c_license="$_answer"

# the language can alter the behaviour of tr
c_license=`echo $c_license | LANG=C LC_ALL=C tr '[a-z]' '[A-Z]'`

    if [ "$c_license" = "N" ]; then
       echo "$l_quit"
       exit 0
    elif [ "$c_license" = "V" ]; then
pg="$PAGER"
if [ -z "$pg" ] ; then pg=more ; fi
$pg $c_licfile

       c_license=""
    fi
  done
fi


## work out the architecture
if [ -z "$0" ]; then
  cg_tardir=.
else
  cg_tardir=`expr "$0/" : '\(/\)/*[^/]*//*$'  \| \
    "$0/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi


# list of available architectures
# look for lowercase matches
cg_archlist=`(cd $cg_tardir;ls *.$INST_EXTENSION*) 2>/dev/null`
if [ -z "$cg_archlist" ]; then
  # check for uppercase matches
# the language can alter the behaviour of tr
_uext=`echo $INST_EXTENSION | LANG=C LC_ALL=C tr '[a-z]' '[A-Z]'`

  cg_archlist=`(cd $cg_tardir;ls *.$_uext*) 2>/dev/null`

  # lowercase the result
# the language can alter the behaviour of tr
cg_archlist=`echo $cg_archlist | LANG=C LC_ALL=C tr '[A-Z]' '[a-z]'`

fi

# remove the extension and extra characters
cg_archlist=`echo $cg_archlist | sed "s|\.$INST_EXTENSION[^ ]*||g"`


if [ -z "$cg_archlist" ]; then
 echo "$0: $lf_badarches"
 exit 0
fi

# the exe to display sensible OS string
cg_unarchexe=`ls $cg_tardir/unscarch* $cg_tardir/UNSCARCH* 2>/dev/null`

# If there's only one, assume it is correct
case $cg_archlist in
????????)
  cg_arch=$cg_archlist
  ;;
esac

if [ -z "$cg_arch" ]; then
  # check already existing SCOARCH environment
  if [ ! -z "$SCOARCH" ]; then
    for _i in $cg_archlist; do
      if [ "$_i" = "$SCOARCH" ]; then
        cg_arch=$SCOARCH
        break
      fi
    done
  fi

  # try scoarch
  if [ -z "$cg_arch" ]; then
    _archexe=`ls $cg_tardir/scoarch* $cg_tardir/SCOARCH* 2>/dev/null`
    if [ -x "$_archexe" ]; then
      cg_arch=`$_archexe $cg_archlist 2>/dev/null`
    fi
  fi
fi

if [ -z "$cg_arch" ]; then
  # make a pretty list of architectures
  if [ -z "$cg_unarchexe" ]; then
    p_architecture="$p_architecture  $cg_archlist"
  else
    for _i in $cg_archlist; do
      p_architecture="$p_architecture  $_i (`$cg_unarchexe $_i`)
"
    done
  fi

  # must have an architecture
echo "$p_architecture"
_valid=false
while [ $_valid = false ]
do
  echo $N "$l_architecture [$cg_arch]? $C"
  read _answer
  if [ $trace ] ; then echo "	trace: answer read in is \"$_answer\"" ; fi
  if [ -z "$_answer" ]
  then
    _answer="$cg_arch"   # default
  fi
  for _i in $cg_archlist;do if [ "$_i" = "$_answer" ]; then _valid=true; fi; done
done
if [ $trace ] ; then echo "	trace: answer accepted is \"$_answer\"" ; fi
cg_arch="$_answer"


  # set SCOARCH, this means they won't have to answer this again
  SCOARCH=$cg_arch
  export SCOARCH
fi
# lowercase attempts
cg_tarfile=$cg_arch
if [ -f $cg_tardir/$cg_tarfile.$INST_EXTENSION ]; then
  cg_tarfile=$cg_tardir/$cg_tarfile.$INST_EXTENSION
elif [ -f $cg_tardir/$cg_tarfile.$INST_EXTENSION\;1 ]; then
  cg_tarfile=$cg_tardir/$cg_tarfile.$INST_EXTENSION\;1
else
  # uppercase attempts
# the language can alter the behaviour of tr
cg_tarfile=`echo $cg_tarfile | LANG=C LC_ALL=C tr '[a-z]' '[A-Z]'`

  if [ -f $cg_tardir/$cg_tarfile.$_uext ]; then
    cg_tarfile=$cg_tardir/$cg_tarfile.$_uext
  elif [ -f $cg_tardir/$cg_tarfile.$_uext\;1 ]; then
    cg_tarfile=$cg_tardir/$cg_tarfile.$_uext\;1
  else
    # failed to find it
    cg_tarfile=""
  fi
fi



## shared bin and etc
if [ -f $VISION_FILE ]; then
	cg_bindir=`grep "VISION[_]BINDIR=" $VISION_FILE | sed -e "/^VISION[_]BINDIR=/s///"`
else
	cg_bindir=""
fi

if [ -z "$cg_bindir" ]; then
  ch_bindir=true
else
  ch_bindir=false
fi

# shared etc
if [ -f $VISION_FILE ]; then
	cg_etcdir=`grep "VISION[_]ETCDIR=" $VISION_FILE | sed -e "/^VISION[_]ETCDIR=/s///"`
else
	cg_etcdir=""
fi

if [ -z "$cg_etcdir" ]; then
  ch_etcdir=true
else
  ch_etcdir=false
fi

# only allow setting of both if unset
if [ "$ch_etcdir" = "true" -a "$ch_bindir" = "true" ]; then
  if [ -f /etc/vision.conf ]; then
    cg_shared=`grep VISION_DIR= /etc/vision.conf | sed -e "/VISION_DIR=/s///"`
  else
    cg_shared=""
  fi
  if [ -z "$cg_shared" ]; then
    # locate a default with enough space if possible
    cg_shared=/usr/local/vision
    if [ ! -d $cg_shared/vfsprofile ]; then
      cg_shared=""
    fi
    
    if [ -z "$cg_shared" ]; then
      cg_shared=/usr/local/vision
_path=$cg_shared
while [ ! -d "$_path" ]; do
if [ -z "$_path" ]; then
  _path=.
else
  _path=`expr "$_path/" : '\(/\)/*[^/]*//*$'  \| \
    "$_path/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

done
if [ -f /bin/pwd ]
then
 origdir=`/bin/pwd`
 cd "$_path"
 dir=`/bin/pwd`
else
 origdir=`pwd`
 cd "$_path"
 dir=`pwd`
fi
 
dirname=$dir
banana=`df -k  > /dev/null 2>&1`
if [  $? = 0 ]
then
 banana=`df -k | egrep [Aa]vail  > /dev/null 2>&1`
 if [ $? = 0 ]
 then
  # System V style output
  a_space=`df -k $dirname | egrep -v [Aa]vail  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
 else
  banana=`df -k | grep Free > /dev/null 2>&1`
  if [ $? = 0 ]
  then 
   # Aix style output
   a_space=`df -k $dirname | grep -v Free  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
  else
  banana=`df -k $dirname | grep "free allocated" > /dev/null 2>&1`
  if [ $? = 0 ]
  then
   # HPUX 10 verbosity
   a_space=`df -k $dirname | sed -n -e '
s/^[ 	]*\([0-9]*\)[ 	]*free allocated.*$/\1/p 
'`
  else
   ## SCO ???
   a_space=`df -k $dirname | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
   fi
  fi
 fi
else
 banana=`df $dirname > /dev/null 2>&1`
 if [  $? = 0  ]
 then
  # Sun OS style output
  a_space=`df  $dirname | egrep -v [Aa]vail  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
 if [ "x$%kytes%" = "x" ]
 then
   a_space=`df $dirname | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
  dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
  sz=`du -s $_path/._._._`
  sz=`expr "$sz" : '\([0-9]*\).*'`
  rm -f $_path/._._._
  case $sz in
   2*)
    a_space=`expr $a_space / $sz`
   ;;
   *)
   ;;
  esac
 fi
 else
  dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
  sz=`du -s $_path/._._._`
  sz=`expr "$sz" : '\([0-9]*\).*'`
  rm -f $_path/._._._
  while [ "$dirname" != "" ]
  do
  a_space=`df | egrep "^$dirname[ 	]*\(.*$" | sed -e '
{
s/^[^\)]*.:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
   if [ "$a_space" != "" -o "$dirname" = "/"  ]
   then
    break
   fi
   dirname=`dirname $dirname`
  done
  case $sz in
   2*)
    a_space=`expr $a_space / $sz`
   ;;
   *)
   ;;
  esac
 fi
fi
cd $origdir

      a_enough=`expr $a_space ">" $INST_BINSPACE + $INST_DATASPACE`
      if [ "$a_enough" = "0" ]; then
	cg_shared=""
      fi
    fi

    if [ -z "$cg_shared" ]; then
      cg_shared=/opt/vision
_path=$cg_shared
while [ ! -d "$_path" ]; do
if [ -z "$_path" ]; then
  _path=.
else
  _path=`expr "$_path/" : '\(/\)/*[^/]*//*$'  \| \
    "$_path/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

done
if [ -f /bin/pwd ]
then
 origdir=`/bin/pwd`
 cd "$_path"
 dir=`/bin/pwd`
else
 origdir=`pwd`
 cd "$_path"
 dir=`pwd`
fi
 
dirname=$dir
banana=`df -k  > /dev/null 2>&1`
if [  $? = 0 ]
then
 banana=`df -k | egrep [Aa]vail  > /dev/null 2>&1`
 if [ $? = 0 ]
 then
  # System V style output
  a_space=`df -k $dirname | egrep -v [Aa]vail  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
 else
  banana=`df -k | grep Free > /dev/null 2>&1`
  if [ $? = 0 ]
  then 
   # Aix style output
   a_space=`df -k $dirname | grep -v Free  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
  else
  banana=`df -k $dirname | grep "free allocated" > /dev/null 2>&1`
  if [ $? = 0 ]
  then
   # HPUX 10 verbosity
   a_space=`df -k $dirname | sed -n -e '
s/^[ 	]*\([0-9]*\)[ 	]*free allocated.*$/\1/p 
'`
  else
   ## SCO ???
   a_space=`df -k $dirname | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
   fi
  fi
 fi
else
 banana=`df $dirname > /dev/null 2>&1`
 if [  $? = 0  ]
 then
  # Sun OS style output
  a_space=`df  $dirname | egrep -v [Aa]vail  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
 if [ "x$%kytes%" = "x" ]
 then
   a_space=`df $dirname | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
  dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
  sz=`du -s $_path/._._._`
  sz=`expr "$sz" : '\([0-9]*\).*'`
  rm -f $_path/._._._
  case $sz in
   2*)
    a_space=`expr $a_space / $sz`
   ;;
   *)
   ;;
  esac
 fi
 else
  dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
  sz=`du -s $_path/._._._`
  sz=`expr "$sz" : '\([0-9]*\).*'`
  rm -f $_path/._._._
  while [ "$dirname" != "" ]
  do
  a_space=`df | egrep "^$dirname[ 	]*\(.*$" | sed -e '
{
s/^[^\)]*.:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
   if [ "$a_space" != "" -o "$dirname" = "/"  ]
   then
    break
   fi
   dirname=`dirname $dirname`
  done
  case $sz in
   2*)
    a_space=`expr $a_space / $sz`
   ;;
   *)
   ;;
  esac
 fi
fi
cd $origdir

      a_enough=`expr $a_space ">" $INST_BINSPACE + $INST_DATASPACE`
      if [ "$a_enough" = "0" ]; then
	cg_shared=""
      fi
    fi

    if [ -z "$cg_shared" ]; then
      cg_shared=/home/vision
_path=$cg_shared
while [ ! -d "$_path" ]; do
if [ -z "$_path" ]; then
  _path=.
else
  _path=`expr "$_path/" : '\(/\)/*[^/]*//*$'  \| \
    "$_path/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

done
if [ -f /bin/pwd ]
then
 origdir=`/bin/pwd`
 cd "$_path"
 dir=`/bin/pwd`
else
 origdir=`pwd`
 cd "$_path"
 dir=`pwd`
fi
 
dirname=$dir
banana=`df -k  > /dev/null 2>&1`
if [  $? = 0 ]
then
 banana=`df -k | egrep [Aa]vail  > /dev/null 2>&1`
 if [ $? = 0 ]
 then
  # System V style output
  a_space=`df -k $dirname | egrep -v [Aa]vail  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
 else
  banana=`df -k | grep Free > /dev/null 2>&1`
  if [ $? = 0 ]
  then 
   # Aix style output
   a_space=`df -k $dirname | grep -v Free  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
  else
  banana=`df -k $dirname | grep "free allocated" > /dev/null 2>&1`
  if [ $? = 0 ]
  then
   # HPUX 10 verbosity
   a_space=`df -k $dirname | sed -n -e '
s/^[ 	]*\([0-9]*\)[ 	]*free allocated.*$/\1/p 
'`
  else
   ## SCO ???
   a_space=`df -k $dirname | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
   fi
  fi
 fi
else
 banana=`df $dirname > /dev/null 2>&1`
 if [  $? = 0  ]
 then
  # Sun OS style output
  a_space=`df  $dirname | egrep -v [Aa]vail  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
 if [ "x$%kytes%" = "x" ]
 then
   a_space=`df $dirname | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
  dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
  sz=`du -s $_path/._._._`
  sz=`expr "$sz" : '\([0-9]*\).*'`
  rm -f $_path/._._._
  case $sz in
   2*)
    a_space=`expr $a_space / $sz`
   ;;
   *)
   ;;
  esac
 fi
 else
  dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
  sz=`du -s $_path/._._._`
  sz=`expr "$sz" : '\([0-9]*\).*'`
  rm -f $_path/._._._
  while [ "$dirname" != "" ]
  do
  a_space=`df | egrep "^$dirname[ 	]*\(.*$" | sed -e '
{
s/^[^\)]*.:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
   if [ "$a_space" != "" -o "$dirname" = "/"  ]
   then
    break
   fi
   dirname=`dirname $dirname`
  done
  case $sz in
   2*)
    a_space=`expr $a_space / $sz`
   ;;
   *)
   ;;
  esac
 fi
fi
cd $origdir

      a_enough=`expr $a_space ">" $INST_BINSPACE + $INST_DATASPACE`
      if [ "$a_enough" = "0" ]; then
	cg_shared=""
      fi
    fi

    if [ -z "$cg_shared" ]; then
      cg_shared=/usr/local/vision
    fi  
  fi
  cg_etcdir=$cg_shared/etc
  cg_bindir=$cg_shared/bin
  ch_shared=true
elif [ "$ch_etcdir" = "false" -a "$ch_bindir" = "true" ]; then
if [ -z "$cg_etcdir" ]; then
  cg_shared=.
else
  cg_shared=`expr "$cg_etcdir/" : '\(/\)/*[^/]*//*$'  \| \
    "$cg_etcdir/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

  cg_bindir=$cg_shared/bin
  ch_shared=false
elif [ "$ch_etcdir" = "true" -a "$ch_bindir" = "false" ]; then
if [ -z "$cg_bindir" ]; then
  cg_shared=.
else
  cg_shared=`expr "$cg_bindir/" : '\(/\)/*[^/]*//*$'  \| \
    "$cg_bindir/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

  cg_etcdir=$cg_shared/etc
  ch_shared=false
else
if [ -z "$cg_etcdir" ]; then
  cg_shared=.
else
  cg_shared=`expr "$cg_etcdir/" : '\(/\)/*[^/]*//*$'  \| \
    "$cg_etcdir/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

  ch_shared=false
fi

if [ "$pa_custom" = "true" ]; then
  # shared bin
  if [ "$ch_shared" = "true" ]; then
    a_mkdir="yes"
echo "$p_gshared"
_valid=false
while [ $_valid = false ]
do
  echo $N "$l_gshared [$cg_shared]? $C"
  read _dirname
  if [ $trace ] ; then echo "	trace: answer read in is \"$_dirname\"" ; fi
  if [ -z "$_dirname" ]
  then
    _dirname="$cg_shared"   # default
  fi
  if [ -f "$_dirname" ]
  then
    echo "$l_isafile"
  elif [ -d "$_dirname" ]
  then
    _valid=true
    a_mkdir="no"
  else
    _valid2=false
    while [ $_valid2 = false ]
    do
      echo $N "$l_mkdir [$a_mkdir]? $C"
      read _answer
      if [ $trace ] ; then echo "	trace: answer read in is \"$_answer\"" ; fi
      if [ -z "$_answer" ]
      then
        _answer="$a_mkdir"   # default
      fi
      case "$_answer" in
      [yY]*)
        a_mkdir=yes
        _valid2=true
        _valid=true
        ;;
      [nN]*)
        a_mkdir=no
        _valid2=true
      esac
    done
  fi
done
if [ $trace ] ; then echo "	trace: answer accepted is \"$_answer\"" ; fi
cg_shared="$_dirname"

    cg_etcdir=$cg_shared/etc
    cg_bindir=$cg_shared/bin
  fi
fi


## install type
if [ -f $VISION_FILE ]; then
	c_instname=`grep "$INST_PRODUCT[_]DEFAULT=" $VISION_FILE | sed -e "/^$INST_PRODUCT[_]DEFAULT=/s///"`
else
	c_instname=""
fi

if [ -z "$c_instname" ]; then
  if [ -d /usr/local/vision/visionfs -o -d $cg_shared/visionfs ]; then
    c_insttype=B
  else
    c_insttype=N
  fi
else
if [ -f $VISION_FILE ]; then
	c_curdesc=`grep "$INST_PRODUCT[_]$c_instname[_]DESC=" $VISION_FILE | sed -e "/^$INST_PRODUCT[_]$c_instname[_]DESC=/s///"`
else
	c_curdesc=""
fi

if [ -f $VISION_FILE ]; then
	c_curbin=`grep "$INST_PRODUCT[_]$c_instname[_]DIR=" $VISION_FILE | sed -e "/^$INST_PRODUCT[_]$c_instname[_]DIR=/s///"`
else
	c_curbin=""
fi

if [ -f $VISION_FILE ]; then
	c_curetc=`grep "$INST_PRODUCT[_]$c_instname[_]ETC=" $VISION_FILE | sed -e "/^$INST_PRODUCT[_]$c_instname[_]ETC=/s///"`
else
	c_curetc=""
fi

if [ -f $VISION_FILE ]; then
	c_curdata=`grep "$INST_PRODUCT[_]$c_instname[_]DATA=" $VISION_FILE | sed -e "/^$INST_PRODUCT[_]$c_instname[_]DATA=/s///"`
else
	c_curdata=""
fi

  
  c_insttype=O
fi

if [ "$pa_custom" = "true" ]; then
  if [ "$c_insttype" != "N" -a "$c_insttype" != "B" ]; then
echo "$p_insttype"
_valid=false
while [ $_valid = false ]
do
  echo $N "$l_insttype [$c_insttype]? $C"
  read _answer
  if [ $trace ] ; then echo "	trace: answer read in is \"$_answer\"" ; fi
  if [ -z "$_answer" ]
  then
    _answer="$c_insttype"   # default
  fi
  case $_answer in [pPoOcC]) _valid=true;;esac
done
if [ $trace ] ; then echo "	trace: answer accepted is \"$_answer\"" ; fi
c_insttype="$_answer"

# the language can alter the behaviour of tr
c_insttype=`echo $c_insttype | LANG=C LC_ALL=C tr '[a-z]' '[A-Z]'`

  fi
fi


## installation name
if [ -z "$c_instname" ]; then
  c_instname="vfs"
else
  if [ "$c_insttype" = "C" -o "$c_insttype" = "P" ]; then
    cnt=1
    while [ "$cnt" != "-1" ]; do
      cnt=`expr 1 + $cnt`
if [ -f $VISION_FILE ]; then
	tmp=`grep "$INST_PRODUCT[_]vfs$cnt[_]DESC=" $VISION_FILE | sed -e "/^$INST_PRODUCT[_]vfs$cnt[_]DESC=/s///"`
else
	tmp=""
fi

      if [ -z "$tmp" ]; then
	c_instname=inst$cnt
	cnt=-1
      fi
    done
  fi
fi

if [ "$pa_custom" = "true" ]; then
  if [ "$c_insttype" = "C" -o "$c_insttype" = "P" ]; then
echo "$p_instname"
_valid=false
while [ $_valid = false ]
do
  echo $N "$l_instname [$c_instname]? $C"
  read _answer
  if [ $trace ] ; then echo "	trace: answer read in is \"$_answer\"" ; fi
  if [ -z "$_answer" ]
  then
    _answer="$c_instname"   # default
  fi
  _valid=true;
done
if [ $trace ] ; then echo "	trace: answer accepted is \"$_answer\"" ; fi
c_instname="$_answer"

    c_instname=`echo $c_instname | LANG=C LC_ALL=C tr -d ",.<>/?#~\'\\@;:\]{}=+_)(*&^%\$\"! 	\-"`
  fi
fi


## install dir
if [ "$c_insttype" = "C" -o "$c_insttype" = "P" ]; then
  c_instbin=${c_curbin}2
else
if [ -f $VISION_FILE ]; then
	c_instbin=`grep "$INST_PRODUCT[_]$c_instname[_]DIR=" $VISION_FILE | sed -e "/^$INST_PRODUCT[_]$c_instname[_]DIR=/s///"`
else
	c_instbin=""
fi

  if [ -z "$c_instbin" ]; then
    c_instbin=$cg_shared/visionfs
  fi
fi

c_bindel="yes"
if [ "$pa_custom" = "true" ]; then
  if [ "$c_insttype" != "O" ]; then
echo "$p_instbin"
_valid=false
while [ $_valid = false ]
do
  echo $N "$l_instbin [$c_instbin]? $C"
  read _dirname
  if [ $trace ] ; then echo "	trace: answer read in is \"$_dirname\"" ; fi
  if [ -z "$_dirname" ]
  then
    _dirname="$c_instbin"   # default
  fi
  if [ -d "$_dirname" -o -f "$_dirname" ]
  then
    if [ -d "$_dirname" ]; then
      _prompt=$l_rmdir
    else
      _prompt=$l_rmfile
    fi
    _valid2=false
    while [ $_valid2 = false ]
    do
      echo $N "$_prompt [$c_bindel]? $C"
      read _answer
      if [ $trace ] ; then echo "	trace: answer read in is \"$_answer\"" ; fi
      if [ -z "$_answer" ]
      then
        _answer="$c_bindel"   # default
      fi
      case "$_answer" in
      [yY]*)
        _valid2=true
        _valid=true
        c_bindel=yes
        ;;
      [nN]*)
        _valid2=true
        _valid=true
        c_bindel=no
      esac
    done
  else
    _valid2=false
    while [ $_valid2 = false ]
    do
      _curr=yes
      echo $N "$l_crdir [$_curr]? $C"
      read _answer
      if [ $trace ] ; then echo "	trace: answer read in is \"$_answer\"" ; fi
      if [ -z "$_answer" ]
      then
        _answer="$_curr"   # default
      fi
      case "$_answer" in
      [yY]*)
        _valid2=true
        _valid=true
        ;;
      [nN]*)
        _valid2=true
      esac
    done
  fi
done
if [ $trace ] ; then echo "	trace: answer accepted is \"$_answer\"" ; fi
c_instbin="$_dirname"

  fi
fi


## config dir
if [ "$c_insttype" = "C" -o "$c_insttype" = "P" ]; then
if [ -z "$c_instbin" ]; then
  c_instetc=.
else
  c_instetc=`expr "$c_instbin/" : '\(/\)/*[^/]*//*$'  \| \
    "$c_instbin/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

    c_instetc=$c_instetc/vfsprofile
    if [ "$c_curetc" = "$c_instetc" ]; then
      c_instetc=${c_curetc}2
    fi
else
if [ -f $VISION_FILE ]; then
	c_instetc=`grep "$INST_PRODUCT[_]$c_instname[_]ETC=" $VISION_FILE | sed -e "/^$INST_PRODUCT[_]$c_instname[_]ETC=/s///"`
else
	c_instetc=""
fi

  if [ -z "$c_instetc" ]; then
if [ -z "$c_instbin" ]; then
  c_instetc=.
else
  c_instetc=`expr "$c_instbin/" : '\(/\)/*[^/]*//*$'  \| \
    "$c_instbin/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

    c_instetc=$c_instetc/vfsprofile
  fi
fi

c_etcdel="no"
if [ "$pa_custom" = "true" ]; then
  if [ "$c_insttype" != "O" ]; then
echo "$p_instetc"
_valid=false
while [ $_valid = false ]
do
  echo $N "$l_instetc [$c_instetc]? $C"
  read _dirname
  if [ $trace ] ; then echo "	trace: answer read in is \"$_dirname\"" ; fi
  if [ -z "$_dirname" ]
  then
    _dirname="$c_instetc"   # default
  fi
  if [ -d "$_dirname" -o -f "$_dirname" ]
  then
    if [ -d "$_dirname" ]; then
      _prompt=$l_rmdir
    else
      _prompt=$l_rmfile
    fi
    _valid2=false
    while [ $_valid2 = false ]
    do
      echo $N "$_prompt [$c_etcdel]? $C"
      read _answer
      if [ $trace ] ; then echo "	trace: answer read in is \"$_answer\"" ; fi
      if [ -z "$_answer" ]
      then
        _answer="$c_etcdel"   # default
      fi
      case "$_answer" in
      [yY]*)
        _valid2=true
        _valid=true
        c_etcdel=yes
        ;;
      [nN]*)
        _valid2=true
        _valid=true
        c_etcdel=no
      esac
    done
  else
    _valid2=false
    while [ $_valid2 = false ]
    do
      _curr=yes
      echo $N "$l_crdir [$_curr]? $C"
      read _answer
      if [ $trace ] ; then echo "	trace: answer read in is \"$_answer\"" ; fi
      if [ -z "$_answer" ]
      then
        _answer="$_curr"   # default
      fi
      case "$_answer" in
      [yY]*)
        _valid2=true
        _valid=true
        ;;
      [nN]*)
        _valid2=true
      esac
    done
  fi
done
if [ $trace ] ; then echo "	trace: answer accepted is \"$_answer\"" ; fi
c_instetc="$_dirname"

  fi
fi


## data dir
if [ "$c_insttype" = "C" -o "$c_insttype" = "P" ]; then
if [ -z "$c_instetc" ]; then
  c_instdata=.
else
  c_instdata=`expr "$c_instetc/" : '\(/\)/*[^/]*//*$'  \| \
    "$c_instetc/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

    c_instdata=$c_instdata/vfsdata
    if [ "$c_instdata" = "$c_curdata" ]; then
      c_instdata=${c_instdata}2
    fi
else
if [ -f $VISION_FILE ]; then
	c_instdata=`grep "$INST_PRODUCT[_]$c_instname[_]DATA=" $VISION_FILE | sed -e "/^$INST_PRODUCT[_]$c_instname[_]DATA=/s///"`
else
	c_instdata=""
fi

  if [ -z "$c_instdata" ]; then
if [ -z "$c_instetc" ]; then
  c_instdata=.
else
  c_instdata=`expr "$c_instetc/" : '\(/\)/*[^/]*//*$'  \| \
    "$c_instetc/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

    c_instdata=$c_instdata/vfsdata
  fi
fi

c_datadel="yes"
if [ "$pa_custom" = "true" ]; then
  if [ "$c_insttype" != "O" ]; then
echo "$p_instdata"
_valid=false
while [ $_valid = false ]
do
  echo $N "$l_instdata [$c_instdata]? $C"
  read _dirname
  if [ $trace ] ; then echo "	trace: answer read in is \"$_dirname\"" ; fi
  if [ -z "$_dirname" ]
  then
    _dirname="$c_instdata"   # default
  fi
  if [ -d "$_dirname" -o -f "$_dirname" ]
  then
    if [ -d "$_dirname" ]; then
      _prompt=$l_rmdir
    else
      _prompt=$l_rmfile
    fi
    _valid2=false
    while [ $_valid2 = false ]
    do
      echo $N "$_prompt [$c_datadel]? $C"
      read _answer
      if [ $trace ] ; then echo "	trace: answer read in is \"$_answer\"" ; fi
      if [ -z "$_answer" ]
      then
        _answer="$c_datadel"   # default
      fi
      case "$_answer" in
      [yY]*)
        _valid2=true
        _valid=true
        c_datadel=yes
        ;;
      [nN]*)
        _valid2=true
        _valid=true
        c_datadel=no
      esac
    done
  else
    _valid2=false
    while [ $_valid2 = false ]
    do
      _curr=yes
      echo $N "$l_crdir [$_curr]? $C"
      read _answer
      if [ $trace ] ; then echo "	trace: answer read in is \"$_answer\"" ; fi
      if [ -z "$_answer" ]
      then
        _answer="$_curr"   # default
      fi
      case "$_answer" in
      [yY]*)
        _valid2=true
        _valid=true
        ;;
      [nN]*)
        _valid2=true
      esac
    done
  fi
done
if [ $trace ] ; then echo "	trace: answer accepted is \"$_answer\"" ; fi
c_instdata="$_dirname"

  fi
fi


## summarise the answers

echo "$l_summary"

# global flags
if [ "$ch_shared"  = "true" ]; then
  echo $N "$l_gshared =$C"
  if [ ! -d "$cg_shared" ]; then
    echo $N " $l_createdir$C"
  fi
  echo " $cg_shared"
fi

# installation bits
echo $N "$l_insttype = $C"
case "$c_insttype" in
  B) echo "$l_insttypeb" ;;
  O) echo "$l_insttypeo ($c_curdesc)" ;;
  N) echo "$l_insttypen" ;;
  P) echo "$l_insttypep" ;;
  C) echo "$l_insttypec ($c_curetc)" ;;
  *) echo "$l_insttypex"
esac

if [ "$c_insttype" = "C" -o "$c_insttype" = "P" ]; then
  echo "$l_instname = $c_instname"
fi

echo $N "$l_instbin =$C"
if [ -d "$c_instbin" -o -f "$c_instbin" ]; then
  if [ "$c_bindel" = "yes" ]; then
    echo $N " $l_deldir$C"
  else
    echo $N " $l_owdir$C"
  fi
else
    echo $N " $l_createdir$C"  
fi
echo " $c_instbin"

_path=$c_instbin
while [ ! -d "$_path" ]; do
if [ -z "$_path" ]; then
  _path=.
else
  _path=`expr "$_path/" : '\(/\)/*[^/]*//*$'  \| \
    "$_path/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

done
if [ -f /bin/pwd ]
then
 origdir=`/bin/pwd`
 cd "$_path"
 dir=`/bin/pwd`
else
 origdir=`pwd`
 cd "$_path"
 dir=`pwd`
fi
 
dirname=$dir
banana=`df -k  > /dev/null 2>&1`
if [  $? = 0 ]
then
 banana=`df -k | egrep [Aa]vail  > /dev/null 2>&1`
 if [ $? = 0 ]
 then
  # System V style output
  a_space=`df -k $dirname | egrep -v [Aa]vail  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
 else
  banana=`df -k | grep Free > /dev/null 2>&1`
  if [ $? = 0 ]
  then 
   # Aix style output
   a_space=`df -k $dirname | grep -v Free  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
  else
  banana=`df -k $dirname | grep "free allocated" > /dev/null 2>&1`
  if [ $? = 0 ]
  then
   # HPUX 10 verbosity
   a_space=`df -k $dirname | sed -n -e '
s/^[ 	]*\([0-9]*\)[ 	]*free allocated.*$/\1/p 
'`
  else
   ## SCO ???
   a_space=`df -k $dirname | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
   fi
  fi
 fi
else
 banana=`df $dirname > /dev/null 2>&1`
 if [  $? = 0  ]
 then
  # Sun OS style output
  a_space=`df  $dirname | egrep -v [Aa]vail  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
 if [ "x$%kytes%" = "x" ]
 then
   a_space=`df $dirname | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
  dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
  sz=`du -s $_path/._._._`
  sz=`expr "$sz" : '\([0-9]*\).*'`
  rm -f $_path/._._._
  case $sz in
   2*)
    a_space=`expr $a_space / $sz`
   ;;
   *)
   ;;
  esac
 fi
 else
  dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
  sz=`du -s $_path/._._._`
  sz=`expr "$sz" : '\([0-9]*\).*'`
  rm -f $_path/._._._
  while [ "$dirname" != "" ]
  do
  a_space=`df | egrep "^$dirname[ 	]*\(.*$" | sed -e '
{
s/^[^\)]*.:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
   if [ "$a_space" != "" -o "$dirname" = "/"  ]
   then
    break
   fi
   dirname=`dirname $dirname`
  done
  case $sz in
   2*)
    a_space=`expr $a_space / $sz`
   ;;
   *)
   ;;
  esac
 fi
fi
cd $origdir

if [ ! -z "$a_space" ]; then
  echo "  ${l_recommended}: ${INST_BINSPACE}K   ${l_available}: ${a_space}K"
fi

echo $N "$l_instetc =$C"
if [ -d "$c_instetc" -o -f "$c_instetc" ]; then
  if [ "$c_etcdel" = "yes" ]; then
    echo $N " $l_deldir$C"
  else
    echo $N " $l_updir$C"
  fi
else
    echo $N " $l_createdir$C"  
fi
echo " $c_instetc"

echo $N "$l_instdata =$C"
if [ -d "$c_instdata" -o -f "$c_instdata" ]; then
  if [ "$c_datadel" = "yes" ]; then
    echo $N " $l_deldir$C"
  else
    echo $N " $l_owdir$C"
  fi
else
    echo $N " $l_createdir$C"  
fi
echo " $c_instdata"

_path=$c_instdata
while [ ! -d "$_path" ]; do
if [ -z "$_path" ]; then
  _path=.
else
  _path=`expr "$_path/" : '\(/\)/*[^/]*//*$'  \| \
    "$_path/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

done
if [ -f /bin/pwd ]
then
 origdir=`/bin/pwd`
 cd "$_path"
 dir=`/bin/pwd`
else
 origdir=`pwd`
 cd "$_path"
 dir=`pwd`
fi
 
dirname=$dir
banana=`df -k  > /dev/null 2>&1`
if [  $? = 0 ]
then
 banana=`df -k | egrep [Aa]vail  > /dev/null 2>&1`
 if [ $? = 0 ]
 then
  # System V style output
  a_space=`df -k $dirname | egrep -v [Aa]vail  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
 else
  banana=`df -k | grep Free > /dev/null 2>&1`
  if [ $? = 0 ]
  then 
   # Aix style output
   a_space=`df -k $dirname | grep -v Free  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
  else
  banana=`df -k $dirname | grep "free allocated" > /dev/null 2>&1`
  if [ $? = 0 ]
  then
   # HPUX 10 verbosity
   a_space=`df -k $dirname | sed -n -e '
s/^[ 	]*\([0-9]*\)[ 	]*free allocated.*$/\1/p 
'`
  else
   ## SCO ???
   a_space=`df -k $dirname | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
   fi
  fi
 fi
else
 banana=`df $dirname > /dev/null 2>&1`
 if [  $? = 0  ]
 then
  # Sun OS style output
  a_space=`df  $dirname | egrep -v [Aa]vail  | sed -e '
{
s/^[^ 	]*[       ]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
 if [ "x$%kytes%" = "x" ]
 then
   a_space=`df $dirname | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
  dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
  sz=`du -s $_path/._._._`
  sz=`expr "$sz" : '\([0-9]*\).*'`
  rm -f $_path/._._._
  case $sz in
   2*)
    a_space=`expr $a_space / $sz`
   ;;
   *)
   ;;
  esac
 fi
 else
  dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
  sz=`du -s $_path/._._._`
  sz=`expr "$sz" : '\([0-9]*\).*'`
  rm -f $_path/._._._
  while [ "$dirname" != "" ]
  do
  a_space=`df | egrep "^$dirname[ 	]*\(.*$" | sed -e '
{
s/^[^\)]*.:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
   if [ "$a_space" != "" -o "$dirname" = "/"  ]
   then
    break
   fi
   dirname=`dirname $dirname`
  done
  case $sz in
   2*)
    a_space=`expr $a_space / $sz`
   ;;
   *)
   ;;
  esac
 fi
fi
cd $origdir

if [ ! -z "$a_space" ]; then
  echo "  ${l_recommended}: ${INST_DATASPACE}K   ${l_available}: ${a_space}K"
fi

# architecture
if [ ! -z "$cg_arch" ]; then
  if [ -z "$cg_unarchexe" ]; then
    echo "$l_architecture = $cg_arch"
  else
    echo "$l_architecture = `$cg_unarchexe $cg_arch`"
  fi
fi

echo ""


## check if ok
a_continue="Y"
echo "$p_continue"
_valid=false
while [ $_valid = false ]
do
  echo $N "$l_continue [$a_continue]? $C"
  read _answer
  if [ $trace ] ; then echo "	trace: answer read in is \"$_answer\"" ; fi
  if [ -z "$_answer" ]
  then
    _answer="$a_continue"   # default
  fi
  case "$_answer" in y|Y|n|N|q|Q)_valid=true;;esac
done
if [ $trace ] ; then echo "	trace: answer accepted is \"$_answer\"" ; fi
a_continue="$_answer"

# the language can alter the behaviour of tr
a_continue=`echo $a_continue | LANG=C LC_ALL=C tr '[a-z]' '[A-Z]'`


# want to change the answers
if [ "$a_continue" = "N" ]; then
  echo "$l_custom"
#  exec $0 --custom --licence "$cg_licence"
  exec $0 --custom
fi

# want to quit
if [ "$a_continue" = "Q" ]; then
  echo "$l_quit" 1>&2
  exit 3
fi

## perform the installation
echo "$l_install"

# make sure umask doesn't damage anything
umask 022

# create shared directory
retval=true
retval="true"
if [ -f $cg_shared ]
then
  retval=false  
else
  if [ ! -d $cg_shared ]
  then
    mkdir -p $cg_shared
  fi

  if [ ! -d $cg_shared ]
  then
    retval=false
  else
    retval=true
    chmod 555 $cg_shared
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
    chown 0 $cg_shared
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
  fi
fi

if [ "$retval" != "true" ]; then
  echo "$0: $lf_shared: $cg_shared" 1>&2
  exit 4
fi

# create shared etc
retval=true
retval="true"
if [ -f $cg_etcdir ]
then
  retval=false  
else
  if [ ! -d $cg_etcdir ]
  then
    mkdir -p $cg_etcdir
  fi

  if [ ! -d $cg_etcdir ]
  then
    retval=false
  else
    retval=true
    chmod 555 $cg_etcdir
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
    chown 0 $cg_etcdir
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
  fi
fi

if [ "$retval" != "true" ]; then
  echo "$0: $lf_etcdir: $cg_etcdir" 1>&2
  exit 5
fi
if [ -f $VISION_FILE ]; then
	grep -v "VISION[_]ETCDIR=" $VISION_FILE > $VISION_FILE.tmp
else
	/bin/rm -f $VISION_FILE
	echo "#  This file is machine processed" > $VISION_FILE.tmp
	echo "# Edit it at your own risk" > $VISION_FILE.tmp
fi
if [ -n "$cg_etcdir" ]; then
	echo VISION"_"ETCDIR="$cg_etcdir" >> $VISION_FILE.tmp
fi
sort $VISION_FILE.tmp > $VISION_FILE
if [ -f $VISION_FILE.tmp ]; then
	/bin/rm -f $VISION_FILE.tmp
fi
chmod 644 $VISION_FILE


# create shared bin
retval=true
retval="true"
if [ -f $cg_bindir ]
then
  retval=false  
else
  if [ ! -d $cg_bindir ]
  then
    mkdir -p $cg_bindir
  fi

  if [ ! -d $cg_bindir ]
  then
    retval=false
  else
    retval=true
    chmod 555 $cg_bindir
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
    chown 0 $cg_bindir
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
  fi
fi

if [ "$retval" != "true" ]; then
  echo "$0: $lf_bindir: $cg_bindir" 1>&2
  exit 6
fi
if [ -f $VISION_FILE ]; then
	grep -v "VISION[_]BINDIR=" $VISION_FILE > $VISION_FILE.tmp
else
	/bin/rm -f $VISION_FILE
	echo "#  This file is machine processed" > $VISION_FILE.tmp
	echo "# Edit it at your own risk" > $VISION_FILE.tmp
fi
if [ -n "$cg_bindir" ]; then
	echo VISION"_"BINDIR="$cg_bindir" >> $VISION_FILE.tmp
fi
sort $VISION_FILE.tmp > $VISION_FILE
if [ -f $VISION_FILE.tmp ]; then
	/bin/rm -f $VISION_FILE.tmp
fi
chmod 644 $VISION_FILE


# attempt to stop the server before doing an overwrite of its binaries
if [ -x $c_instbin/bin/vfsstop -a -x $c_instbin/bin/vfsstatus ]; then
  $c_instbin/bin/vfsstatus --quiet
  if [ "$?" != "0" ]; then
    echo "$l_attemptstop"
    $c_instbin/bin/vfsstop
    if [ "$?" != "0" ]; then
      $c_instbin/bin/vfsstop --kill
    fi
  fi
elif [ -x $c_instbin/bin/scripts/stop -a -x $c_instbin/bin/scripts/status ]; then
  $c_instbin/bin/scripts/status --quiet
  if [ "$?" != "0" ]; then
    echo "$l_attemptstop"
    $c_instbin/bin/scripts/stop --quiet
    if [ "$?" != "0" ]; then
      $c_instbin/bin/scripts/stop --quiet --kill
    fi
  fi
fi

# create new installation directory
if [ "$c_bindel" = "yes" ]; then
  rm -rf "$c_instbin"
fi
retval=true
retval="true"
if [ -f $c_instbin ]
then
  retval=false  
else
  if [ ! -d $c_instbin ]
  then
    mkdir -p $c_instbin
  fi

  if [ ! -d $c_instbin ]
  then
    retval=false
  else
    retval=true
    chmod 555 $c_instbin
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
    chown 0 $c_instbin
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
  fi
fi

if [ "$retval" != "true" ]; then
  echo "$0: $lf_instbin: $c_instbin" 1>&2
  exit 8
fi

# install the tar file
cat $cg_tarfile | (cd "$c_instbin"; tar xf -)
if [ "$?" != "0" ]; then
  echo "$0: $lf_tarfile: $cg_tarfile" 1>&2
  exit 9
fi
if [ -f $VISION_FILE ]; then
	grep -v "$INST_PRODUCT[_]$c_instname[_]DESC=" $VISION_FILE > $VISION_FILE.tmp
else
	/bin/rm -f $VISION_FILE
	echo "#  This file is machine processed" > $VISION_FILE.tmp
	echo "# Edit it at your own risk" >> $VISION_FILE.tmp
fi
if [ -n "$PRODUCT_FULL_NAME $PRODUCT_VERSION_FULL" ]; then
	echo $INST_PRODUCT"_"$c_instname"_"DESC="$PRODUCT_FULL_NAME $PRODUCT_VERSION_FULL" >> $VISION_FILE.tmp
fi
sort $VISION_FILE.tmp > $VISION_FILE
if [ -f $VISION_FILE.tmp ]; then
	/bin/rm -f $VISION_FILE.tmp
fi
chmod 644 $VISION_FILE

if [ -f $VISION_FILE ]; then
	grep -v "$INST_PRODUCT[_]$c_instname[_]DIR=" $VISION_FILE > $VISION_FILE.tmp
else
	/bin/rm -f $VISION_FILE
	echo "#  This file is machine processed" > $VISION_FILE.tmp
	echo "# Edit it at your own risk" >> $VISION_FILE.tmp
fi
if [ -n "$c_instbin" ]; then
	echo $INST_PRODUCT"_"$c_instname"_"DIR="$c_instbin" >> $VISION_FILE.tmp
fi
sort $VISION_FILE.tmp > $VISION_FILE
if [ -f $VISION_FILE.tmp ]; then
	/bin/rm -f $VISION_FILE.tmp
fi
chmod 644 $VISION_FILE

if [ -f $VISION_FILE ]; then
	grep -v "$INST_PRODUCT[_]DEFAULT=" $VISION_FILE > $VISION_FILE.tmp
else
	/bin/rm -f $VISION_FILE
	echo "#  This file is machine processed" > $VISION_FILE.tmp
	echo "# Edit it at your own risk" > $VISION_FILE.tmp
fi
if [ -n "$c_instname" ]; then
	echo $INST_PRODUCT"_"DEFAULT="$c_instname" >> $VISION_FILE.tmp
fi
sort $VISION_FILE.tmp > $VISION_FILE
if [ -f $VISION_FILE.tmp ]; then
	/bin/rm -f $VISION_FILE.tmp
fi
chmod 644 $VISION_FILE


# install the new global level script
if [ ! -f $c_instbin/_inst/visionfs ]; then
  echo "$0: $lf_noglobbin: $c_instbin/_inst/visionfs" 1>&2
  exit 9
fi
rm -f $cg_bindir/visionfs
cp $c_instbin/_inst/visionfs $cg_bindir/visionfs
chmod 555 $cg_bindir/visionfs
chown bin $cg_bindir/visionfs
chgrp bin $cg_bindir/visionfs
if [ ! -x $cg_bindir/visionfs ]; then
  echo "$0: $lf_badglobbin: $cg_bindir/visionfs" 1>&2
  exit 9
fi
  
# create new config directory
if [ "$c_etcdel" = "yes" ]; then
  rm -rf "$c_instetc"
fi
retval=true
retval="true"
if [ -f $c_instetc ]
then
  retval=false  
else
  if [ ! -d $c_instetc ]
  then
    mkdir -p $c_instetc
  fi

  if [ ! -d $c_instetc ]
  then
    retval=false
  else
    retval=true
    chmod 500 $c_instetc
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
    chgrp bin $c_instetc
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
    chown bin $c_instetc
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
  fi
fi

if [ "$retval" != "true" ]; then
  echo "$0: $lf_instetc: $c_instetc" 1>&2
  exit 10
fi
if [ -f $VISION_FILE ]; then
	grep -v "$INST_PRODUCT[_]$c_instname[_]ETC=" $VISION_FILE > $VISION_FILE.tmp
else
	/bin/rm -f $VISION_FILE
	echo "#  This file is machine processed" > $VISION_FILE.tmp
	echo "# Edit it at your own risk" >> $VISION_FILE.tmp
fi
if [ -n "$c_instetc" ]; then
	echo $INST_PRODUCT"_"$c_instname"_"ETC="$c_instetc" >> $VISION_FILE.tmp
fi
sort $VISION_FILE.tmp > $VISION_FILE
if [ -f $VISION_FILE.tmp ]; then
	/bin/rm -f $VISION_FILE.tmp
fi
chmod 644 $VISION_FILE

if [ "$c_insttype" = "C" ]; then
  # make a copy of the old one
  tar cf - $c_curetc/* | (cd $c_instetc; tar xf -)
  if [ "$?" != "0" ]; then
    echo "$0: $lf_curetc: $c_curetc -> $c_instetc" 1>&2
    exit 10
  fi
fi

# create new data directory
if [ "$c_datadel" = "yes" ]; then
  rm -rf "$c_instdata"
fi
retval=true
retval="true"
if [ -f $c_instdata ]
then
  retval=false  
else
  if [ ! -d $c_instdata ]
  then
    mkdir -p $c_instdata
  fi

  if [ ! -d $c_instdata ]
  then
    retval=false
  else
    retval=true
    chmod 555 $c_instdata
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
    chgrp bin $c_instdata
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
    chown bin $c_instdata
    if [ "$?" != "0" ]
    then
      retval=nearly
    fi
  fi
fi

if [ "$retval" != "true" ]; then
  echo "$0: $lf_instdata: $c_instdata" 1>&2
  exit 11
fi
if [ -f $VISION_FILE ]; then
	grep -v "$INST_PRODUCT[_]$c_instname[_]DATA=" $VISION_FILE > $VISION_FILE.tmp
else
	/bin/rm -f $VISION_FILE
	echo "#  This file is machine processed" > $VISION_FILE.tmp
	echo "# Edit it at your own risk" >> $VISION_FILE.tmp
fi
if [ -n "$c_instdata" ]; then
	echo $INST_PRODUCT"_"$c_instname"_"DATA="$c_instdata" >> $VISION_FILE.tmp
fi
sort $VISION_FILE.tmp > $VISION_FILE
if [ -f $VISION_FILE.tmp ]; then
	/bin/rm -f $VISION_FILE.tmp
fi
chmod 644 $VISION_FILE


## transfer to the new installation, invoked with the new name

exec $c_instbin/bin/visionfs --inst "$c_instname" setup --inst "$c_instname" --install
echo "$0: $lf_badexec: $c_instbin/bin/visionfs" 1>&2
exit 12
