case $CONFIG in
'')
    if test ! -f config.sh; then
	ln ../config.sh . || \
	ln ../../config.sh . || \
	ln ../../../config.sh . || \
	(echo "Can't find config.sh."; exit 1)
    fi
    . config.sh
    ;;
esac
case "$0" in
*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
esac
echo "Extracting install (with variable substitutions)"
$spitshell >install <<!GROK!THIS!
$startsh
# @(#) Installing script accepting bsd-style arguments
# Derived from a script found in the X11R4 distribution.

# $Id: install.SH,v 2.0 91/02/19 15:49:42 ram Exp $
#
# $Log:	install.SH,v $
# Revision 2.0  91/02/19  15:49:42  ram
# Baseline for first official release.
# 

chown='$chown'
chmod='$chmod'
chgrp='$chgrp'
!GROK!THIS!
$spitshell >>install <<'!NO!SUBS!'

mode=""
dst=""
src=""
dostrip=""
newdir=""
uid=""
gid=""

mkdir_p()
{
	# recursively called to build a path (simulates the BSD `mkdir -p')
	# Bourne shell cannot handle recursive functions -- use subshells

	(
		name=$1
		if test ! -d $name
		then
			mkdir_p `dirname $name`
			mkdir $name
			echo "install: created directory $name" >&2
		fi
	)
}

while test x$1 != x
do
	case $1 in 
	-c) shift
		continue
		;;
	-m) mode="$2 "
		shift
		shift
		continue
		;;
	-o) uid="$2 "
		shift
		shift
		continue
		;;
	-g) gid="$2 "
		shift
		shift
		continue
		;;
	-s) dostrip="strip"
		shift
		continue
		;;
	-d) newdir="$newdir$2 "
		shift
		shift
		continue
		;;
	*) if test x$src = x
		then
			src=$1
		else
			dst=$1
		fi
		shift
		continue
		;;
	esac
done

# if -d option is used, we have to create the path given
# mkdir -p may not exist, so do it by hand
if test ! x$newdir = x
then
	for i in $newdir
	do
		mkdir_p $i
	done
	exit 0		# -d is the only action
fi

if test x$src = x
then
	echo "install:  no input file specified" >&2
	exit 1
fi

if test x$dst = x
then
	echo "install:  no destination specified" >&2
	exit 1
fi

# Set up some variable to be used later
rmcmd=""
srcdir="."

# In case we are interrupted
trap "$rmcmd ; exit 1" 1 2 3 15

# If the destination isn't a directory we'll need to copy it first
if test ! -d $dst
then
	dstbase=`basename $dst`
	cp $src /tmp/$dstbase
	rmcmd="rm -f /tmp/$dstbase"
	src=$dstbase
	srcdir=/tmp
	dst="`echo $dst | sed 's,^\(.*\)/.*$,\1,'`"
	if test x$dst = x
	then
		dst="."
	fi
fi

# If the src file has a directory, copy it to /tmp to make install happy
srcbase=`basename $src`

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

# Now start the install procedure
(
	cd $srcdir

	# first, copy the src to dst, renaming old version
	if test -f $dst/$src
	then
		mv $dst/$src $dst/OLD$src &&
		echo "install: $dst/$src renamed as OLD$src"
	fi
	cp $src $dst/$src &&
	echo "install: $src installed as $dst/$src"

	# Alter mode
	if test ! x$uid = x
	then
		$chown $uid $dst/$src
	fi
	if test ! x$gid = x
	then
		$chgrp $gid $dst/$src
	fi
	if test ! x$mode = x
	then
		$chmod $mode $dst/$src
	fi

	# strip dest if necessary
	if test ! x$dostrip = x
	then
		echo "install: stripping $dst/$src"
		strip $dst/$src
	fi
)

# And clean up
$rmcmd
!NO!SUBS!
chmod 755 install
$eunicefix install
