#! /bin/sh
#
# @(#)installfile	1.3	LPS_UNX_COM	2/19/95
#
# Copyright 1993   Digital Equipment Corporation, Maynard, MA
#
# installfile
#
# Script to copy a file to a directory and set its mode, owner and group.
#
# A check is made to see whether the source and destination actually point
# to the same file.  If they do, then the file is not copied, but all other
# installation tasks (setting mode, owner and group) are performed.
#
# If the directory paths of the source file and target directory are the
# same then the file is not copied; all other aspects of the installation
# of the file are performed, such as protection, owner, etc.
#
# Parameters are:
#
#     $1 - Source file path
#     $2 - Target directory path
#     $3 - Mode value
#     $4 - Owner
#     $5 - Group
#     $6 - Strip flag (ignored)
#
# Global variables used:
#    LINKCHECKOPTS   To enable debugging during symbolic link checks.
#
# If any problems are encountered during this script (other than a failure
# to optionally strip the target executable file), the script exits with a
# value of 1; otherwise, the exit value is 0 for success.

basename="`basename $1`"
target="$2/$basename"

# First check to see if the paths for source and destination files
# resolve to the same path due to potential symbolic links; if so,
# then don't copy the file.

if linkcheck $LINKCHECKOPTS "`dirname $1`" "$2"
then
    :
else
    if cp $1 $target
    then
	:
    else
	echo
	echo "    Unable to copy file $1 to directory $2"
	exit 1
    fi
fi

if chmod $3 $target
then
    if chown $4 $target
    then
	if chgrp $5 $target
	then
	    exit 0	# Success
	else
	    error="set group ownership for $target"
	fi
    else
	error="set ownership for $target"
    fi
else
    error="set mode (protection) for $target"
fi

echo
echo "    Unable to $error"

exit 1
