#! /bin/sh
#
#	Shell to begin execution of PortMaster Installation Program
#
PATH=/bin:/usr/bin:/usr/ucb:$PATH
#
#	Must be run as root
#
UNAME=`whoami`
#
if [ "$UNAME" != "root" ]; then
	echo "PMinstall must be run as root."
	echo "Installation Aborted."
	exit 0
fi
#
#	Get full path of this shell script
#
DIR=`expr \
  ${0-.}'/' : '\(/\)[^/]*/$' \
  \| ${0-.}'/' : '\(.*[^/]\)//*[^/][^/]*//*$' \
  \| .`
#
#	Check for compressed files before trying to run anything
#
if [ -f ${DIR}/Zcheck ]
then
	echo -n "Uncompressing distribution files.  Please wait...."
	for i in ${DIR}/*/*.Z ${DIR}/*/*/*.Z
	do
		uncompress -f ${i} >/tmp/unclog 2>&1
	done
	/bin/rm -f ${DIR}/Zcheck
	echo "done."
fi
#
#	We need the system architecture and the version to
#	determine which executable to run.
#
#
ARCH=""
if [ -f /bin/arch ]
then
	ARCH=`arch`
else
	ARCH=`uname -m`
fi
#
#	Handle Sun architectures
#
SUNARCH=`echo $ARCH | awk '{printf("%.4s", $1)}'`
if [ "$SUNARCH" = "sun4" ]
then
	ARCH="sun4"
fi
#
#
SYSTYPE=`uname -s`
if [ "$SYSTYPE" = "AIX" ]
then
	ARCH="RS6000"
	SYSOS="3.2"
elif [ "$SYSTYPE" = "HP-UX" ]
then
	ARCH="hp9000"
	SYSOS="9.3"
else
	SYSOS=`uname -r | awk '{printf("%.3s", $1)}'`
fi
#
#
if [ "$ARCH" = "" ]
then
	echo "Unknown system type"
	exit -1
fi
if [ "$SYSOS" = "" ]
then
	echo "Unknown system release"
	exit -1
fi
#
#	Run-it
exec ${DIR}/${ARCH}_${SYSOS}/pm_install
