#!/bin/sh
##########################################################################
# Install script for IBM WebSphere Application Server on                 #
# Linux,LinuxS/390                                                       #
#                                                                        #
# Author: Jared Jurkiewicz, Otto Hammersmith                             #
# Last modified: 11/28/2000                                              #
##########################################################################
# Patch for use with Red Hat Linux  Jul 28, 2001  - Red Hat, Inc.        #
#   David Sainty <dsainty@redhat.com>                                    #
##########################################################################

#
# Simple function for doing a quick-install of db2.
#
  function db2install
  {

    uname -a | grep s390 > /dev/null 2> /dev/null
    if [ $? = 1 ]; then
      rpm -q shlibs > /dev/null 2> /dev/null
  	  if [ $? = 0 ] ; then
	  	  rpm -Uvh ./DB2/*/db2/install/dummyrpm/glibc*.rpm
	  fi
    fi
    ./bin/catgets -c install.mo -n 1 -s "Installing db2 and creating user db2inst1."
    echo ""  #Newline...
    cd DB2/*
    ./db2setup -r ../../silent/db2udbee.rsp
    cd ../..
  }

#
# Simple function to detect language setting and install the right doc RPM
#
  function installdoc
  {
      CURRENT_LANG=`echo $LANG | cut -b 1-5`

      case $CURRENT_LANG in
      	en_US)	rpm -Uvh ./WebSphere/doc/IBMWebAS-*-doc-en-3.5-1.noarch.rpm;;
        ja_JP)  rpm -Uvh ./WebSphere/doc/IBMWebAS-*-doc-ja-3.5-1.noarch.rpm;;
        fr_FR)  rpm -Uvh ./WebSphere/doc/IBMWebAS-*-doc-fr-3.5-1.noarch.rpm;;
        de_DE)  rpm -Uvh ./WebSphere/doc/IBMWebAS-*-doc-de-3.5-1.noarch.rpm;;
        es_ES)  rpm -Uvh ./WebSphere/doc/IBMWebAS-*-doc-es-3.5-1.noarch.rpm;;
        zh_CN)  rpm -Uvh ./WebSphere/doc/IBMWebAS-*-doc-zh-3.5-1.noarch.rpm;;
        zh_TW)  rpm -Uvh ./WebSphere/doc/IBMWebAS-*-doc-zh_tw-3.5-1.noarch.rpm;;
        pt_BR)  rpm -Uvh ./WebSphere/doc/IBMWebAS-*-doc-pt-3.5-1.noarch.rpm;;
        it_IT)  rpm -Uvh ./WebSphere/doc/IBMWebAS-*-doc-it-3.5-1.noarch.rpm;;
        ko_KR)  rpm -Uvh ./WebSphere/doc/IBMWebAS-*-doc-ko-3.5-1.noarch.rpm;;
        *)      rpm -Uvh ./WebSphere/doc/IBMWebAS-*-doc-en-3.5-1.noarch.rpm;; 
      esac

      if [ "${USEDIHS}" = "TRUE" ] ; then
        case $CURRENT_LANG in
          en_US)  rpm -Uvh ./IBM_HTTP_Server/*/IBM_MSG_EN-1.3.12-2.*.rpm;;
          ja_JP)  rpm -Uvh ./IBM_HTTP_Server/*/IBM_MSG_JP-1.3.12-2.*.rpm;;
          fr_FR)  rpm -Uvh ./IBM_HTTP_Server/*/IBM_MSG_FR-1.3.12-2.*.rpm;;
          de_DE)  rpm -Uvh ./IBM_HTTP_Server/*/IBM_MSG_DE-1.3.12-2.*.rpm;;
          es_ES)  rpm -Uvh ./IBM_HTTP_Server/*/IBM_MSG_ES-1.3.12-2.*.rpm;;
          zh_CN)  rpm -Uvh ./IBM_HTTP_Server/*/IBM_MSG_CN-1.3.12-2.*.rpm;;
          zh_TW)  rpm -Uvh ./IBM_HTTP_Server/*/IBM_MSG_TW-1.3.12-2.*.rpm;;
          pt_BR)  rpm -Uvh ./IBM_HTTP_Server/*/IBM_MSG_PT-1.3.12-2.*.rpm;;
          it_IT)  rpm -Uvh ./IBM_HTTP_Server/*/IBM_MSG_IT-1.3.12-2.*.rpm;;
          ko_KR)  rpm -Uvh ./IBM_HTTP_Server/*/IBM_MSG_KO-1.3.12-2.*.rpm;;
          *)      rpm -Uvh ./IBM_HTTP_Server/*/IBM_MSG_EN-1.3.12-2.*.rpm;;
        esac                              
      fi 
  }

#
# Simple function for checking if the proper pre-req of IHS is there (TurboLinux lacks one)
#
function checkIHSprereq
{
  # check if we need the compat RPM...
  uname -a | grep s390 > /dev/null 2> /dev/null
  if [ $? = 1 ]; then
    if [ ! -f /usr/lib/libstdc++.so.2.9 ] ; then
        rpm -Uvh ./IBM_HTTP_Server/*/IBM_turbo_libstdc++_29-1.0-0.i386.rpm
    fi
  fi                                       
}

#
# Simple function for checking if the proper pre-req of IHS is there (TurboLinux lacks it)
#   
function installihs
{
  #Check to make sure we're ok, pre-req wise.
  checkIHSprereq 
   
  # Install it
  ./bin/catgets -c install.mo -n 20 -s "Installing IBM HTTP Server Version 1.3.12.2"
  echo "" #Newline..
  rpm -Uvh ./IBM_HTTP_Server/*/IBM_HTTP_Server-1.3.12-*.rpm
  export USEDIHS=TRUE

}



 
#
# Function for installing custom database.  Prompts user and sets necessary
# environment variables, 
# 
function custominstall
{
  # Set the DB type.
  # need to prompt for this one.  Oracle or DB2, simple enough.

  echo "#################################################"
  while [ "${CUSTOMDBTYPE}" = "" ] ; do
    ./bin/catgets -c install.mo -n 24 -s "Select the database you wish to use and press <ENTER>."
    echo "" #Newline..
    ./bin/catgets -c install.mo -n 34 -s "1.) DB2"
    echo "" #Newline..
    ./bin/catgets -c install.mo -n 35 -s "2.) Oracle"
    echo "" #Newline..
    read CUSTOMDBTYPE
  done
  if [ "${CUSTOMDBTYPE}" = "1" ] ; then
    ./bin/catgets -c install.mo -n 27 -s "DB2 Selected"
    export WAS_LINUX_DBTYPE=DB2
  elif [ "${CUSTOMDBTYPE}" = "2" ] ; then
    ./bin/catgets -c install.mo -n 36 -s "Oracle Selected"
    export WAS_LINUX_DBTYPE=Oracle
  fi
  echo "" #newline
  echo "#################################################" 

  echo ""  #Newline...
  echo "" 
  ./bin/catgets -c install.mo -n 2 -s "WebSphere Custom Repository configuration initiated."
  echo ""  #Newline...
  echo ""
  ./bin/catgets -c install.mo -n 3 -s "Please answer the following questions.  Your responses will be used to configure WebSphere Application Server for your database installation." | fmt
  echo ""  #Newline...
  
  while [ "${CUSTOMUSER}" = "" ] ; do
    ./bin/catgets -c install.mo -n 4 -s "What is your database user id?"
    echo "" #Newline
    ./bin/catgets -c install.mo -n 39 -s "database user id:"
    read CUSTOMUSER
  done
  echo ""
  ./bin/catgets -c install.mo -n 5 -s "Database user: "
  echo " ${CUSTOMUSER}"
  export WAS_LINUX_DBUSER=${CUSTOMUSER}

  while [ "${CUSTOMPASSWORD}" = "" ] ; do
    ./bin/catgets -c install.mo -n 6 -s "What is your database user password? "
    echo ""
    ./bin/catgets -c install.mo -n 41 -s "database user password: " 
    read CUSTOMPASSWORD
  done
  echo ""
  ./bin/catgets -c install.mo -n 7 -s "Database user password: "
  echo ${CUSTOMPASSWORD}
  export WAS_LINUX_DBPASSWORD=${CUSTOMPASSWORD}

  while [ "${CUSTOMHOME}" = "" ] ; do
    ./bin/catgets -c install.mo -n 8 -s "Where is the base database directory/home so the JDBC driver can be located? " | fmt
    echo "" #Newline..
    ./bin/catgets -c install.mo -n 9 -s "Default is: /home/db2inst1/"
    echo "" #Newline..  
    ./bin/catgets -c install.mo -n 37 -s "Database Base Directory:"
    read CUSTOMHOME
    echo ""
    if [ "${CUSTOMHOME}"  = "" ] ; then
	CUSTOMHOME="/home/db2inst1/"
    fi
  done
  export WAS_LINUX_DBHOME=${CUSTOMHOME}
  export WAS_LINUX_DBCLASSPATH=${CUSTOMHOME}

  ./bin/catgets -c install.mo -n 13 -s "What is your JDBC database url?"
  echo "" #Newline...
  ./bin/catgets -c install.mo -n 14 -s "The default is: jdbc:db2:was"
  echo "" #Newline... 
  ./bin/catgets -c install.mo -n 38 -s "Note:  DB2 URL format:  jdbc:db2:<dbname>  Oracle format: jdbc:oracle:thin:@<hostname>:<port>:<sid>" | fmt
  echo "" #Newline..
  ./bin/catgets -c install.mo -n 40 -s "Database JDBC URL:"   
  read CUSTOMURL
  if [ "${CUSTOMURL}" = "" ] ; then 
    CUSTOMURL="jdbc:db2:was"
  fi
  echo ""
  ./bin/catgets -c install.mo -n 15 -s "JDBC URL: "
  echo " $CUSTOMURL"
  export WAS_LINUX_DBURL=$CUSTOMURL
  echo "#################################################" 
}


#####################
# Main script code. #
#####################

cd linux

# Set the NLS location
#setNLSPath

export NLSPATH=${PWD}/locale/%l/%N

#
# Install the JDK.
#
echo "#################################################" 
./bin/catgets -c install.mo -n 16 -s "Installing pre-requisites:  Java:  Version 1.2.2"
echo "" #Newline..
echo "#################################################" 
export JAVA_HOME=/opt/IBMWebAS/IBMJava2-122
rpm --relocate /opt=/opt/IBMWebAS -Uvh ./IBMJava/*.rpm --nodeps
echo ""

################################################################
# Addition by Red Hat, Inc.  David Sainty <dsainty@redhat.com> #
################################################################

export COMPAT_LIBDIR="\/usr\/s390-glibc21-linux\/lib"

mkdir $JAVA_HOME/jre/bin/rh-backup
cp -d $JAVA_HOME/jre/bin/{java,javaw,jvmtcf,keytool,policytool,rmid,rmiregistry} $JAVA_HOME/jre/bin/rh-backup/.
for loop in javaw jvmtcf keytool policytool rmid rmiregistry java
do
  sed "s/\(\$DEBUG_PROG\) \(\"\$prog\" \"\$\@\"\)/\1 $COMPAT_LIBDIR\/ld.so.1 --library-path $COMPAT_LIBDIR:\$LD_LIBRARY_PATH \2/" < $JAVA_HOME/jre/bin/${loop} > $JAVA_HOME/jre/bin/${loop}_new
  mv -f $JAVA_HOME/jre/bin/${loop}_new $JAVA_HOME/jre/bin/${loop}
  chmod 0755 $JAVA_HOME/jre/bin/${loop}
done

mkdir $JAVA_HOME/bin/rh-backup
cp -d $JAVA_HOME/bin/{appletviewer,extcheck,idlj,jar,jarsigner,javac,javadoc,javah,javap,jdb,native2ascii,rmic,serialver} $JAVA_HOME/bin/rh-backup/.
for loop in appletviewer extcheck idlj jar jarsigner javac javadoc javah javap jdb native2ascii rmic serialver
do
  sed "s/\(\$DEBUG_PROG\) \(\"\$prog\" \"\$\@\"\)/\1 $COMPAT_LIBDIR\/ld.so.1 --library-path $COMPAT_LIBDIR:\$LD_LIBRARY_PATH \2/" < $JAVA_HOME/bin/${loop} > $JAVA_HOME/bin/${loop}_new
  mv -f $JAVA_HOME/bin/${loop}_new $JAVA_HOME/bin/${loop}
  chmod 0755 $JAVA_HOME/bin/${loop}
done

###################
# End of Addition #
###################

#
# Query user for using IHS, install if necessary
#
./bin/catgets -c install.mo -n 17 -s "Install and use IBM HTTP Server?  [default is yes]"
echo "" #Newline..
./bin/catgets -c install.mo -n 18 -s "1.) Yes"
echo "" #Newline..
./bin/catgets -c install.mo -n 19 -s "2.) No"
echo "" #Newline..
read INSTALLIHS

if [ "$INSTALLIHS" = "1" ]; then
  echo ""
  installihs
else
    if [ "${INSTALLIHS}" = "2" ]; then
    ./bin/catgets -c install.mo -n 21 -s "Not Installing IBM HTTP Server Version 1.3.12.2"
    echo "" #Newline..
    else
      if [ "${INSTALLIHS}" = "" ]; then
         installihs
      else
        ./bin/catgets -c install.mo -n 21 -s "Not Installing IBM HTTP Server Version 1.3.12.2"
        echo "" #Newline..
        ./bin/catgets -c install.mo -n 22 -s "Unknown option."
        echo "" #Newline..
	./bin/catgets -c install.mo -n 23 -s "Exiting install script..."
        echo "" #Newline..
        exit
      fi     
    fi
fi
echo ""
echo "#################################################" 
if [ -d DB2 ] ; then
#
# Query user which database to use and exec install function for that db.
#
./bin/catgets -c install.mo -n 24 -s "Select the database you wish to use and press <ENTER>."
echo "" #Newline..
./bin/catgets -c install.mo -n 25 -s "1.) DB2 Quick Install [default]"
echo "" #Newline..
./bin/catgets -c install.mo -n 26 -s "2.) Custom"
echo "" #Newline..
read DBTYPE

if [ "${DBTYPE}" = "1" ]; then
#  echo "DB2 Selected"
  ./bin/catgets -c install.mo -n 27 -s "DB2 Selected"
  echo "" #Newline..
  db2install
  export DBNAME=WAS
  export DBHOME=/home/db2inst1

else
  if [ "${DBTYPE}" = "" ]; then
    ./bin/catgets -c install.mo -n 27 -s "DB2 Selected"
    echo "" #Newline..
    db2install
    export DBNAME=WAS
    export DBHOME=/home/db2inst1
  else 
    if [ "${DBTYPE}" = "2" ]; then
      ./bin/catgets -c install.mo -n 28 -s "Custom Selected"
      echo "" #Newline..
      custominstall
    else 
	if [ "${DBTYPE}" = "3" ]; then
	./bin/catgets -c install.mo -n 29 -s "InstantDB Selected"
        echo "" #Newline..
	export WAS_LINUX_DBTYPE=InstantDB
	export WAS_LINUX_DBURL=jdbc:idb:/opt/IBMWebAS/bin/was.prp
        export WAS_LINUX_DBDRIVER=jdbc.idbDriver
	else
		./bin/catgets -c install.mo -n 30 -s "Unknown option."
                echo "" #Newline..
		./bin/catgets -c install.mo -n 31 -s "Exiting install script..."
                echo "" #Newline..
      		exit
	fi
    fi
  fi
fi
fi

#
# Now install WAS, all needed environment settings should be set.
#
echo ""
./bin/catgets -c install.mo -n 32 -s "Installing IBM WebSphere Application Server for Linux"
echo "" #Newline..
rpm -Uvh ./WebSphere/*.rpm
if [ "${DBNAME}" = "WAS" ]; then
	su db2inst1 -c /opt/IBMWebAS/bin/createdb2.sh
fi

#
# Install the language specific doc rpm
#
installdoc
#sleep 3
echo "#################################################" 
echo ""
./bin/catgets -c install.mo -n 33 -s "IBM WebSphere Application Server for Linux installation is complete.  Please run startupServer.sh in /opt/IBMWebAS/bin to invoke the server.  Also, please restart your webserver if you selected IHS at this time to ensure the plugin configuration is updated.  If you installed with Apache, please refer to the install documentation for configuration information." | fmt
echo "" #Newline..
echo "#################################################" 
# Install debugger...
if [ -d IBMDebug ]; then
  rpm -Uvh --nodeps IBMDebug/*.rpm
fi

cd ..
