#!/bin/sh
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.

# makesspkg: make a superserver package for Solaris or similar systems.
# Should be run as root (e.g. with rasu), so the files in the package
# will wind up being owned by root.
# Accepts one optional argument, the name of the package instance
# to be created, followed optionally by flags to be passed through to
# makesstar, such as -c for client without server and -n for no documentation.

INSTANCE=""

if [ $# -gt 0 ] ; then
  case $1 in
    -*)
	;;
    * )
	INSTANCE=$1;
	shift;;
  esac
fi

./makesstar $@
if [ $? != 0 ] ; then
  echo $0 exiting due to error in makesstar
  exit 1
fi

INCLUDE_DOC=1
INCLUDE_SERVER=1
DONE_PARSING=0

while [ $# -gt 0 -a $DONE_PARSING -eq 0 ] ; do
  case "$1" in
    -c|--clientonly)
		     INCLUDE_SERVER=0;
		     shift;;
    -n|--nodocs    )
		     INCLUDE_DOC=0;
		     shift;;
    -nc|-cn        )
		     INCLUDE_SERVER=0;
		     INCLUDE_DOC=0;
		     shift;;
    -*             )
		     echo $0 unknown option $1, terminating.;
		     exit 1;;
    *              )
		     DONE_PARSING=1;;
  esac
done

if [ $INCLUDE_SERVER -eq 1 ] ; then
  if [ $INCLUDE_DOC -eq 1 ] ; then
    SUFFIX=clsr
  else
    SUFFIX=clsrnd
  fi
else
  if [ $INCLUDE_DOC -eq 1 ] ; then
    SUFFIX=cl
  else
    SUFFIX=clnd
  fi
fi


#copy Server specific info files
cp pkginfo.$SUFFIX pkginfo
cp request.$SUFFIX request
cp postinstall.$SUFFIX postinstall
cp preremove.$SUFFIX preremove
cp depend.$SUFFIX depend
cp copyright.$SUFFIX copyright

cat > prototype <<EOF
i pkginfo
i request
i postinstall
i preremove
i depend
i copyright
EOF

pkgproto `pwd`/sstar/interbase=\$IBINSTALL/interbase >> prototype

if [ -d sspkg ] ; then
    rm -rf sspkg
fi

mkdir sspkg

# if the user did not specify a name for the package instance, we
# assume that the PSTAMP field has already been edited into pkginfo

if [ "$INSTANCE" != "" ] ; then
    pkgmk -d `pwd`/sspkg -p $INSTANCE
else
    pkgmk -d `pwd`/sspkg
fi

rm -rf sstar

exit
