#! /bin/sh
#
#  @(#)install.sh	4.1	ULTRIX	7/17/90
#
# $Id: hginstall,v 1.1 1995/11/27 07:58:10 gpani Exp $
# $Log: hginstall,v $
# Revision 1.1  1995/11/27 07:58:10  gpani
# Initial revision
#
# Revision 1.1  1995/11/15 07:50:01  gpani
# Initial revision
#

cmd=/bin/mv
strip=""
chmod="/bin/chmod 755"
if [ -f "/etc/chown" ]
then
    chownprg="/etc/chown"
else
    chownprg="/bin/chown"
fi

chown="$chownprg -f root"
chgrp="/bin/chgrp -f system"
newer=0
friendly=0

while :
do
	case $1 in
	-s )	strip="/bin/strip"
		;;
	-c )	cmd="/bin/cp"
		;;
	-m )	chmod="/bin/chmod $2"
		shift
		;;
	-o )	chown="$chownprg -f $2"
		shift
		;;
	-g )	chgrp="/bin/chgrp -f $2"
		shift
		;;
	-n )	newer=1
		;;
	-f )	friendly=1
		;;
	* )	break
		;;
	esac
	shift
done

case "$2" in
"")	echo "install: no destination specified"
	exit 1
	;;
.|"$1")	echo "install: can't move $1 onto itself"
	exit 1
	;;
esac
case "$3" in
"")	;;
*)	echo "install: too many files specified -> $*"
	exit 1
	;;
esac
if [ -d $2 ]
then	file=$2/$1
else	file=$2
fi
if [ -r $1 ]
then
	if [ -r $file ]
	then
		if [ $newer = 1 ]
		then
			if `testnewer $1 $file` 
			then
				if [ $friendly = 1 ]
				then
					/bin/mv -f $file $file.old
				else 
					/bin/rm -f $file
				fi
			else
				# echo "install: file $file is up to date."
				exit 0
			fi
		else
			if [ $friendly = 1 ]
			then
				/bin/mv -f $file $file.old
			else
				/bin/rm -f $file
			fi
		fi
	else
		echo ""
	fi
else
	echo "install: file $1 does not exist."
	exit 1
fi


#
# mkdir if directory does not exist.
#

echo "hginstall: installing $file"

tmpvar=`dirname $file`




if [ ! -d "$tmpvar" ]
then
    mkdir -p $tmpvar
fi
	
$cmd $1 $file
[ $strip ] && $strip $file

# 
# gpani 9 Jan 95    
# 
# $chown $file
# $chgrp $file

$chmod $file
