#!/bin/sh
#
# Andrei.Ryjov  AKA  aryzhov@yahoo.com  Sun Dec  9 09:50:18 MET 2001
#
# The order of preferences in profile generation is important
# so that we can be as generic and as specific as we like
#
# See also !README in $SI_CONFIG_DIR/Profiles directory
#
[ -z "$SID" ] && SID=/tmp/install_config
[ X$SubrIsRead = XYes ] || . $SID/Scripts/Misc/!Includes/Subroutines
[ X$VarsAreSet = XYes ] || SetJVars

#
# PROFLIST says what pieces to build the profile from,
# and in what order
#
PROFLIST="
  Types
  Begin
  DiskSlicing
  Packages
  Finish
  Postinstall
"

#
# Make sure the $SI_PROFILE exists and is a symlink
#
if [ -f ${SI_PROFILE} ] ; then

  echo "
	$SI_BEGIN WARNING:
	${SI_PROFILE} seems to be static (Sun default)
	rather than POST symlink to $REALFILE
	using it as default

  "

elif [ ! -h ${SI_PROFILE} ] ; then

  echo "
	$SI_BEGIN ERROR:
	No ${SI_PROFILE} symlink
  "
  Start_Shell

else    # Allright, that's a softlink!

  #
  # Create the file that the link points to
  #
  REALFILE=`file -h ${SI_PROFILE} | awk '{print $5}'`
  touch $REALFILE || {
    echo "
	Cannot create $REALFILE for $SI_PROFILE
    "
    Start_Shell
  }

  echo Constructing $SI_PROFILE for $SITE/$MYBASE

  for PROF in $PROFLIST ; do
    if   [ -f $INCDIR/$SITE/$PROF/$MYNAME   ] ; then F=$INCDIR/$SITE/$PROF/$MYNAME
    elif [ -f $INCDIR/$SITE/$PROF/$MYBASE   ] ; then F=$INCDIR/$SITE/$PROF/$MYBASE
    elif [ -f $INCDIR/$SITE/$PROF/Std       ] ; then F=$INCDIR/$SITE/$PROF/Std
    elif [ -f $INCDIR/AnySite/$PROF/Std     ] ; then F=$INCDIR/AnySite/$PROF/Std
    else
      echo "
	ERROR:
	  Can not find a $PROF profile part for $SITE/$MYNAME
      "
      Start_Shell
    fi
    echo "\t$SI_PROFILE   <===    $F"
    cat $F >>$SI_PROFILE
  done
fi
