#! /bin/sh
#
# $Header: install.sh,v 4.300 91/06/09 02:31:32 root Rel41 $ SONY;
#
#	@(#)install.sh	4.8	(Berkeley)	3/6/86
#
cmd=""
stripbefore=""
stripafter=""
preserve=""
chmod="/bin/chmod -f 755"
chown="/etc/chown -f root"
chgrp="/bin/chgrp -f staff"
pflag=false
mflag=false
while true ; do
	case $1 in
		-s )	if [ $cmd ]
			then	stripafter="/usr/bin/strip"
			else	stripbefore="/usr/bin/strip"
			fi
			shift
			;;
		-c )	if [ $cmd ]
			then	echo "install: multiple specifications of -c"
				exit 1
			fi
			cmd="/bin/cp"
			stripafter=$stripbefore
			stripbefore=""
			shift
			;;
		-p )	preserve="-p"
			pflag=true
			shift
			;;
		-m )	chmod="/bin/chmod -f $2"
			mflag=true
			shift
			shift
			;;
		-o )	chown="/etc/chown -f $2"
			shift
			shift
			;;
		-g )	chgrp="/bin/chgrp -f $2"
			shift
			shift
			;;
		* )	break
			;;
	esac
done

if [ ! ${2-""} ]
then	echo "install: no destination specified"
	exit 1
fi
if [ ${3-""} ]
then	echo "install: too many files specified -> $*"
	exit 1
fi
if [ $1 = $2 -o $2 = . ]
then	echo "install: can't move $1 onto itself"
	exit 1
fi
if [ '!' -f $1 ]
then	echo "install: can't open $1"
	exit 1
fi
if [ -d $2 ]
then	file=$2/`basename $1`
else	file=$2
fi
/bin/rm -f $file
if [ $stripbefore ]
then	$stripbefore $1
fi

if $pflag
then
	if [ $cmd ]
	then 	$cmd -p $1 $file
	else 	/bin/cp -p $1 $file
		/bin/rm $1
	fi
	$mflag || chmod=true 
elif [ $cmd ]
	then	$cmd $1 $file
	else	/bin/mv	$1 $file
fi

if [ $stripafter ]
then	$stripafter $file
fi

$chown $file
$chgrp $file
$chmod $file

