#!/bin/ksh
#
# @(#)95	1.2  bin/zf-custom-install, zf_build, zf-2.3, 2.5.1.5 9/15/98 20:53:43

set -e

usage()
{
	if (( $# )) ; then
		print "$@\n" 1>&2
	fi

	cat 1>&2 <<- EOF
		usage: zf-custom-install <installp file> <target_dir>

		For example:
		
		  zf-custom-install /tmp/ZeroFault.aix41.obj /usr/local/zf
		
		will install ZeroFault in /usr/local/zf.

		Note that you must set the ZF_HOME environment variable to
		the target directory.
	EOF
	exit 1
}

[[ $# != 2 ]] && usage

install_file="$1"
target_dir="$2"

case $install_file in
        /*)
                ;;
        *)        
                install_file=`pwd`/$install_file
                ;;
esac

[[ ! -d ${target_dir} ]] && usage target directory is not a directory
[[ ! -w ${target_dir} ]] && usage target directory is not writeable
cd ${target_dir}
target_dir=$(/bin/pwd)

mkdir /tmp/zf.$$
[[ $? != 0 ]] && {
        print "can't mkdir /tmp/zf.$$" 1>&2
        exit 1 
}
cd /tmp/zf.$$
restore -xvqf ${install_file}
[[ $? != 0 ]] && {
        print "error restoring install image" 1>&2
        exit 1
}

cp -rp usr/lpp/ZeroFault/* ${target_dir}
rm -f ${target_dir}/liblpp.a
mkdir ${target_dir}/app-defaults
cp -p usr/lpp/X11/lib/X11/app-defaults/zf ${target_dir}/app-defaults

cd /
rm -rf /tmp/zf.$$

cat <<- EOF

	The following environment variables must be set for ZeroFault
	to run properly.  These should probably be set in the /etc/profile
	or each user's .profile:

	export ZF_HOME=${target_dir}
	export PATH=\$PATH:${target_dir}/bin
	export XAPPLRESDIR=\$XAPPLRESDIR:${target_dir}/app-defaults
EOF
