#!/bin/tcsh

set installdir="/usr/sbin"
echo -n "installing procfgd in $installdir... "
cp procfgd $installdir || echo "failed" && exit 1
cp procfgd_adduser $installdir || echo "failed" && exit 1
echo "OK"

set man_cfg=/etc/man.confg
set man_type=man1
set dirlist=`[ -e $man_cfg ] && grep -e "^MANPATH[^_]" $man_cfg | awk '{print $2}'`
if ("$dirlist" == "") then
    set dirlist="/usr/share/man /usr/man"
endif
# prune the list down to only values that exist
foreach dir ($dirlist)
    [ -e $dir/$man_type ] && set man_path = $dir && break
end
if ("$man_path" == "") then
    set man_path = /usr/man
endif
set man_path = $man_path/$man_type

echo -n "installing procfgd man page (procfgd.1) in $man_path..."
rm -f $man_path/procfgd.1
cp procfgd.1.gz $man_path || echo "failed" && exit 1
echo "OK"

# documentation installation
set docdir="/usr/share/doc/procfgd-"1.3.12""
mkdir -p $docdir
echo -n "installing documentation in $docdir..."
cp README LICENSE* ldistrib.txt $docdir || echo "failed" && exit 1
echo "OK"
       
# xerces library installation
set xerces_tar="libxerces-c1_6_0.tar.gz"
set xerces_lib="libxerces-c1_6_0.so"
set libdir="/usr/lib"
set no_tar="FALSE"
set copy="FALSE"
if (!(-f $libdir/$xerces_lib)) then
	if (-f $PWD/../$xerces_tar) then
		set xerces_path=$PWD/../$xerces_tar
		set copy="TRUE"
	else if (-f $PWD/$xerces_tar) then
		set xerces_path=$PWD/$xerces_tar
	else if (-f $PWD/../$xerces_lib) then
		set xerces_path=$PWD/../$xerces_lib
		set copy="TRUE"
		set no_tar="TRUE"
	else if (-f $PWD/$xerces_lib) then
		set xerces_path=$PWD/$xerces_lib
		set no_tar="TRUE"
	else
		set xerces_path="NONE"
	endif
	if ($xerces_path != "NONE") then
		echo -n "installing $xerces_lib in $libdir... "
		if ($copy == "TRUE") then
			cp -fu $xerces_path .
		endif
		if ($no_tar == "FALSE") then
			tar xzf $xerces_tar || echo "failed" && exit 1
		endif
		cp $xerces_lib $libdir || echo "failed" && exit 1
		echo "OK"		
	else
		echo "Missing $xerces_tar file. Please consult README file."
	endif
endif

