#! /bin/sh
#
#	Shell to begin execution of PortMaster Installation Program
#
PATH=/bin:/usr/bin:/usr/ucb:$PATH
#
#	Must be run as root
#
UNAME=`whoami`
#
# cdr@server.livingston.com 94/11/15 root check disabled
# 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 ${DIR}/*/*/*.Z ${DIR}/*/*/*/*.Z
	do
		uncompress -f ${i} >/dev/null 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=`uname -m`
SYSOS=`uname -s`

ARCH4=`echo $ARCH | awk '{printf("%.4s",$1)}'`

if [ "$ARCH4" = "sun4" ]
then
	ARCH="sun4"
	SYSVER=`uname -r | awk -F\. '{printf("%.3s.%.3s", $1, $2)}'`
	
elif [ "$ARCH4" = "sun3" ]
then
	ARCH="sun3"
	SYSVER=`uname -r | awk -F\. '{printf("%.3s.%.3s", $1, $2)}'`
	
elif [ "$ARCH" = "alpha" ]
then
	SYSVER=`uname -r | awk -F\. '{printf("%.3s.%.3s", $1, $2)}'`

elif [ "$ARCH" = "hp9000" ]
then
	SYSVER=`uname -r | awk -F\. '{printf("%.3s.%.3s", $1, $2)}'`

elif [ "$SYSOS" = "IRIX" ]
then
	ARCH=`uname -s`
	SYSVER=`uname -r | awk -F\. '{printf("%.3s.%.3s", $1, $2)}'`

elif [ "$ARCH4" = "RS60" ]
then
	SYSVER=`uname -r | awk -F\. '{printf("%.3s.%.3s", $1, $2)}'`

elif [ "$ARCH" = "i86pc" ]
then
	ARCH="sun86"
	SYSVER=`uname -r | awk '{printf("%.3s", $1)}'`

elif [ "$ARCH" = "i386" ]
then
	ARCH=`uname -s`
	SYSVER=`uname -r | awk '{printf("%.3s", $1)}'`

elif [ "$ARCH" = "i486" ]
then
	ARCH=`uname -s`
	SYSVER=`uname -r | awk '{printf("%.3s", $1)}'`

elif [ "$ARCH" = "i586" ]
then
	ARCH=`uname -s`
	SYSVER=`uname -r | awk '{printf("%.3s", $1)}'`

elif [ "$SYSOS" = "HP-UX" ]
then
	ARCH="hp9000"
	SYSVER="9.3"

elif [ "$SYSOS" = "AIX" ]
then
	ARCH="RS6000"
	SYSVER=`uname -v`'.'`uname -r`
fi 

if [ "$SYSOS" = "Linux" ]
then
        PLATFORM="Linux"
elif [ "$SYSOS" = "BSD/OS" ]
then
        PLATFORM="BSDOS_${SYSVER}"
else
        PLATFORM="${ARCH}_${SYSVER}"
fi

#
#	Run-it
#
if [ -d ${DIR}/${PLATFORM} ]
then
	exec ${DIR}/${PLATFORM}/pm_install "$@"
else
	echo "${PLATFORM} program directory not found in ${DIR}"
fi
