#!/bin/sh
#
# Andrei.Ryjov  AKA  aryzhov@excite.com  Wed Feb 16 19:22:34 MET 2001
#
# Process the Jumpstart profile from stdin to stdout
# Substitute the #!Include comments
PREMSG="Profile generation"
IFS=""

while read LINE ; do
  if echo $LINE | egrep -s '^#!Include' ; then
    #
    # The file may be in both $SI_CONFIG_DIR and $SI_CONFIG_DIR/Profiles
    # Make sure it is the same file
    #
    FILE=`echo $LINE | awk '{print $2}'`
    if   [ ! -r $SI_CONFIG_DIR/$FILE ] ; then
      echo "
	$PREMSG WARNING:
	  Can not find include file $FILE - trying Profiles/$FILE

      " >>/dev/console

      if [ ! -r $SI_CONFIG_DIR/Profiles/$FILE ] ; then

	echo "
	  $PREMSG FATAL ERROR:
	    Can not find include file Profiles/$FILE
	    Starting shell

	" >>/dev/console
	exit 1
      else
	FILE=Profiles/$FILE
      fi
    else
      if [ -r $SI_CONFIG_DIR/Profiles/$FILE ] ; then
	cmp $SI_CONFIG_DIR/$FILE $SI_CONFIG_DIR/Profiles/$FILE || {
	  echo "
	    $PREMSG ERROR:
	      $SI_CONFIG_DIR/$FILE $SI_CONFIG_DIR/Profiles/$FILE
	      Different versions of include file

	      Starting shell

	  " >>/dev/console
	  /sbin/sh
	}
      fi
    fi
    cat $SI_CONFIG_DIR/$FILE
  else
    echo "$LINE"
  fi
done
