#! /bin/sh
# $Header: install_dbext.sh,v 1.28 2000/01/04 18:31:14 rjk Stab $
 #bcpyrght
 echo "
 ****************************************************************************
 *                                                                          *
 * Copyright 1993 - 1999 VERITAS Software Corporation, All Rights Reserved  *
 *                                                                          *
 ****************************************************************************
 "
 #ecpyrght

MYNAME=`basename $0`

RELEASE=YYYYY

# Make sure this is being run from root.
 
ISROOT=`/usr/bin/id | egrep "^uid=0\("`
if [ "${ISROOT}" = "" ]
then
	echo ""
	echo "This must be run while logged in as root."
	echo ""
	exit 1
fi

CWD=`pwd`
CALL_path=`dirname $0`
ECHO=echo
 
# Confirm an action with yes as the default
#
#       confirm prompt_string
#
#       Returns 0 for yes and 1 if else
 
confirm () {
        echo "$1 (y/n) \c "
        read ans
        case $ans in
                Y*|y*)
                        echo
                        return 0
                        ;;
                *)
                        echo
                        return 1
                        ;;
        esac
}

untar_image()
{
	echo ""
	echo "Extracting files from $1 ..."
	MACHINE=`echo $1 | awk -F. '{print $2}'` 

	case "$MACHINE" in
		hp* | rs6000* )
			/bin/tar -xvpf $1
			;;
		alpha)
			/bin/tar xvbpf 20 $1 
			;;
		solaris* | sequent42 | ncr | dgux )
			/bin/tar -xvpof $1
			;;
		sgi)
			/bin/tar -xvpbf 20 $1
			;;
		*)
			echo "unsupported platform"
			;;
	esac
}

get_tar_dir () {
	echo "
No database extension tar files found in $TARPATH directory."

	while true; do
		if confirm "Do you want to continue?"
		then 
			echo "Enter a directory where tar files are located: \c"
			read TARPATH
			if [ -d "$TARPATH" ]
			then
				cd $TARPATH
				return 0
			else
				echo "Directory $TARPATH does not exist"
			fi
		else
			echo "No database extension packages were installed."
			return 1 
		fi
	done
}

print_title() {
	if [ $package_found -eq 0 ]
	then
		echo "
Found packages to install NetBackup for\c"
	fi
	
}

# script runs on the client side, then we can
# get platform info from /usr/openv/netbackup/bin/version file

TARPATH=`pwd`
if [ -f /usr/openv/netbackup/bin/version ] 
then
 	MACHINE=`head -1 /usr/openv/netbackup/bin/version | cut -f2 -d-`
	case "$MACHINE" in
		HP*)
			PLATFORM=hp800
			;;
		AIX*)
			PLATFORM=rs6000
			;;
		Solaris*)
			PLATFORM=solaris
			;;
		OSF1*)
			PLATFORM=alpha
			;;
		DYNIX*)
			PLATFORM=sequent42
			;;
		IRIX*)
			PLATFORM=sgi
			;;
		UNIX*)
			unix_level=`uname -s`
			if [ "${unix_level}" = "dgux" ]; then
				PLATFORM=dgux
			else 
				PLATFORM=ncr
			fi
			;;
		*)
			echo "WARNING: Platform $MACHINE is not supported."
			PLATFORM=nosupport
			;;
	esac	
else
	echo "/usr/openv/netbackup/bin/version not found."
	echo "Aborted."
	exit 1
fi

# Look for tar files for PLATFORM

echo "
	NetBackup Database Extensions Installation"

while true; do
	lotus_tar=`ls LOTUS.$PLATFORM.tar 2>/dev/null`
	syb_tar=`ls SYBASE.$PLATFORM.tar 2>/dev/null`
	inf_tar=`ls INFORMIX.$PLATFORM.tar 2>/dev/null`
	bt_tar=`ls BACKTRACK.$PLATFORM.tar 2>/dev/null`
	db2_tar=`ls DB2.$PLATFORM.tar 2>/dev/null`
	td_tar=`ls TERADATA.$PLATFORM.tar 2>/dev/null`

	if [ "${PLATFORM}" = "solaris" ]; then
		os_level=`uname -r | cut -c1-3`
		if [ "${os_level}" = "5.6" -o "${os_level}" = "5.7" ] ; then
			oebu_tar=`ls OEBU.${PLATFORM}_26.tar 2>/dev/null`
			sap_tar=`ls SAP.${PLATFORM}_26.tar 2>/dev/null`
			proxy_tar=`ls PROXY.${PLATFORM}_26.tar 2>/dev/null`
			lotus_tar=`ls LOTUS.${PLATFORM}_26.tar 2>/dev/null`
		else
			oebu_tar=`ls OEBU.$PLATFORM.tar 2>/dev/null`
			sap_tar=`ls SAP.$PLATFORM.tar 2>/dev/null`
		fi
	elif [ "${PLATFORM}" = "rs6000" ]; then
		os_level=`uname -r | cut -c1`
		if [ "${os_level}" = "2" -o "${os_level}" = "3" ] ; then
			sap_tar=`ls SAP.${PLATFORM}_42.tar 2>/dev/null`
		else
			sap_tar=`ls SAP.$PLATFORM.tar 2>/dev/null`
		fi
		oebu_tar=`ls OEBU.$PLATFORM.tar 2>/dev/null`
	elif [ "${PLATFORM}" = "hp800" ]; then
		os_level=`uname -r | cut -c3-4`
		if [ "${os_level}" = "11" ] ; then
			os_bits=`getconf _CS_KERNEL_BITS`
			if [ "${os_bits}" = "64" ] ; then
				oebu_tar=`ls OEBU.hp11_64.tar 2>/dev/null`
				if [ -n "$inf_tar" ] ; then
					inf_tar_hp_64=`ls INFORMIX.hp11_64.tar 2>/dev/null`
				else
					inf_tar=`ls INFORMIX.hp11_64.tar 2>/dev/null`
				fi
			else 
				oebu_tar=`ls OEBU.$PLATFORM.tar 2>/dev/null`
				proxy_tar=`ls PROXY.hp11.tar 2>/dev/null`
			fi
		else	
			oebu_tar=`ls OEBU.$PLATFORM.tar 2>/dev/null`
		fi
		sap_tar=`ls SAP.$PLATFORM.tar 2>/dev/null`
	else 
		oebu_tar=`ls OEBU.$PLATFORM.tar 2>/dev/null`
		sap_tar=`ls SAP.$PLATFORM.tar 2>/dev/null`
	fi
 
	package_found=0

	if [ -n "$oebu_tar" ]
	then 
		print_title
		echo "	Oracle"
		package_found=1
	fi
	if [ -n "$bt_tar" ]
	then 
		print_title
		echo "	SQL-BackTrack"
		package_found=1
	fi
	if [ -n "$sap_tar" ]
	then 
		print_title
		echo "	SAP"
		package_found=1
	fi
	if [ -n "$inf_tar" ]
	then 
		print_title
		echo "	Informix"
		package_found=1
	fi
	if [ -n "$syb_tar" ]
	then 
		print_title
		echo "	Sybase"
		package_found=1
	fi
	if [ -n "$db2_tar" ]
	then 
		print_title
		echo "	DB2"
		package_found=1
	fi
	if [ -n "$td_tar" ]
	then 
		print_title
		echo "	Teradata"
		package_found=1
	fi
	if [ -n "$proxy_tar" ]
	then 
		print_title
		echo "	Oracle on UNIX Advanced BLI Agent"
		package_found=1
	fi
	if [ -n "$lotus_tar" ]
	then 
		print_title
		echo "	Lotus Notes"
		package_found=1
	fi
	if [ $package_found -eq 0 ]
	then
		if  get_tar_dir
		then
			: 
		else
			exit 0
		fi
	else
		break
	fi
done

echo ""
oebu_inst=0
if [ -n "$oebu_tar" ]
then 
	if confirm "Do you want to install NetBackup for Oracle?"
	then 	
		oebu_inst=1
	fi
fi

bt_inst=0
if [ -n "$bt_tar" ]
then 
	if confirm "Do you want to install NetBackup for SQL-BackTrack?"
	then 	
		bt_inst=1
	fi
fi

sap_inst=0
if [ -n "$sap_tar" ]
then 
	if confirm "Do you want to install NetBackup for SAP?"
	then 	
		sap_inst=1
	fi
fi

proxy_inst=0
if [ -n "$proxy_tar" ]
then 
	if confirm "Do you want to install NetBackup for Oracle on UNIX Advanced BLI Agent ?"
	then 	
		proxy_inst=1
	fi
fi

inf_inst=0
if [ -n "$inf_tar" ]
then 
	if confirm "Do you want to install NetBackup for Informix?"
	then 	
		if [ -n "$inf_tar_hp_64" ]
		then
			if confirm "Do you want to install the 64 bit version of NetBackup for Informix?"
			then
				inf_tar=$inf_tar_hp_64
			fi
		fi
		inf_inst=1
	fi
fi
	
syb_inst=0
if [ -n "$syb_tar" ]
then 
	if confirm "Do you want to install NetBackup for Sybase?"
	then 	
		syb_inst=1
	fi
fi

db2_inst=0
if [ -n "$db2_tar" ]
then 
	if confirm "Do you want to install NetBackup for DB2?"
	then 	
		db2_inst=1
	fi
fi

td_inst=0
if [ -n "$td_tar" ]
then 
	if confirm "Do you want to install NetBackup for Teradata?"
	then 	
		td_inst=1
	fi
fi

lotus_inst=0
if [ -n "$lotus_tar" ]
then 
	if confirm "Do you want to install NetBackup for Lotus Notes?"
	then 	
		lotus_inst=1
	fi
fi

#---- untar and run installation scripts if exist
cd /

if [ $oebu_inst -eq 1 ] 
 then	
	echo ""
	echo "   Installing NetBackup for Oracle..."
	untar_image $TARPATH/$oebu_tar
	RET_STATUS=$?
	if [ $RET_STATUS -ne 0 ]
	then
		echo "NetBackup for Oracle installation failed."
	else
		if [ ! -d /usr/openv/netbackup/logs/user_ops ]; then
			mkdir -p /usr/openv/netbackup/logs/user_ops
			chmod 777 /usr/openv/netbackup/logs
			chmod 1777 /usr/openv/netbackup/logs/user_ops
		fi	
		echo ""
		echo "NetBackup for Oracle installation completed."
	fi
fi

if [ $bt_inst -eq 1 ]
then	
	echo ""
	echo "   Installing NetBackup for SQL-BackTrack..."
	untar_image $TARPATH/$bt_tar
	if [ -f	/usr/openv/netbackup/bin/install_obsi ]
	then
		 /usr/openv/netbackup/bin/install_obsi
		 RET_STATUS=$?
	else
		echo ""
		echo "WARNING: /usr/openv/netbackup/bin/install_obsi is not found."
		 RET_STATUS=1
	fi
	if [ $RET_STATUS -ne 0 ]
	then
		echo ""
		echo "NetBackup for SQL-BackTrack installation failed."
	else
		if [ ! -d /usr/openv/netbackup/logs/user_ops ]; then
			mkdir -p /usr/openv/netbackup/logs/user_ops
			chmod 777 /usr/openv/netbackup/logs
			chmod 1777 /usr/openv/netbackup/logs/user_ops
		fi	
		echo ""
		echo "NetBackup for SQL-BackTrack installation completed."
	fi
fi

if [ $sap_inst -eq 1 ]
then	
	echo ""
	echo "   Installing NetBackup for SAP..." 
	untar_image $TARPATH/$sap_tar
	RET_STATUS=$?
	if [ $RET_STATUS -ne 0 ]
	then
		echo ""
		echo "NetBackup for SAP installation failed."
	else
		echo ""
		echo "NetBackup for SAP installation completed."
	fi
fi

if [ $inf_inst -eq 1 ]
then	
	echo ""
	echo "   Installing NetBackup for Informix..."
	untar_image $TARPATH/$inf_tar
	if [ -f /usr/openv/netbackup/bin/install_infxbsa ]
	then
		/usr/openv/netbackup/bin/install_infxbsa
		 RET_STATUS=$?
	else
		echo ""
		echo "WARNING: /usr/openv/netbackup/bin/install_infxbsa is not found."
		RET_STATUS=1
	fi
	if [ $RET_STATUS -ne 0 ]
	then
		echo ""
		echo "NetBackup for Informix installation failed."
	else
		echo ""
		echo "NetBackup for Informix installation completed."
	fi
fi

if [ $syb_inst -eq 1 ]
then	
	echo ""
	echo "   Installing NetBackup for Sybase..."
	untar_image $TARPATH/$syb_tar
	if [ -f /usr/openv/netbackup/bin/install_sybackup ]
	then
		/usr/openv/netbackup/bin/install_sybackup
		 RET_STATUS=$?
	else
		echo ""
		echo "WARNING: /usr/openv/netbackup/bin/install_sybackup is not found."
		RET_STATUS=1
	fi
	if [ $RET_STATUS -ne 0 ]
	then
		echo ""
		echo "NetBackup for Sybase installation failed."
	else
		echo ""
		echo "NetBackup for Sybase installation completed."
		
	fi
fi

if [ $db2_inst -eq 1 ]
then	
	echo ""
	echo "   Installing NetBackup for DB2..."
	untar_image $TARPATH/$db2_tar
	RET_STATUS=$?
	if [ $RET_STATUS -eq 0 ] 
	then
		if [ -f /usr/openv/netbackup/bin/install_db2 ]
		then
			/usr/openv/netbackup/bin/install_db2
			 RET_STATUS=$?
		else
			echo ""
			echo "WARNING: /usr/openv/netbackup/bin/install_db2 is not found."
			RET_STATUS=1
		fi
	fi
	if [ $RET_STATUS -ne 0 ]
	then
		echo ""
		echo "NetBackup for db2 installation failed."
	else
		if [ ! -d /usr/openv/netbackup/logs/user_ops ]; then
			mkdir -p /usr/openv/netbackup/logs/user_ops
			chmod 777 /usr/openv/netbackup/logs
			chmod 1777 /usr/openv/netbackup/logs/user_ops
		fi	
		echo ""
		echo "NetBackup for db2 installation completed."
		
	fi
fi

if [ $td_inst -eq 1 ] 
 then	
	echo ""
	echo "   Installing NetBackup for Teradata..."
	untar_image $TARPATH/$td_tar
	RET_STATUS=$?
	if [ $RET_STATUS -eq 0 ] 
	then

	if [ ! -d /usr/openv/netbackup/logs/user_ops ]; then
		mkdir -p /usr/openv/netbackup/logs/user_ops
		chmod 777 /usr/openv/netbackup/logs
		chmod 1777 /usr/openv/netbackup/logs/user_ops
	fi	

CREATE_DIR_LIST="/usr/openv/netbackup/logs/user_ops/Teradata
/usr/openv/netbackup/logs/user_ops/Teradata/logs
/usr/openv/netbackup/logs/user_ops/Teradata/jobs
/usr/openv/netbackup/ext/db_ext/NCR_Teradata/arclogs
/usr/openv/netbackup/ext/db_ext/NCR_Teradata/history
/usr/openv/netbackup/ext/db_ext/NCR_Teradata/scripts
/usr/openv/netbackup/ext/db_ext/NCR_Teradata/tmp"

		create_dir_error=0	
		for CREATE_DIR in $CREATE_DIR_LIST;do 
			if [ ! -d $CREATE_DIR ]; then
				/bin/mkdir $CREATE_DIR
				if [ $? -ne 0 ]; then
					echo "ERROR - creating $CREATE_DIR "
					create_dir_error=1	
				else
					echo "Completed creating $CREATE_DIR "
				fi
			fi
			/bin/chmod 777 $CREATE_DIR 
		done

		if [ $create_dir_error -eq 0 ]; then
			echo ""
			echo "NetBackup for Teradata installation successful."
		else 
			echo ""
			echo "NetBackup for Teradata installation failed."
		fi
	else
		echo ""
		echo "NetBackup for Teradata installation failed."
	fi
fi

if [ $proxy_inst -eq 1 ] 
then	
	echo ""
	echo "   Installing NetBackup for Oracle on UNIX Advanced BLI Agent ..."
	untar_image $TARPATH/$proxy_tar
	RET_STATUS=$?
	if [ $RET_STATUS -eq 0 ] 
	then
		if [ -f /usr/openv/netbackup/bin/install_oracle ]
		then
			/usr/openv/netbackup/bin/install_oracle
			 RET_STATUS=$?
		else
			echo ""
			echo "WARNING: /usr/openv/netbackup/bin/install_oracle is not found."
			RET_STATUS=1
		fi
	fi
	if [ $RET_STATUS -ne 0 ]
	then
		echo ""
		echo "NetBackup for Oracle on UNIX Advanced BLI Agent installation failed."
	else
		echo ""
		echo "NetBackup for Oracle on UNIX Advanced BLI Agent installation completed."
	fi
fi

if [ $lotus_inst -eq 1 ] 
then	
	echo ""
	echo "   Installing NetBackup for Lotus Notes ..."
	untar_image $TARPATH/$lotus_tar
	RET_STATUS=$?
	if [ $RET_STATUS -ne 0 ]
	then
		echo ""
		echo "NetBackup for Lotus Notes installation failed."
	else
		echo ""
		echo "NetBackup for Lotus Notes installation completed."
	fi
fi

echo ""
exit 0
