#!/bin/sh
#
#   Darryl L. Miles (09/10/1995) quick bodge(TM)
#
#   BSD Install syntax in, coverts and runs IRIX install out.
#	This does not work completely, time to use perl!
#
#

strip=no

while true
do
	case "$1" in
	-o)	owner=$2; shift;	;;
	-g)	group=$2; shift;	;;
	-m)	mode=$2; shift;		;;
	-s)	strip=yes;	;;
	# This is old compatability (it says)
	-c)	true;		;;
	--)	shift;	break;	;;
	-*)	euh="$euh $1";	;;
	*)	break;		;;
	esac
	shift
done

if [ "$euh" != "" ]
then
	echo "$0: Unknown options/arguments '$euh'" >&2
	exit 1
fi

if [ $# -lt 2 ]
then
	echo "$0: Not enough arguments, need src and dest pathnames" >&2
	exit 1
fi

srcs=""
dest=""

while [ $# -gt 0 ]
do
	if [ $# -eq 1 ]
	then
		# The last so must be dest
		dest=$1
	else
		# A src file
		srcs="$srcs $1"
	fi
	shift
done


if [ "$srcs" = "" ]
then
	echo "$0: Destination file or directory has not been specified" >&2
	exit 1
fi

if [ "$dest" = "" ]
then
	echo "$0: Source file(s) has not been specified" >&2
	exit 1
fi


# Work out the command line args for IRIX install proggie
arg=""

if [ "$owner" != "" ]
then
	arg="$arg -u $owner"
fi

if [ "$group" != "" ]
then
	arg="$arg -g $group"
fi

if [ "$mode" != "" ]
then
	arg="$arg -m $mode"
fi

if a=`expr "$dest" : "\(.*\)/"`
then
   b=`expr "$dest" :".*/\(.*\)"`
   if [ "$b" != "$srcs" ]
   then
      altname=$b
   fi
   dest=$a
fi

# If dest name is different to the src name then rename it.
#   I hope this will do the trick...
if [ "$altname" != "" ]
then
   $arg="$arg -O $altname"
fi

# IRIX install uses -F to specify the path if you wish the dirs to be
#   created, and -f is you don't.  We assume -F.
arg="$arg -F $dest $srcs"


# We don't implement symbol stripping at the mo, IRIX install doesn't
#   appear to have this functionallity, do we'd have to run the 'strip'
#   util after /sbin/install.

#echo "Would exec: /sbin/install $arg"
#echo "Would exec: /sbin/install $arg" >>/tmp/install.log

exec /sbin/install $arg
