#!/bin/sh

# $Id: bsdinstall,v 1.1 1995/11/27 07:58:10 gpani Exp $
# $Log: bsdinstall,v $
# Revision 1.1  1995/11/27 07:58:10  gpani
# Initial revision
#
# Revision 1.1  1995/11/15 07:47:58  gpani
# Initial revision
#
#
# This accepts bsd-style install arguments and makes the appropriate calls
# to the System V install.
#

flags=""
dst=""
src=""
dostrip=""
owner=""
mode=""

while [ x$1 != x ]; do
    case $1 in 
	-c) shift
	    continue;;

	-m) flags="$flags $1 $2 "
	    mode="$2"
	    shift
	    shift
	    continue;;

	-o) flags="$flags -u $2 "
	    owner="$2"
	    shift
	    shift
	    continue;;

	-g) flags="$flags $1 $2 "
	    shift
	    shift
	    continue;;

	-s) dostrip="strip"
	    shift
	    continue;;

	*)  if [ x$src = x ] 
	    then
		src=$1
	    else
		dst=$1
	    fi
	    shift
	    continue;;
    esac
done

case "$mode" in
"")
	;;
*)
#	case "$owner" in
#	"")
#		flags="$flags -u root"
#		;;
#	esac
	;;
esac

if [ x$src = x ] 
then
	echo "bsdinst:  no input file specified"
	exit 1
fi

if [ x$dst = x ] 
then
	echo "bsdinst:  no destination specified"
	exit 1
fi


# set up some variable to be used later

rmcmd=""
srcdir="."

# if the destination isn't a directory we'll need to copy it first

if [ ! -d $dst ]
then
	dstbase=`basename $dst`
	cp $src /usr/tmp/$dstbase
	rmcmd="rm -f /usr/tmp/$dstbase"
	src=$dstbase
	srcdir=/usr/tmp
	dst="`echo $dst | sed 's,^\(.*\)/.*$,\1,'`"
	if [ x$dst = x ]
	then
		dst="."
	else
		cd $dst
		dst="`pwd`"
	fi
fi


# If the src file has a directory, copy it to /usr/tmp to make install happy

srcbase=`basename $src`

if [ "$src" != "$srcbase" -a "$src" != "./$srcbase" ] 
then
	cp $src /usr/tmp/$srcbase
	src=$srcbase
	srcdir=/usr/tmp
	rmcmd="rm -f /usr/tmp/$srcbase"
fi

# do the actual install

if [ -f /usr/sbin/install ]
then
	installcmd=/usr/sbin/install
elif [ -f /etc/install ]
then
	installcmd=/etc/install
else
	installcmd=install
fi

# This rm is commented out because some people want to be able to
# install through symbolic links.  Uncomment it if it offends you.
## It offends me because it means I can't install over running apps.
rm -f $dst/$srcbase
(cd $srcdir ; $installcmd -f $dst $flags $src)

if [ x$dostrip = xstrip ]
then
	strip $dst/$srcbase
fi

# and clean up

$rmcmd

