#!/bin/bash
#
# 2006-10-24: this script should be vestigial now.  we want to avoid having to install
#   headers and libnfs4acl.a, so the CLI and GUI tools should hopefully be able to 
#   just statically link against it here in the build tree.  a `make install` in the 
#   top-level directory should just install `nfs4_getfacl` and `nfs4_setfacl`.
#
#
# supercrummy install script for libnfs4acl.  the Makefile stuff we bogarted isn't being friendly.

bin_path="/usr/local/bin"
lib_path="/lib"
hdr_path="/usr/local/include"
headers="nfs4.h libacl.h libacl_nfs4.h acl.h"
objects="nfs4_getfacl nfs4_setfacl"

mvhdrs() {
	for hdr in $headers; do
		sh -x -c "cp include/$hdr $hdr_path"
	done
}

isbin() {
	if (ldd "$1" >/dev/null 2>&1) ; then
		return 0
	else
		return 1
	fi
}

if (egrep -i "ENABLE_SHARED.*yes" include/builddefs); then
	sh -x -c "cp libnfs4acl/.libs/libnfs4acl.so.0.0.1 $lib_path"
	sh -x -c "cp nfs4_getfacl/.libs/nfs4_getfacl $bin_path"
	sh -x -c "cp nfs4_setfacl/.libs/nfs4_setfacl $bin_path"
	mvhdrs
	echo "Running \`ldconfig' .."
	if ! (/usr/bin/env ldconfig); then
		echo "An error occurred with \`ldconfig'."
		exit 1
	fi
else
	for name in $objects ; do
		if (isbin "$name/$name") ; then
			sh -x -c "cp $name/$name $bin_path"
		elif (isbin "$name/.libs/$name") ; then
			sh -x -c "cp $name/.libs/$name $bin_path"
		else
			echo "ERROR: couldn't find \`$name' executable."
		fi
	done
	
	sh -x -c "cp libnfs4acl/.libs/libnfs4acl.a $lib_path"
	mvhdrs
fi
