#!/bin/sh
#
# install - install a program, script, or datafile
# This is based on a program from X11R5.
# Modified by Marcus Sundberg [marcus@ggi-project.org]
#


# set DOITPROG to echo to test this script

# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"


# put in absolute paths if you don't have them in your path; or use env. vars.

mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"

tranformbasename=""
transform_arg=""
instcmd="$cpprog"
chmodcmd="$chmodprog 755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
srcs=""
dst=""

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

	-m) chmodcmd="$chmodprog $2"
	    shift
	    shift
	    continue;;

	-o) chowncmd="$chownprog $2"
	    shift
	    shift
	    continue;;

	-g) chgrpcmd="$chgrpprog $2"
	    shift
	    shift
	    continue;;

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

if [ x"$srcs" = x ]
then
	echo "install:	no input file specified"
	exit 1
else
	true
fi

for src in `echo $srcs` ; do
	if [ -f $src -o -d $src ]
	then
		true
	else
		echo "install:  $src does not exist"
		exit 1
	fi
	
	if [ x"$dst" = x ]
	then
		echo "install:	no destination specified"
		exit 1
	else
		true
	fi

	srcname=`basename $src`
	if [ -d $dst ] ; then
		dest="$dst/$srcname"
	else
		dest="$dst"
	fi
	
	$doit $rmcmd $dest
	$doit $instcmd $src $dest

# set any options; do chmod last to preserve setuid bits

	if [ x"$chowncmd" != x ]; then $doit $chowncmd $dest; else true;fi
	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dest; else true;fi
	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dest; else true;fi

done


exit 0
