#!/bin/bash
##################################################################
### copyright 2002 Compaq Information Technologies Group, L.P. ###
##################################################################

#/sbin/lsmod | grep cpqasm >/dev/null 2>&1
ps -ef | grep hpasmd | grep -v grep >/dev/null 2>&1
if [ $? -eq 1 ]; then
   echo "ERROR: $0 requires the module hpasmd to be running"
   exit 1
fi


if [ "$DISPLAY" = "" ]; then
   if [ -f /sbin/hpimlview ]; then
      KBDMODE=`kbd_mode | awk '{print $(NF-1)}' | tr -d '()'`
      if [ "$KBDMODE" = "UTF-8" ]; then
         unicode_stop
      fi
      /sbin/hpimlview
      if [ "$KBDMODE" = "UTF-8" ]; then
         unicode_start
      fi
   fi
   exit 0
fi

#First off, we need to find libtclx.so
LIBTCLX=`rpm -ql tclx 2> /dev/null | egrep "/libtclx.*\.so$" | tail -n 1`
#if this fails, we cross our fingers and pass in "-", i.e. whatever 
#"package requires" gives us
if [ -z "$LIBTCLX" ]; then
	LIBTCLX="-"
fi

#Next locate tixwish
WISH=`which tixwish 2>/dev/null`
if [ -z "$WISH" ]; then
	WISH=`rpm -ql tix 2> /dev/null | egrep "/tixwish[^\.].*$" | tail -n 1`
fi

#We found tixwish, execute with -tclx	
if [ ! -z "$WISH" ]; then
	$WISH /sbin/cpqimlview.tcl -tclx "$LIBTCLX"
	exit $? 
fi

#Find libtix.so
LIBTIX=`rpm -ql tix 2> /dev/null | egrep "/libtix.*\.so$" | tail -n 1`
#if this fails, we cross our fingers and pass in "-", i.e. whatever 
#"package requires" gives us
if [ -z "$LIBTIX" ]; then
	LIBTIX="-"
fi

#Next locate wish
WISH=`which wish 2>/dev/null`
if [ -z "$WISH" ]; then
	WISH=`rpm -ql tk 2> /dev/null | egrep "/wish[^\.].*$" | tail -n 1`
fi

#We found wish, execute with -tclx AND -tix
if [ ! -z "$WISH" ]; then
	$WISH /sbin/cpqimlview.tcl -tclx "$LIBTCLX" -tix "$LIBTIX"
	exit $? 
fi

#Error
echo "ERROR: wish/tixwish not found."
echo "tcl/tk must be installed to use the IML viewer."
echo "The viewer also uses the tclX and tix extensions."
exit 1
