#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# websm720 src/sysmgt/cfgassist/com/ibm/cfgassist/apps/wsmconfig/config.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1998,2011 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)72	1.1  src/sysmgt/cfgassist/com/ibm/cfgassist/apps/wsmconfig/config.sh, cfgassist, websm720 7/14/11 20:43:49
configprelim()
{
       print "RETURN=<p>"

    tmp_msg=$(echo "$(dspmsg configsh.cat -s 1 1 'Note:  To complete your migration installation from CD_ROM, you must update additional installed software. Select "Update installed software after a migration installation."')") 

    tmp_method=$(grep INSTALL_DEVICE /var/adm/sw/__assistinfo |grep -v '^#' |grep -E "/dev/cd")

    # In this release, migration update is unnecessary
    #if [[ $tmp_method != "" ]]; then
    #   print "tmp_msg="$tmp_msg
    #else
    #   print "tmp_msg=&rbl;"
    #fi

    print "tmp_msg=&rbl;"

}

nav2()
{
#Must do some discovery of system environment to determine next page
#Table of contents
   if [[ $1 = "p3" ]]; then

      value=$(date +"%m%d%Y")
      print "defdate="$value

      #Necessary to prevent translation by CMVC
      format=%H
      format=$format%M
      format=$format%S

      value=$(date +"$format")
      print "deftime="$value
 
      value=$(/usr/bin/locale -k LC_TIME | grep '^mon' | cut -f2 -d'=' | sed "s/\";\"/,/g" | cut -f2 -d'"')
      print "allmonth="$value

tzdst=$(echo "$(dspmsg smit.cat -s 30 7 '(CUT0GDT)           Coordinated Universal Time   (CUT)\n\
(GMT0BST)           United Kingdom               (CUT)\n\
(AZOREST1AZOREDT)   Azores; Cape Verde        (CUT -1)\n\
(FALKST2FALKDT)     Falkland Islands          (CUT -2)\n\
(GRNLNDST3GRNLNDDT) Greenland; East Brazil    (CUT -3)\n\
(AST4ADT)           Central Brazil            (CUT -4)\n\
(EST5EDT)           Eastern U.S.; Colombia    (CUT -5)\n\
(CST6CDT)           Central U.S.; Honduras    (CUT -6)\n\
(MST7MDT)           Mountain U.S.             (CUT -7)\n\
(PST8PDT)           Pacific U.S.; Yukon       (CUT -8)\n\
(AST9ADT)           Alaska                    (CUT -9)\n\
(HST10HDT)          Hawaii; Aleutian          (CUT-10)\n\
(BST11BDT)          Bering Straits            (CUT-11)\n\
(NZST-12NZDT)       New Zealand               (CUT+12)\n\
(MET-11METDT)       Solomon Islands           (CUT+11)\n\
(EET-10EETDT)       Eastern Australia         (CUT+10)\n\
(JST-9JDT)          Japan                     (CUT +9)\n\
(KORST-9KORDT)      Korea                     (CUT +9)\n\
(WAUST-8WAUDT)      Western Australia         (CUT +8)\n\
(TAIST-8TAIDT)      Taiwan                    (CUT +8)\n\
(BEIST-8BEIDT)      Peoples Rep. China        (CUT +8)\n\
(THAIST-7THAIDT)    Thailand                  (CUT +7)\n\
(NOVST-6NOVDT)      Novosibirsk, Russia       (CUT +6)\n\
(PAKST-5PAKDT)      Pakistan                  (CUT +5)\n\
(WST-4WDT)          Gorki; Central Asia; Oman (CUT +4)\n\
(MEST-2MEDT)        Turkey                    (CUT +2)\n\
(SAUST-3SAUDT)      Saudi Arabia              (CUT +3)\n\
(WET-2WET)          Finland                   (CUT +2)\n\
(USAST-2USADT)      South Africa              (CUT +2)\n\
(NFT-1DFT)          Norway; France            (CUT +1)')")

tznodst=$(echo "$(dspmsg smit.cat -s 30 22 '(CUT0)           Coordinated Universal Time   (CUT)\n\
(GMT0)           United Kingdom               (CUT)\n\
(AZOREST1)       Azores; Cape Verde        (CUT -1)\n\
(FALKST2)        Falkland Islands          (CUT -2)\n\
(GRNLNDST3)      Greenland; East Brazil    (CUT -3)\n\
(AST4)           Central Brazil            (CUT -4)\n\
(EST5)           Eastern U.S.; Colombia    (CUT -5)\n\
(CST6)           Central U.S.; Honduras    (CUT -6)\n\
(MST7)           Mountain U.S.             (CUT -7)\n\
(PST8)           Pacific U.S.; Yukon       (CUT -8)\n\
(AST9)           Alaska                    (CUT -9)\n\
(HST10)          Hawaii; Aleutian          (CUT-10)\n\
(BST11)          Bering Straits            (CUT-11)\n\
(NZST-12)        New Zealand               (CUT+12)\n\
(MET-11)         Solomon Islands           (CUT+11)\n\
(EET-10)         Eastern Australia         (CUT+10)\n\
(JST-9)          Japan                     (CUT +9)\n\
(KORST-9)        Korea                     (CUT +9)\n\
(WAUST-8)        Western Australia         (CUT +8)\n\
(TAIST-8)        Taiwan                    (CUT +8)\n\
(BEIST-8)        Peoples Rep. China        (CUT +8)\n\
(THAIST-7)       Thailand                  (CUT +7)\n\
(NOVST-6)        Novosibirsk, Russia       (CUT +6)\n\
(PAKST-5)        Pakistan                  (CUT +5)\n\
(WST-4)          Gorki; Central Asia; Oman (CUT +4)\n\
(MEST-2)         Turkey                    (CUT +2)\n\
(SAUST-3)        Saudi Arabia              (CUT +3)\n\
(WET-2)          Finland                   (CUT +2)\n\
(USAST-2)        South Africa              (CUT +2)\n\
(NFT-1)          Norway; France            (CUT +1)')")

ENVFILE=/etc/environment
#  Get value of TZ variable from /etc/environment
#  If not defined then set zone to unknown
#  and set DST start and end to U.S. defaults

if egrep '^TZ=' $ENVFILE >/dev/null 2>&1; then
    egrep '^TZ=' $ENVFILE | while read var ; do
        tzvar=$var
    done
else
    tzvar=
fi
MTZ=${tzvar#TZ=}
MTZ="($MTZ)"
print "tz"=$MTZ

      valuedst=$(echo "$tzdst" | awk '{printf("%s!",$0);}')
      valuenodst=$(echo "$tznodst" | awk '{printf("%s!",$0);}')
      value=$valuedst
      value1=$(echo "$tzdst" | grep $MTZ)

      if [[ $? = 1 ]]; then
        # tz not found in dst list
        value1=$(echo "$tznodst" | grep $MTZ)
        if [[ $? = 1 ]]; then
          # tz not found in no dst list, add it
          value=$value$MTZ
          value1=$MTZ
        else
          value=$valuenodst
        fi
      fi
      print "deftz="$value1
      print "alltz="$value


      value=$(locale -k LC_TIME | grep '^d_fmt' | cut -f2 -d'=' | cut -f2 -d'"')
     
      if [ $(echo "$value" | grep ".*m.*d.*[yY]") ]; then
	print "datetype="1
      elif [ $(echo "$value" | grep ".*d.*m.*[yY]") ]; then
	print "datetype="2
      elif [ $(echo "$value" | grep ".*[yY].*m.*d") ]; then
	print "datetype="3
      else
        print "datetype="1
      fi 

      value=$(locale -k LC_TIME | grep '^t_fmt=' | cut -f2 -d'=' | cut -f2 -d'"' | cut -c-2)
      if [[ $value = "%I" ]]; then
        print "timetype="1
      elif [[ $value = "%H" ]]; then
        print "timetype="2
      else
        print "timetype="1
      fi

      print "RETURN=p4"
      print "p2var=password"

   elif [[ $1 = "password" ]]; then
      
      print "RETURN=password"
      print "p2var=tcpip"

   elif [[ $1 = "tcpip" ]]; then
     #Discover preliminary TCPIP information
     
     allni=$(/usr/sbin/lsdev -Cc if -F "name  location  description" | grep -v '^lo' | grep -v '^cti' | grep -v '^so' | grep -v '^ca' | grep -v '^es' | sort | awk '{printf("%s,",$0);}')
     print "allni="$allni
     
     allni2=$(echo "`/bin/dspmsg -s 4 smit.cat 488 'any     Use the first available interface'`,$(/usr/sbin/lsdev -Cc if -F "name  location  description" | grep -v '^lo' | grep -v '^cti' | grep -v '^so' | grep -v '^ca' | grep -v '^es' | sort | awk '{printf("%s,",$0);}' )")
     print "allni2="$allni2

     s_ni2=`netstat -rn | grep default | grep -v "link" | awk '{printf "%s,",$6}'`
     s_ni2=${s_ni2%%,*}
     if [ -z ${s_ni2} ]; then
        s_ni2=$(/usr/sbin/lsdev -Cc if -S a -F "name  location  description"| grep -v '^lo' |grep -v "^cti" grep -v "^so" | grep -v "^ca" | grep -v "^es" | awk '{printf "%s,",$0}')
        s_ni2=${s_ni2%%,*}
     fi
     if [ -z ${s_ni2} ]; then
        lssrc -s dhcpcd | grep active >/dev/null
        RC=$?
        if [[ $RC -eq 0 ]] ; then
         s_ni2=`lssrc -ls dhcpcd | grep -v "^Log" | grep -v "^Tracing" | grep -v "^ " | grep -v "^Subsystem" | grep -v dhcpcd | grep -v "^Interface" | awk '{printf "%s,",$1}'`
         s_ni2=${s_ni2%%,*}
        fi
     fi
     if [ -n "$s_ni2" ]; then
        s_ni=`lsdev -Cc if -F "name  location  description" | grep $s_ni2`
     elif [ -n "$allni" ]; then
        s_ni=${allni%%,*}
     else  # last ditch effort to avoid exception.
        allni="lo0 Loopback Network Interface"
        s_ni="$allni"
     fi
     print "s_ni="$s_ni
     
     devName=""
     print "devName="$devName
     
     value=$(echo $s_ni | cut -f1 -d' ')
     value2=$(/usr/sbin/mktcpip -S $value 2>&1 | grep -v '^#')
     
     host=$(echo $value2 | cut -f1 -d':')
     print "host="$host
     
     ipaddress=$(echo $value2 | cut -f2 -d':')
     print "ipaddress="$ipaddress
      
     subnet=$(echo $value2 | cut -f3 -d':')
     print "subnet="$subnet
     
     gateway=$(echo $value2 | cut -f7 -d':')
     print "gateway="$gateway

     domain=$(echo $value2 | cut -f6 -d':')
     print "domain="$domain

     name=$(echo $value2 | cut -f5 -d':')
     print "name="$name

     print "RETURN=tcpip1"

     # remove p12 until migration is needed againg
     #print "p2var=p12"
     print "p2var=tempwebinfo1"

   elif [[ $1 = "p12" ]]; then

      method=$(grep INSTALL_METHOD /var/adm/ras/bosinst.data | grep -v '^#' | awk '{printf("%s\n",$3);}' -)

      if [[ $method != "migrate" ]]; then
	print "RETURN=p12a"
      else
        value=$(/usr/lib/instl/sm_inst list_devices | awk '{printf("%s,",$0);}')
        if [ !`echo $value | grep -q /usr/sys/inst.images` ]; then
             value=$(print "$value/usr/sys/inst.images, ,")
        fi
	print "alldevice="$value
	print "RETURN=p12"
      fi
      #print "p2var=tempwebinfo1" 
      print "p2var=p15"

   elif [[ $1 = "tempwebinfo1" ]]; then

      value=$(/usr/lib/instl/sm_inst list_devices | awk '{printf("%s!",$0);}')
      if [ !`echo $value | grep -q /usr/sys/inst.images` ]; then
           value=$(print "$value/usr/sys/inst.images, !")
      fi
      print "alldevice="$value
      print "p2var=p15"

      bundle=$(/usr/bin/lslpp -l | grep bos.docregister.com)
      if [[ -z "$bundle" ]]; then
        print "RETURN=nodocsearch"
        return 0
      fi

      bundle=$(/usr/bin/lslpp -l | grep bos.docsearch.rte)
      if [[ -z "$bundle" ]]; then
        print "RETURN=nodocsearch"
        return 0
      fi

      bundle=$(/usr/bin/lslpp -l | grep IMNSearch.rte.client)
      if [[ -z "$bundle" ]]; then
        print "RETURN=nodocsearch"
        return 0
      fi

      bundle=$(/usr/bin/lslpp -l | grep IMNSearch.rte.httpdlite)
      if [[ -z "$bundle" ]]; then
        print "RETURN=nodocsearch"
        return 0
      fi

      print "RETURN=tempwebinfo1"
      #print "RETURN=temp"

   elif [[ $1 = "p15" ]]; then

      #oldLang=$(echo $LANG)
      #export LANG=C
      print "hostname=$(LANG=C host $(hostname) | awk '{print $1}')"
      #export LANG=$oldLang

      print "p2var=software"

      temp=$(wsmappletcfg -init 2>&1)
      if [[ $? = 0 ]]; then
         value=$(wsmappletcfg -query)
         docdir=$(echo $value | cut -f1 -d'|')
         cgidir=$(echo $value | cut -f2 -d'|')
         server=$(echo $value | cut -f3 -d'|')
	 languages=$(echo $value | cut -f4 -d'|')
	 print "server=$server"
         print "docdir=$docdir"
         print "cgidir=$cgidir"
	 print "languages=$languages"
         print "RETURN=cfgassist1_found"
      else
	 print "languages=$(wsmappletcfg -querylang)"
         print "RETURN=cfgassist1_notfound"
      fi

   elif [[ $1 = "p16" ]]; then

      print "p2var=p17"
      print "RETURN=temp"

   elif [[ $1 = "software" ]]; then

       print "RETURN=softwaremain"
       print "p2var=p17"

   elif [[ $1 = "p17" ]]; then

      print "RETURN=p17"

   else

      print "RETURN=p2"

   fi

}

nav4()
{
   #This function sets the time and timezone
   print "RETURN=p2"
     value1=$(echo $1 | cut -c5-)$(echo $2 | cut -c-4).$(echo $2 | cut -c5-)$(echo $1 | cut -c3,4)
     print "newtimedate="$value1
     if [[ $3 = "true" ]]; then
       shift 3
       value=$(echo $* | cut -f2 -d'(' | cut -f2 -d')')
       newtz=$(dspmsg smit.cat -s 30 7 '(CUT0GDT)           Coordinated Universal Time   (CUT)\n\
(GMT0BST)           United Kingdom               (CUT)\n\
(AZOREST1AZOREDT)   Azores; Cape Verde        (CUT -1)\n\
(FALKST2FALKDT)     Falkland Islands          (CUT -2)\n\
(GRNLNDST3GRNLNDDT) Greenland; East Brazil    (CUT -3)\n\
(AST4ADT)           Central Brazil            (CUT -4)\n\
(EST5EDT)           Eastern U.S.; Colombia    (CUT -5)\n\
(CST6CDT)           Central U.S.; Honduras    (CUT -6)\n\
(MST7MDT)           Mountain U.S.             (CUT -7)\n\
(PST8PDT)           Pacific U.S.; Yukon       (CUT -8)\n\
(AST9ADT)           Alaska                    (CUT -9)\n\
(HST10HDT)          Hawaii; Aleutian          (CUT-10)\n\
(BST11BDT)          Bering Straits            (CUT-11)\n\
(NZST-12NZDT)       New Zealand               (CUT+12)\n\
(MET-11METDT)       Solomon Islands           (CUT+11)\n\
(EET-10EETDT)       Eastern Australia         (CUT+10)\n\
(JST-9JDT)          Japan                     (CUT +9)\n\
(KORST-9KORDT)      Korea                     (CUT +9)\n\
(WAUST-8WAUDT)      Western Australia         (CUT +8)\n\
(TAIST-8TAIDT)      Taiwan                    (CUT +8)\n\
(BEIST-8BEIDT)      Peoples Rep. China        (CUT +8)\n\
(THAIST-7THAIDT)    Thailand                  (CUT +7)\n\
(NOVST-6NOVDT)      Novosibirsk, Russia       (CUT +6)\n\
(PAKST-5PAKDT)      Pakistan                  (CUT +5)\n\
(WST-4WDT)          Gorki; Central Asia; Oman (CUT +4)\n\
(MEST-2MEDT)        Turkey                    (CUT +2)\n\
(SAUST-3SAUDT)      Saudi Arabia              (CUT +3)\n\
(WET-2WET)          Finland                   (CUT +2)\n\
(USAST-2USADT)      South Africa              (CUT +2)\n\
(NFT-1DFT)          Norway; France            (CUT +1)' | grep "$value" | cut -f1 -d')' | cut -c2-)
     else
       shift 3
       value=$(echo $* | cut -f2 -d'(' | cut -f2 -d')')
       newtz=$(dspmsg smit.cat -s 30 22 '(CUT0)           Coordinated Universal Time   (CUT)\n\
(GMT0)           United Kingdom               (CUT)\n\
(AZOREST1)       Azores; Cape Verde        (CUT -1)\n\
(FALKST2)        Falkland Islands          (CUT -2)\n\
(GRNLNDST3)      Greenland; East Brazil    (CUT -3)\n\
(AST4)           Central Brazil            (CUT -4)\n\
(EST5)           Eastern U.S.; Colombia    (CUT -5)\n\
(CST6)           Central U.S.; Honduras    (CUT -6)\n\
(MST7)           Mountain U.S.             (CUT -7)\n\
(PST8)           Pacific U.S.; Yukon       (CUT -8)\n\
(AST9)           Alaska                    (CUT -9)\n\
(HST10)          Hawaii; Aleutian          (CUT-10)\n\
(BST11)          Bering Straits            (CUT-11)\n\
(NZST-12)        New Zealand               (CUT+12)\n\
(MET-11)         Solomon Islands           (CUT+11)\n\
(EET-10)         Eastern Australia         (CUT+10)\n\
(JST-9)          Japan                     (CUT +9)\n\
(KORST-9)        Korea                     (CUT +9)\n\
(WAUST-8)        Western Australia         (CUT +8)\n\
(TAIST-8)        Taiwan                    (CUT +8)\n\
(BEIST-8)        Peoples Rep. China        (CUT +8)\n\
(THAIST-7)       Thailand                  (CUT +7)\n\
(NOVST-6)        Novosibirsk, Russia       (CUT +6)\n\
(PAKST-5)        Pakistan                  (CUT +5)\n\
(WST-4)          Gorki; Central Asia; Oman (CUT +4)\n\
(MEST-2)         Turkey                    (CUT +2)\n\
(SAUST-3)        Saudi Arabia              (CUT +3)\n\
(WET-2)          Finland                   (CUT +2)\n\
(USAST-2)        South Africa              (CUT +2)\n\
(NFT-1)          Norway; France            (CUT +1)' | grep "$value" | cut -f1 -d')' | cut -c2-)
     fi
     chtz $newtz
     TZ=$newtz
     export TZ
     date $value1
}

IPversion_check()
{
  #This function determines if the value inputed was in IPV6 format
  ipaddress=$1
  echo $ipaddress | egrep -s ":"+
  if [[ $? = 1 ]]; then 
    version=4
  else
    version=6
    allni=$(/usr/sbin/lsdev -C -c if -F "name  location  description" | grep -v '^lo' | grep -v '^at' | grep -v '^ca' | grep -v '^es' | awk '{printf("%s,",$0);}')
    print "allni="$allni
  fi
  print "version="$version
  print "RETURN=tcpip3"
}


#-------------------------------------------------------------------------------
# NAME: software_license_exit
#
# PURPOSE: To get a list of software licenses with text
#               
#
#-------------------------------------------------------------------------------
software_license_exit()
{
 
  retval=softwaremain

  integer exitval=0
  flags=""

  flags="$flags -lv"

  cmd="/usr/sbin/inulag $flags"
  eval $cmd
  exitval=$?
  
  # ----------------------------------------------
  #    Info message
  # ----------------------------------------------

   print "======================================================"
   print "RETURN=$retval"
   print "cmd=$cmd"
   print "exitval=$exitval"
   print "======================================================"

   exit ${exitval}

}


#-------------------------------------------------------------------------------
# NAME: listsw_exit()
#
# PURPOSE: listsw panel exit routine. Create lsuniqueID and sets up files that are
#          needed on later panels.
#
#-------------------------------------------------------------------------------
listsw_exit()
{
  listsw_option=${1}
  retval=$listsw_option
   

   # create the unique identifier if it hasn't been set yet

   lsuniqueID="_$$."`date +"%Y.%m.%d.%T"`
   lsuniqueID=$( echo "${lsuniqueID}" | sed 's/:/_/g' )   # replace colons with underscores

   print "lsuniqueID=$lsuniqueID"                       # pass uniqueID back to wizard
   print "listsw_option=$listsw_option"                 # pass uniqueID back to wizard
  
   ignore=`rm /tmp/.ls_configassist_* 2>/dev/null`

   # create the constants that have the lsuniqueID as part of them
   LS_ALL_FILE="/tmp/.ls_configassist_all_list$lsuniqueID"
   LS_PROD_FILE="/tmp/.ls_configassist_product_list$lsuniqueID"
   LS_PKG_FILE="/tmp/.ls_configassist_pkg_list$lsuniqueID"
   LS_TEMP_FILE="/tmp/.ls_configassist_temp$lsuniqueID"
   LS_SHORTENED_LIST_FILE="/tmp/.ls_configassist_short_fileset_list$lsuniqueID"
   LS_CHOSEN_LIST_FILE="/tmp/.ls_configassist_chosen_list$lsuniqueID"

   print "LS_ALL_FILE=$LS_ALL_FILE"
   print "LS_PROD_FILE=$LS_PROD_FILE"
   print "LS_PKG_FILE=$LS_PKG_FILE"
   print "LS_SHORTENED_LIST_FILE=$LS_SHORTENED_LIST_FILE"
   print "LS_CHOSEN_LIST_FILE=$LS_CHOSEN_LIST_FILE"

  print "RETURN="$retval


}


#-------------------------------------------------------------------------------
# NAME: installsw_exit()
#
# PURPOSE: to passed back some variable to the wizard and also define next panel 
#         
#
#-------------------------------------------------------------------------------
installsw_exit()
{
  installsw_option=${1}

  print "installsw_option=$installsw_option"

   processMultVolumes=yes
   availableDevices=`getAvailableDevices`
   print "processMultVolumes=$processMultVolumes"
   print "availableDevices=$availableDevices"
   print "RETURN=installsw_devices"

}

#-------------------------------------------------------------------------------
# NAME: installsw_devices_exit()
#
# PURPOSE: installsw_devices panel exit routine. Create uniqueID and sets up
#          files thst are needed on later panels. Checks if the device or directory
#          is valid.
#
#-------------------------------------------------------------------------------
installsw_devices_exit()
{
  #This function find out what is the next software panel
  sourceType=${1}
  sourceDevice=${2}
  sourceDirectory=${3}
  process_multiple=${4}
  installsw_option=${5}
  

  packages="ignore"
  device_type="DIRECTORY"
  browse_filtered="false"
  which_dialog="install_dialog"
  caller="software"

  # create the unique identifier if it hasn't been set yet

   uniqueID="_$$."`date +"%Y.%m.%d.%T"`
   uniqueID=$( echo "${uniqueID}" | sed 's/:/_/g' )     # replace colons with underscores
   
   print "uniqueID=$uniqueID"                           # pass uniqueID back to wizard
  
  # create the constants that have the uniqueID as part of them
  LIST_FILE="/tmp/.sw_configassist_fileset_list$uniqueID"
  PROD_FILE="/tmp/.sw_configassist_product_list$uniqueID"
  PKG_FILE="/tmp/.sw_configassist_pkg_list$uniqueID"
  OPT_FILE="/tmp/.sw_configassist_options_list$uniqueID"
  SHORTENED_LIST_FILE="/tmp/.sw_configassist_short_fileset_list$uniqueID"
  CHOSEN_LIST_FILE="/tmp/.sw_configassist_chosen_list$uniqueID"
  BUNDLE_FILE="/usr/sys/inst.data/sys_bundles/.sw_configassist_bundle$uniqueID.bnd"
  
  print "LIST_FILE=$LIST_FILE"
  print "PROD_FILE=$PROD_FILE"
  print "PKG_FILE=$PKG_FILE"
  print "OPT_FILE=$OPT_FILE"
  print "SHORTENED_LIST_FILE=$SHORTENED_LIST_FILE"
  print "CHOSEN_LIST_FILE=$CHOSEN_LIST_FILE"
  print "BUNDLE_FILE=$BUNDLE_FILE"
  

        # Do not change the directory nor the extension
  VIEW_SETTINGS_FILE="/tmp/.sw_configassist_view_settings_file$uniqueID"
  print "VIEW_SETTINGS_FILE=$VIEW_SETTINGS_FILE"

  # Do not change the directory nor the extension
  TEMP_FILE="/tmp/.sw_configassist_temp$uniqueID"
  TEMP_FILE1="/tmp/.sw_configassist_temp1$uniqueID"
  TEMP_FILE2="/tmp/.sw_configassist_temp2$uniqueID"

  print "TEMP_FILE=$TEMP_FILE"
  print "TEMP_FILE1=$TEMP_FILE1"
  print "TEMP_FILE2=$TEMP_FILE2"

  vim_tmpfile="$TEMP_FILE"
  print "vim_tmpfile=$vim_tmpfile"

  if [[ $installsw_option = "install_bundles" ]] then
    retval="installsw_bundles_listing"
  else
    retval="installsw_package_sw_listing"
  fi

  #check if there is an /etc/niminfo file
            if [[ -s /etc/niminfo ]]; then
                #get names of machines in which op will be performed
                targetMachines=`grep NIM_NAME /etc/niminfo | awk -F= '{print$2}'`
             #   print "targetMachines=$targetMachines"
            fi
 
  # strip off the description for the device
   input_device=$sourceDevice
   input_device=${input_device%']'*}
   input_device=${input_device#*'['}
  
   if [[ $input_device = "empty" ]] then
   # display error panel if invalid media
   retval=installsw_bad_media_panel
   fi


  case $sourceType in
      "device")            source=$sourceDevice
                           device_type="OTHER"
                           if [[ $process_multiple = "yes" ]] then
                                process_multiple="true"
                           
                           fi

                           if [[ $installsw_option != "install_bundles" ]] then

                           . /usr/cfgassist/bin/inst_query_utils > /dev/null
                           QueryDevice "$caller" "$which_dialog" "$browse_filtered" "$packages" "$input_device" "$device_type" "$target" "$process_multiple" "$vim_tmpfile" "$LIST_FILE" "$PROD_FILE" "$PKG_FILE" "$OPT_FILE" > /dev/null

                           # grab return code
                           RC=$?

                           if [[ $RC -ne 0 ]] then
                           # display error panel if invalid media
                           retval=installsw_bad_media_panel
                           fi;

                           fi;;

      "directory")      source=$sourceDirectory
                        # check if it is a valid directory
                        if [[ ! -d $sourceDirectory ]] then
                           retval=installsw_bad_directory_panel
                        else
                           # check if toc file is valid
                           . /usr/cfgassist/bin/inst_query_utils > /dev/null
                           QueryDevice "$caller" "$which_dialog" "$browse_filtered" "$packages" "$sourceDirectory" "$device_type" "$target" "$process_multiple" "$vim_tmpfile" "$LIST_FILE" "$PROD_FILE" "$PKG_FILE" "$OPT_FILE" > /dev/null

                           # grab return code
                           RC=$?

                           if [[ $RC -ne 0 ]] then
                           # display error panel if invalid toc file
                           retval=installsw_bad_toc_panel
                           fi
                        fi;;

   esac

  
  print "source="$source
  print "caller="$caller
  print "targetMachines="$targetMachines
  print "RETURN="$retval

}

#-------------------------------------------------------------------------------
# NAME: getSoftwareList(uniqueID, which_list)
#
# PURPOSE: To get a list of available packages from the source.
#               This will be in the form name1, name2..
#
# PARAMETERS:
#       $1: Unique ID for temp file names (not used)
#       $2: List software installed automatically (list_auto_sw) or optionally (list_optional_sw)
#
#-------------------------------------------------------------------------------
getSoftwareList()
{
  typeset list_which PATH

  lsuniqueID=${1}

  if [[ ${2} = "list_auto_sw" ]]; then
    list_which=1
  else
    list_which=0
  fi

  # create the constants that have the uniqueID as part of them
  LS_ALL_FILE="/tmp/.ls_configassist_all_list$lsuniqueID"
  LS_PKG_FILE="/tmp/.ls_configassist_pkg_list$lsuniqueID"
 
  PATH=/usr/bin

  LANG=C lslpp -Lqca | sort -u > ${LS_ALL_FILE}

  awk -F: '{ if ($15 == '$list_which') { print $1 } }' ${LS_ALL_FILE} | sort -u > ${LS_PKG_FILE}

  print "RETURN="`paste -s -d, ${LS_PKG_FILE}`

}

#-------------------------------------------------------------------------------
# NAME: getBundleFiles(source)
#
# PURPOSE: To get a list of Bundles.
#               This will be in the form name1,description1,name2 ...
#
#-------------------------------------------------------------------------------
getBundleFiles()
{
   uniqueID=${1}
   descAppBundle=${2}
   descClientBundle=${3}
   descDCEBundle=${4}
   descCDEBundle=${5}
   descGNOMEBundle=${6}
   descKDEBundle=${7}
   descNetscapeBundle=${8}
   descdevicesBundle=${9}
   descwsmremoteBundle=${10}
   deschdwrBundle=${11}
   descpersprodBundle=${12}
   descserverBundle=${13}
   descothersBundle=${14}
   descmediaBundle=${15}
   descuserBundle=${16}
   descdocservBundle=${17}
   descgraphicsBundle=${18}
   descjavaBundle=${19}
   descnfsnisBundle=${20}
   descnetworkingBundle=${21}

   SYS_BUNDLE_DIR=/usr/sys/inst.data/sys_bundles/
   USER_BUNDLE_DIR=/usr/sys/inst.data/user_bundles/
   sp="_#_"


  # create the constants that have the uniqueID as part of them

  TEMP_FILE2="/tmp/.sw_configassist_temp2$uniqueID"

   #------------------------------------------------------------------------

   # Add all the system bundles except for Media-Defined to the BUNDLES list
   #------------------------------------------------------------------------
   BUNDLES=""
   ft="yes"
  for BUNDLE in $(ls ${SYS_BUNDLE_DIR}*.bnd  2>/tmp/getbundles.stderr |
       grep -v Media-Defined | sort -Au); do

      BUNDLE="`basename $BUNDLE | sed -e s,.bnd$,,`"
      case $BUNDLE in
         App-Dev)    COMMENTS="${descAppBundle}"
                     ;;
         Client)     COMMENTS="${descClientBundle}"
                     ;;
         DCE-Client) COMMENTS="${descDCEBundle}"
                     ;;
         CDE)        COMMENTS="${descCDEBundle}"
                     ;;
         GNOME)      COMMENTS="${descGNOMEBundle}"
                     ;;
         KDE)        COMMENTS="${descKDEBundle}"
                     ;;
         Netscape)   COMMENTS="${descNetscapeBundle}"
                     ;;
         devices)    COMMENTS="${descdevicesBundle}"
                     ;;
         wsm_remote) COMMENTS="${descwsmremoteBundle}"
                     ;;
         HTTP_Server) COMMENTS="${descwsmremoteBundle}"
                     ;;
         Hdwr-Diag)  COMMENTS="${deschdwrBundle}"
                     ;;
         Pers-Prod)  COMMENTS="${descpersprodBundle}"
                     ;;
         Server)     COMMENTS="${descserverBundle}"
                     ;;
         DocServices)  COMMENTS="${descdocservBundle}"
                     ;;
         Graphics)   COMMENTS="${descgraphicsBundle}"
                     ;;
         Java)       COMMENTS="${descjavaBundle}"
                     ;;
         NFS_NIS)    COMMENTS="${descnfsnisBundle}"
                     ;;
         Networking) COMMENTS="${descnetworkingBundle}"
                     ;;
         *)          COMMENTS="${descothersBundle}"
                     ;;
      esac

      if [[ ${ft} = "yes" ]] then
        BUNDLES="${BUNDLE}${sp}${COMMENTS}"
        ft="no"
      else
        BUNDLES="${BUNDLES}${sp}${BUNDLE}${sp}${COMMENTS}"
      fi
   done
 

   #-------------------------------------------------
   # Add the Media-Defined bundle to the BUNDLES list
   #-------------------------------------------------
   COMMENTS="${descmediaBundle}"
   BUNDLES="${BUNDLES}${sp}Media-Defined${sp}${COMMENTS}"

   #-------------------------------------------------
   # Add any user defined bundles to the BUNDLES list
   #-------------------------------------------------
   COMMENTS="${descuserBundle}"
   for BUNDLE in $(ls ${USER_BUNDLE_DIR}*.bnd 2>/dev/null | sort -Au); do
      BUNDLES="${BUNDLES}${sp}`basename $BUNDLE | sed -e s,.bnd$,,`${sp}${COMMENTS}"
   done

   #---------------------------------------------------
   # Strip off the leading "|" from the list of BUNDLES
   #---------------------------------------------------
   #print ${BUNDLES} | sed -e "s/^|//g"

   print ${BUNDLES}  > ${TEMP_FILE2}

   listBundles=`cat $TEMP_FILE2`

   print "RETURN="$listBundles
}


#-------------------------------------------------------------------------------
# NAME: getPackagesOnMedia
#
# PURPOSE: To get a list of available packages from the source.
#               This will be in the form name1,description1,name2 ...
#
#-------------------------------------------------------------------------------
getPackagesOnMedia()
{
   source=${1}
   sourceType=${2}
   processMultVolumes=${3}
   caller=${4}
   target=${5}
   uniqueID=${6}


   SAVEIFS=${IFS}
   # create the constants that have the uniqueID as part of them
  LIST_FILE="/tmp/.sw_configassist_fileset_list$uniqueID"
  PROD_FILE="/tmp/.sw_configassist_product_list$uniqueID"
  PKG_FILE="/tmp/.sw_configassist_pkg_list$uniqueID"
  OPT_FILE="/tmp/.sw_configassist_options_list$uniqueID"
  TEMP_FILE="/tmp/.sw_configassist_temp$uniqueID"
  TEMP_FILE1="/tmp/.sw_configassist_temp1$uniqueID"
  
   vim_tmpfile="$TEMP_FILE"


   # Set the parameters to be sent to QueryDevice
   which_dialog="install_dialog"
   browse_filtered="false"
   packages="ignore"

   #if there are multiple targets, replace commas by spaces
   target=$( echo "${target}" | sed 's/,/ /g' )

   # strip off the description for the device
   input_device=$source
   input_device=${input_device%']'*}
   input_device=${input_device#*'['}

   case $sourceType in
      "device")         device_type="OTHER";;
      "resource")       device_type="NETWORK";;
      "directory")      device_type="DIRECTORY";;
   esac

   if [[ $processMultVolumes = "yes" ]] then
      process_multiple="true"
   else
      process_multiple="false"
   fi
   #vim_tmpfile="$TEMP_FILE"
   vim_tmpfile="$vim_tmpfile"
   # Get the lists of products, packages, and filesets
   . /usr/cfgassist/bin/inst_query_utils > /dev/null
   QueryDevice "$caller" "$which_dialog" "$browse_filtered" "$packages" "$input_device" "$device_type" "$target" "$process_multiple" "$vim_tmpfile" "$LIST_FILE" "$PROD_FILE" "$PKG_FILE" "$OPT_FILE" > /dev/null

   # Do not include msg and loc in the package file

        cat $PKG_FILE |
        while read package 
        do
                current_entry="$package"

                found=0
                first_field=0

                IFS="."
                for field in $package
                do
                        # if any of the NLS keyworks are in the package name,
                        # it's a locale file and we want to exclude it from
                        # the list of files to display in the list fileset panel
                        if [[ $field = "msg" ]] || [[ $field = "loc" ]] ||
                           [[ $field = "help" ]]  || [[ $field = "html" ]] then
                         #   [[ $field = "iconv" ]] then
                                found=1
                                break
                        else
                                first_field=1

                        fi
                done
                IFS=${SAVEIFS}
                if [[ $found -eq 0 ]] && [[ $first_field -ne 0 ]] then
                        echo "$current_entry">>$TEMP_FILE1
                fi

         done

         # if we put any entries in the temp file, that means we are going to filter out
         # language filesets. Replace the shortened list file with the temp file.

         if [[ -s $TEMP_FILE1 ]] then
                cp $TEMP_FILE1 $PKG_FILE
         rm $TEMP_FILE1 
         fi


 # Create comma seperated list of packages for editlist

   print "caller="$caller
   print "RETURN="`paste -s -d, ${PKG_FILE}`
}


#------------------------------------------------------------------------------
# NAME: getFilesetsOnMedia
#
# PURPOSE: To get a list of available filesets from the source.
#               This will be in the form name1,description1,level1,name2 ...
#
#------------------------------------------------------------------------------
getFilesetsOnMedia()
{
   uniqueID=${1}
   packagesToInstall=${2}
   

   SHORTENED_LIST_FILE="/tmp/.sw_configassist_short_fileset_list$uniqueID"
   TEMP_FILE="/tmp/.sw_configassist_temp$uniqueID"

   # Get list of filesets from packages to install, and
   # format it into a comma seperated list for the editlist
   /usr/bin/awk -F: '{OFS=","; gsub(/,/, " "); print $2, $12, $3}' ${SHORTENED_LIST_FILE} | paste -s -d, - > $TEMP_FILE
   print "RETURN="`cat ${TEMP_FILE}`
}

#------------------------------------------------------------------------------
# NAME: getInstalledFilesets
#
# PURPOSE: To get a list of available filesets from the source.
#               This will be in the form name1,description1,level1,name2 ...
#
#------------------------------------------------------------------------------
getInstalledFilesets()
{
   lsuniqueID=${1}
   packagesToInstall=${2}
  

   LS_SHORTENED_LIST_FILE="/tmp/.ls_configassist_short_fileset_list$lsuniqueID"
   LS_TEMP_FILE="/tmp/.ls_configassist_temp$lsuniqueID"

   # Get list of filesets from packages to install, and
   # format it into a comma seperated list for the editlist
   /usr/bin/awk -F: '{OFS=","; gsub(/,/, " "); print $2, $8, $3}' ${LS_SHORTENED_LIST_FILE} | paste -s -d, - > $LS_TEMP_FILE
   print "RETURN="`cat ${LS_TEMP_FILE}`
}

#-------------------------------------------------------------------------------
# NAME:installsw_package_sw_listing_exit
#
# PURPOSE: To create a shortened list of the available filesets dependant on the
#          package choosen.  Also to set what the next panel will be.
#
#-------------------------------------------------------------------------------
installsw_package_sw_listing_exit()
{
   installAll=${1}
   packagesToInstall=${2}
   uniqueID=${3}
   filterFilesets=${4}
   previewInstall=${5}

   
   LIST_FILE="/tmp/.sw_configassist_fileset_list$uniqueID"
   SHORTENED_LIST_FILE="/tmp/.sw_configassist_short_fileset_list$uniqueID"
   CHOSEN_LIST_FILE="/tmp/.sw_configassist_chosen_list$uniqueID"
   TEMP_FILE1="/tmp/.sw_configassist_temp1$uniqueID"
   
   print "installAll=$installAll"
   print "filterFilesets=$filterFilesets"
   print "previewInstall=$previewInstall"

   if [[ $installAll = "yes" ]] then
      cp $LIST_FILE $SHORTENED_LIST_FILE
      cp $LIST_FILE $CHOSEN_LIST_FILE
      retval="installsw_confirmation_panel"
   else
      # clear the SHORTENED_LIST_FILE and CHOSEN_LIST_FILE
      echo "" > $SHORTENED_LIST_FILE
      echo "" > $CHOSEN_LIST_FILE
      retval="installsw_fileset_software_listing"

      # Create a shortened list file showing only the packages
      # that were choosen.  This will be a shorter list of the
      # main fileset list.
      IFS=","
      for package in $packagesToInstall
         do
         grep "^${package}[.:]" ${LIST_FILE}
         done > $SHORTENED_LIST_FILE


   fi

   print "RETURN=$retval"
}

#-------------------------------------------------------------------------------
# NAME:installsw_bundles_listing_exit
#
# PURPOSE: Pass some variables back to the wizard.
#          Also to set what the next panel will be.
#
#-------------------------------------------------------------------------------
installsw_bundles_listing_exit()
{
   bundlesToInstall=${1}
   uniqueID=${2}
   previewInstall=${3}


   print "previewInstall=$previewInstall"
   print "bundlesToInstall=$bundlesToInstall"
   retval="installsw_confirmation_panel"

   print "RETURN=$retval"
}

#-------------------------------------------------------------------------------
# NAME:list_auto_sw_exit
#
# PURPOSE: To create a shortened list of the available filesets dependant on the
#          package choosen.  Also to set what the next panel will be.
#
#-------------------------------------------------------------------------------
list_auto_sw_exit()
{
   packagesToInstall=${1}
   lsuniqueID=${2}
   listsw_option=${3}


   LS_LIST_FILE="/tmp/.ls_configassist_all_list$lsuniqueID"
   LS_SHORTENED_LIST_FILE="/tmp/.ls_configassist_short_fileset_list$lsuniqueID"
   LS_CHOSEN_LIST_FILE="/tmp/.ls_configassist_chosen_list$lsuniqueID"

      # clear the SHORTENED_LIST_FILE and CHOSEN_LIST_FILE
      echo "" > $LS_SHORTENED_LIST_FILE
      echo "" > $LS_CHOSEN_LIST_FILE
      retval="listsw_fileset_software_listing"

      # Create a shortened list file showing only the packages
      # that were choosen.  This will be a shorter list of the
      # main fileset list.
      IFS=","
      for package in $packagesToInstall
         do
         grep "^${package}[.:]" ${LS_LIST_FILE}
         done > $LS_CHOSEN_LIST_FILE

      if [[ $listsw_option = "list_auto_sw" ]]; then
        list_which=1
      else
        list_which=0
      fi

      /usr/bin/awk -F: '{ if($15 == '$list_which') print }' $LS_CHOSEN_LIST_FILE | sort -u > ${LS_SHORTENED_LIST_FILE}

   print "RETURN=$retval"
}

#------------------------------------------------------------------------------
# NAME: installsw_getSettings
#
# PURPOSE: To return the list of installation settings.
#               This will be in the form setting1,value1,setting2 ...
#
#------------------------------------------------------------------------------
installsw_getSettings()
{
   targetMachines=${1}
   source=${2}
   sourceType=${3}
   labelMachines=${4}
   labelDevice=${5}
   labelDirectory=${6}
   labelSoftware=${7}
   labelLicenses=${8}
   acceptAllLicenses=${9}
   filesetsToInstall=${10}
   levelsToInstall=${11}
   installAll=${12}
   uniqueID=${13}
   labelPreview=${14}
   preview=${15}
   bundlesToInstall=${16}
   installsw_option=${17} 


   VIEW_SETTINGS_FILE="/tmp/.sw_configassist_view_settings_file$uniqueID"
   SHORTENED_LIST_FILE="/tmp/.sw_configassist_short_fileset_list$uniqueID"
   
   # create the list of settings
   # Using the character "!" for the separator in this case
   settings=''

   settings="$labelLicenses!""$acceptAllLicenses!"
   settings="$settings""$labelPreview!""$preview!"

   # Set the source from the source type
   case $sourceType in
      "device")         settings="$settings""$labelDevice!";;
      "directory")      settings="$settings""$labelDirectory!";;
   esac
   settings="$settings""$source"

   if [[ $installAll = "no" ]] then

   # Build  file with the filesets user chose to install
   levelsToInstallTemp=$levelsToInstall
   IFS=","
   for fileset in $filesetsToInstall
      do
        level=${levelsToInstallTemp%%','*}              # get next level in the list
        levelsToInstallTemp=${levelsToInstallTemp#*','} # remove the next level from the list
        grep ":$fileset:" ${SHORTENED_LIST_FILE} |
        grep ":$level:"
      done >> $VIEW_SETTINGS_FILE

   # Put filesets from above file in the settings string and pass them to view settings panel
   putHeader="true"
   IFS=":"
   cat $VIEW_SETTINGS_FILE |
   while read package fileset level PTF type state superseed sup_pft sup_state latest_sup quiesce description netls_vendor_id netls_prod_id netls_prod_ver inspath
      do
        if [[ $putHeader = "true" ]] then
                settings="$settings""!$labelSoftware"
                putHeader="false"
        else
                settings="$settings"'!'
        fi
        settings="$settings""!$fileset $level"
      done
   fi
   if [[ $installsw_option = "install_bundles" ]] then
             settings="$settings""!$labelSoftware""!$bundlesToInstall!"
   fi

   rm -f $VIEW_SETTINGS_FILE >/dev/null 2>&1

   print "RETURN=${settings}"
}

#------------------------------------------------------------------------------
# NAME: installSoftware
#
# PURPOSE: To install the software choosen onto the targets specified
#
#------------------------------------------------------------------------------
installSoftware()
{
   installAll=${1}
   targetMachines=${2}
   source=${3}
   sourceType=${4}
   filesetsToInstall=${5}
   levelsToInstall=${6}
   processMultVolumes=${7}
   acceptAllLicenses=${8}
   uniqueID=${9}
   preview=${10}
   installsw_option=${11}
   bundlesToInstall=${12}
   
   ORIGINAL_IFS="${IFS}"

   rc="0"       # initial setting of return code
  
 
   BUNDLE_FILE="/usr/sys/inst.data/sys_bundles/.sw_configassist_bundle$uniqueID.bnd"
   SHORTENED_LIST_FILE="/tmp/.sw_configassist_short_fileset_list$uniqueID"
   CHOSEN_LIST_FILE="/tmp/.sw_configassist_chosen_list$uniqueID"

   # strip off the superfulous description for the device
   source=${source%']'*}
   source=${source#*'['}

 if [[ $installsw_option != "install_bundles" ]] then
  
   # Make the bundle and
   #   if we aren't installing all media add the filesets to the Choosen List File.
   if [[ $installAll = "yes" ]] then
      print "all" > $BUNDLE_FILE
   else
      # Add the filesets to install to the Choosen List File.
      levelsToInstallTemp=$levelsToInstall
      IFS=","
      for fileset in $filesetsToInstall
         do
         level=${levelsToInstallTemp%%','*}             # get next level in the list
         levelsToInstallTemp=${levelsToInstallTemp#*','} # remove the next level from the list
         grep ":$fileset:" ${SHORTENED_LIST_FILE} |
         grep ":$level:"
         done >> $CHOSEN_LIST_FILE
  
      # Make bundle
      # Even though geninstall doesn't need prefixes, it runs faster it they are present
      # so we are keeping this part of the code.
      /usr/bin/awk -F: '{ if($5 ~ /^[RUJE]$/) { print $5":"$2" "$3 } else { print "I:"$2" "$3 } }' > $BUNDLE_FILE < $CHOSEN_LIST_FILE
      sort ${BUNDLE_FILE}
   fi

   
   bundle="$BUNDLE_FILE"
   bundle=${bundle##*'/'}            # strip full path
   bundle=${bundle%'.'*}             # strip extension

 else

   bundle="$bundlesToInstall"

 fi

   IFS="$ORIGINAL_IFS"

   command=''

      # Set the parameters for the InstallBundlePanel
      caller='software'
      target='""'
      force='""'
      input_choice="$source"
      inst_all_lic='false'
      commit='true'
      save_replaced='false'
      install_reqs='true'
      extend_fs='true'
      verify_sizes='false'
      include_langs='true'
      detail_output='false'
      script='""'
      max_installs='""'
      max_time='""'

      if [[ $sourceType = "device" ]] && [[ $processMultVolumes = "yes" ]] then
         multi_volume='true'
      else
         multi_volume='false'
      fi
      if [[ $preview = "yes" ]] then
         preview='true'
      else
         preview='false'
      fi
      if [[ $acceptAllLicenses = "yes" ]] then
         acceptlicense='true'
      else
         acceptlicense='false'
      fi

      # defect 513808
      if [[ $bundle = "wsm_remote" ]] then
         include_langs='false'
      fi

      command='export PATH=$PATH:/usr/cfgassist/bin ; '
      command="${command}"'. /usr/cfgassist/bin/inst_panel_exits > /dev/null ; '
      command="${command}"'InstallBundlePanel '
      command="${command}""${caller} ${target} ${force} ${input_choice} ${bundle} ${inst_all_lic} ${commit} ${save_replaced} ${install_reqs} "
      command="${command}""${extend_fs} ${verify_sizes} ${include_langs} ${detail_output} ${multi_volume} ${script} ${preview} ${max_installs} "
      command="${command}""${max_time} ${acceptlicense} "
   
  
   if [[ $command = "" ]] then
      #**************************************************************
      #*  Invalid parameters for installation                       *
      #**************************************************************

     return 1
   fi 
 
    eval $command
    rc=$?

    if [[ $rc = "0" ]] then
      retval=installsw_finish_success_panel
      logmsg="0, Installed Software"
    else
      retval=installsw_finish_failure_panel
      logmsg="1, Unable to install Software"
    fi


   print "${logmsg}:"|wsmoutput -header "LOG1:"
   print "RETURN=$retval"


   return $rc
}
    
#---------------------------------------------------------------------------------
# NAME: cleanup
#
# PURPOSE: Clean up temporary files
#
#---------------------------------------------------------------------------------
cleanup()
{
CDAUTOMOUNT=$2

if [[ ! $DEBUG = "true" ]] then
   ignore=`rm /tmp/.sw_configassist_* 2>/dev/null`
   ignore=`rm /tmp/.ls_configassist_* 2>/dev/null`
   ignore=`rm /usr/sys/inst.data/sys_bundles/.sw_configassist_* 2>/dev/null`
fi

if [[ "$CDAUTOMOUNT" = "yes" ]]; then
   /usr/sbin/cdutil -r > /dev/null 2>&1
fi

print "RETURN=sg-exit-done" # 
}


#---------------------------------------------------------------------------------
# NAME: getAvailableDevices
#
# PURPOSE: Obtain available devices.
#
#---------------------------------------------------------------------------------
getAvailableDevices()
{
   cd_list=""
   tape_list=""
   lpp_src_list=""


   # Get available cdrom drives.
   lsdev -Cccdrom -S Available -F "name description" | \
   while read name description;
      do
      cd_list="${cd_list}${description} [/dev/${name}]!"
      done

   # Get available tape drives.
   lsdev -Cctape -S Available -F "name description" | \
   while read name description;
      do
      tape_list="${tape_list}${description} [/dev/${name}]!"
      done

   # Get available diskette drives.
   lsdev -Ccdiskette -S Available -F "name description" | \
   while read name description;
     do
      disk_list="${disk_list}${description} [/dev/${name}]!"
      done


    device_list="${cd_list}${tape_list}"
   #device_list="${cd_list}${tape_list}${disk_list}"

   echo "${device_list}"
}

 

update_interface_list()
{
  #This function rediscovers the network interfaces for DHCP
  option1=$1

  if [[ $option1 = "tcpip2a" ]]; then
     allni=$(/usr/sbin/lsdev -C -c if -F "name  location  description" | grep -v '^lo' | grep -v '^at' | grep -v '^ca' | grep -v '^es' | awk '{printf("%s,",$0);}')
     newValue=$(/bin/dspmsg -s 4 smit.cat 488 'any     Use the first available interface')
     allni=$newValue,$allni
     print "allni="$allni
  fi
  print "RETURN="$option1
}

IPversion_branch()
{
  version=$1

  if [[ $version = "6" ]]; then
     print "RETURN=tcpip7v6"
  elif [[ $version = "tcpip5a" ]]; then
     print "RETURN=tcpip7atm"
  elif [[ $version = "tcpip5c" ]]; then
     print "RETURN=tcpip7c370"
  else
     print "RETURN=tcpip7"
  fi
}

device_branch()
{
  # This function sends user to appropriate additional parameters screen

  ni=$1

  value=$(echo $ni | awk '{print $1}')
  case $value in
    at[0-7] )
	      print "RETURN=tcpip5a"
	      print "version=tcpip5a"
	      ;;
    ca[0-9] | es[0-9] )
	      print "RETURN=tcpip5c"
	      print "version=tcpip5c"
	      ;;
    any )
	      print "RETURN=tcpip7a"
	      ;;
    *)
       INTERFACE=`echo $ni | awk '{print $1}'`
       DEVICE=`echo $INTERFACE | sed 's/^tr/tok/;s/^en/ent/;s/^et/ent/;s/^fi/fddi/'`
       linebuf=`/usr/cfgassist/bin/dspattr -l $DEVICE -w -C R -Fattribute~description~classification~user_settable~value_rep~help~value~values`
       if [[ -z "${linebuf}" ]] ; then
           print "RETURN=tcpip5"
           print "devName="$DEVICE
           print "option1=$option1"
       else
           print "RETURN=tcpip4"
           print "devName="$DEVICE
           print "dialogOptions="${linebuf%%?}
           print "attrChanges=DUMMYRETVAL1"
       fi
       ;;
  esac

}

tcpip_branch()
{
  option1=$1
  if [[ $option1 = "tcpip2a" ]]; then
    print "RETURN=tcpip7a"
  else
    print "RETURN=tcpip5"
  fi
}


tcpipfinish()
{
  # This function configures TCPIP (manually)

  devName=$1
  host=$2
  ipaddress=$3
  name=$4
  domain=$5
  subnet=$6
  gateway=$7
  ni=$8
  attrChanges=$9

  ni=$(echo $ni | cut -f1 -d' ')
  params=""
  if [ "${name}" != "[empty]" -a "${domain}" != "[empty]" ]; then
    params="-n $name -d $domain"
  fi
  if [ "${subnet}" != "[empty]" ]; then
    params="${params} -m $subnet"
  fi
  if [ "${gateway}" != "[empty]" ]; then
    params="${params} -g $gateway"
  fi
  mktcpip -h $host -a $ipaddress -i $ni "${params}"
  RC=$?
  integer i=0
  integer max=0
  attrValStr=""
  if [ $RC -eq 0 -a "${devName}" != "[empty]" -a "${attrChanges}" != "[empty]" ] ; then
      set -A attrVal ${attrChanges}
      max=${#attrVal[*]}
      while  (( i < max ))
      do
        attrValStr=$attrValStr"-a "${attrVal[i]}" "
        i=i+1
      done
      eval /usr/sbin/chdev -l "${ni}" -a state=detach
      eval rmdev -l "${devName}"
      eval /usr/sbin/chdev -l "${devName}" "${attrValStr}"
      if [ $? != 0 ] ; then
         eval chdev -P -l "${devName}" "${attrValStr}"
      fi
      eval mkdev -l "${devName}"
      eval /usr/sbin/chdev -l "${ni}" -a state=up
      RC=$?
      eval /usr/lib/methods/cfginet 2>/dev/null 1>/dev/null
  fi

  #This is a hack to terminate a TaskGuide variable
  print "a=0"

  if [[ $RC != 0 ]]; then
      print "RETURN=tcpip_error"
    else
      print "RETURN=tcpip8"
  fi
  return $RC
}

tcpipfinish_v6()
{
  # This function configures TCPIP (manually)

  devName=$1
  host=$2
  ipaddress=$3
  name=$4
  domain=$5
  subnet=$6
  gateway=$7
  ni=$8
  attrChanges=$9

  ni=$(echo $ni | cut -f1 -d' ')
  params=""
  if [ "${name}" != "[empty]" -a "${domain}" != "[empty]" ]; then
    params="-n $name -d $domain"
  fi
  if [ "${subnet}" != "[empty]" ]; then
    params="${params} -m $subnet"
  fi
  if [ "${gateway}" != "[empty]" ]; then
    params="${params} -g $gateway"
  fi
  eval mktcpip6 -h $host -a $ipaddress -i $ni "${params}"
  RC=$?
  integer i=0
  integer max=0
  attrValStr=""
  if [ $RC -eq 0 -a "${devName}" != "[empty]" -a "${attrChanges}" != "[empty]" ] ; then
      set -A attrVal ${attrChanges}
      max=${#attrVal[*]}
      while  (( i < max ))
      do
        attrValStr=$attrValStr"-a "${attrVal[i]}" "
        i=i+1
      done
      eval /usr/sbin/chdev -l "${ni}" -a state=detach
      eval rmdev -l "${devName}"
      eval /usr/sbin/chdev -l "${devName}" "${attrValStr}"
      if [ $? != 0 ] ; then
         eval chdev -P -l "${devName}" "${attrValStr}"
      fi
      eval mkdev -l "${devName}"
      eval /usr/sbin/chdev -l "${ni}" -a state=up
      RC=$?
      eval /usr/lib/methods/cfginet 2>/dev/null 1>/dev/null
  fi
  #This is a hack to terminate a TaskGuide variable
  print "a=0"

  if [[ $RC != 0 ]]; then
      print "RETURN=tcpip_error"
    else
      print "RETURN=tcpip8"
  fi
  return $RC
}

tcpipfinish_atm()
{
  # This function configures TCPIP (manually) for atm network interface

  # devName=$1
  host=$1
  ipaddress=$2
  name=$3
  domain=$4
  subnet=$5
  gateway=$6
  ni=$7
  contype=$8
  servaddress=${9}
  altdevice=${10}
  idletimer=${11}
  bitrate=${12}

  #Construct list of optional attributes
  finalAttributes=""

  if [ "${name}" != "null" -a "${domain}" != "null" ]; then
    finalAttributes="-n $name -d $domain"
  fi
  if [ "${subnet}" != "null" ]; then
    finalAttributes="$finalAttributes -m $subnet"
  fi
  if [ "${gateway}" != "null" ]; then
    finalAttributes="$finalAttributes -g $gateway"
  fi
  if [  -n $contype -a "${contype}" != "null" ]; then
    finalAttributes="$finalAttributes -C $contype"
  fi
  if [  -n $servaddress -a "${servaddress}" != "null" ]; then
    finalAttributes="$finalAttributes -A $servaddress"
  fi
  if [  -n $altdevice -a "${altdevice}" != "null" ]; then
    finalAttributes="$finalAttributes -D $altdevice"
  fi
  if [  -n $idletimer -a "${idletimer}" != "null" ]; then
    finalAttributes="$finalAttributes -I $idletimer"
  fi
  if [  -n $bitrate -a "${bitrate}" != "null" ]; then
    finalAttributes="$finalAttributes -U $bitrate"
  fi
 
  ni=$(echo $ni | cut -f1 -d' ')
  echo "mktcpip.atm -h $host -a $ipaddress -i $ni $finalAttributes"
  eval mktcpip.atm -h $host -a $ipaddress -i $ni $finalAttributes
  RC=$?

  #This is a hack to terminate a TaskGuide variable
  print "a=0"

  if [[ $RC != 0 ]]; then
    print "RETURN=tcpip_error"
  else
    print "RETURN=tcpip8"
  fi
  return $RC
}

tcpipfinish_c370()
{
  # This function configures TCPIP (manually) for atm network interface

#  devName=$1
  host=$1
  ipaddress=$2
  name=$3
  domain=$4
  subnet=$5
  gateway=$6
  ni=$7
  subchannel=$8

  #Construct list of optional attributes
  finalAttributes=""
  if [ "${name}" != "null" -a "${domain}" != "null" ]; then
    finalAttributes="-n $name -d $domain"
  fi
  if [ "${subnet}" != "null" ]; then
    finalAttributes="$finalAttributes -m $subnet"
  fi
  if [ "${gateway}" != "null" ]; then
    finalAttributes="$finalAttributes -g $gateway"
  fi
  if [ -n $subchannel -a "${subchannel}" != "null" ]; then
    finalAttributes="$finalAttributes -c $subchannel"
  fi
  
  ni=$(echo $ni | cut -f1 -d' ')
  echo "mktcpip -h $host -a $ipaddress -i $ni $finalAttributes"
  mktcpip -h $host -a $ipaddress -i $ni $finalAttributes
  RC=$?
  

  #This is a hack to terminate a TaskGuide variable
  print "a=0"

  if [[ $RC != 0 ]]; then
    print "RETURN=tcpip_error"
  else
    print "RETURN=tcpip8"
  fi
  return $RC
}


dhcpfinish()
{
  # This function configures TCPIP (DHCP)
 
  whendhcp=$1
  ni=$2
  attrChanges=$3

  ni=$(echo $ni | cut -f1 -d' ')
  if [[ $whendhcp = "both" ]]; then
    when=4
  elif [ $whendhcp = "now" ]; then
    when=2
  else
    when=3
  fi
  setup_dhcp interface ${ni} when ${when} 
  RC=$?
  #This is a hack to terminate a TaskGuide variable
  print "a=0"
  
  if [[ $RC != 0 ]]; then 
    print "RETURN=tcpip_error"
  else
    print "RETURN=tcpip8"
  fi

}

nav9()
{
   if [[ $1 = "p10" ]]; then
      print "RETURN=p10"
   elif [[ $2 = "p11" ]]; then
      print "RETURN=p11"
   elif [[ $3 = "p12" ]]; then
      print "RETURN=p12"
   elif [[ $4 = "p13" ]]; then
      print "RETURN=p13"
   else
      print "RETURN=p2"
   fi

   print "p2var=p14"
}

nav10()
{
   if [[ $1 = "p7" ]]; then
      print "RETURN=p11"
   else 
      print "RETURN=p11a"
   fi
}

nav11()
{
   #This function configures TCPIP (manually)
   if [[ $CONFIG_SAFE = "false" ]]; then
      ni=$(echo $8 | cut -f1 -d' ')
      mktcpip -h $1 -a $2 -i $8 -n $3 -d $4 -m $5 -g $6
   fi
   print "RETURN=p2"
}

nav11a()
{
   #This function configures TCPIP (DHCP)
   if [[ $CONFIG_SAFE = "false" ]]; then
      ni=$(echo $2 | cut -f1 -d' ')
      echo "interface $ni" >>/etc/dhcpcd.ini
      if [[ $1 = "both" ]]; then
         /usr/sbin/chrctcp -S -a dhcpcd
      elif [ $1 = "now" ]; then
         /usr/sbin/chrctcp -S dhcpcd
      else
         /usr/sbin/chrctcp -a dhcpcd
      fi
   fi

   print "RETURN=p2"
}

nav12()
{
  #This function does the update all installation
  devsource=$(echo $1 | cut -f1 -d' ')
  runcmd "/usr/lib/instl/sm_inst installp_cmd -a -X -g -c -N -d $devsource -f '_update_all'"

  #This is a hack to terminate a TaskGuide variable
  print "a=0"

  print "RETURN=p2"
}

nav13()
{
   print "RETURN=p12"
}

nav13a()
{
   print "RETURN=p13b"
   print "p2var=p14"
}

nav13b()
{
   print "RETURN=p2"
   print "p2var=p14"
}
         
webinfobranch()
{
  webinfochoice2=$1
  print "from=webinfo3"

  if [[ $webinfochoice2 = "simple1" ]]; then
    #Check to see if netscape is installed
    netscape=$(/usr/bin/lslpp -q -l -c Netscape.nav.rte)

    if [[ -z $netscape ]]; then
      #Netscape is not installed
      print "RETURN=simple"

    else
      #Add BROWSER variable to /etc/environment

      /usr/sbin/chwebconfig -C -o BROWSER -b 'netscape'

      Check to see if Document Services is installed
      dss=$(/usr/bin/lslpp -q -l -c bos.docsearch.rte)

      if [[ -z $dss ]]; then
	#DSS is not installed
	print "RETURN=simple2"
      else
	#Check to see if web server is installed
	server=$(/usr/bin/lslpp -q -l -c internet_server.base.httpd)
	if [[ -z $server ]]; then
	  #Server is not installed
	  print "RETURN=simple3"
	else

          # Call chwebconfig to configure Documentation server 
          #    with default values(Lotus Go webserver)

          /usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/lpp/internet/server_root/cgi-bin -d /usr/lpp/internet/server_root/pub
          SUCCESS=$?


          #This is a hack to terminate a TaskGuide variable
          print "a=0"
         if [[ $SUCCESS -eq 0 ]]; then  # return code successful
          print "RETURN=document1"
         else
          print "RETURN=webinfoerror"
         fi

	fi
      fi
    fi
  else
    export type_conf=advanced_conf
    print "RETURN=advanced1"
  fi
}

netscapebranch()
{
  netscapechoice=$1
  print "from=webinfo3"

  # netscape should be installed
  if [[ $netscapechoice = "simple1" ]]; then
      print "RETURN=simple1"

  # else netscape is available via network filesystem, add to /etc/environment
  else

      #Add BROWSER variable to /etc/environment

      /usr/sbin/chwebconfig -C -o BROWSER -b 'netscape'

      dss=$(/usr/bin/lslpp -q -l -c bos.docsearch.rte)

      if [[ -z $dss ]]; then
        #DSS is not installed
        print "RETURN=simple2"
      else
        #Check to see if web server is installed
        server=$(/usr/bin/lslpp -q -l -c internet_server.base.httpd)
        if [[ -z $server ]]; then
          #Server is not installed
          print "RETURN=simple3"
        else

          # Call chwebconfig to configure Documentation server 
          #   with default values(Lotus Go webserver)

          /usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/lpp/internet/server_root/cgi-bin -d /usr/lpp/internet/server_root/pub
          SUCCESS=$?

          #This is a hack to terminate a TaskGuide variable
          print "a=0"
          if [[ $SUCCESS -eq 0 ]]; then  # return code successful
           print "RETURN=document1"
          else
           print "RETURN=webinfoerror"
          fi

        fi
      fi
    fi
}

nscomminstall()
{
  # Install Netscape
 
  installtype=$1 
  device=$2
  dir=$3
  from=$4

  if [[ $installtype = "physical" ]]; then

    devsource=$(echo $device | cut -f1 -d' ')
    temp=$(installp -Ld $devsource | grep Netscape.nav* | cut -f3 -d':')
    temp1=$(installp -Ld $devsource | grep 'Netscape.communicator*.*.rte' | cut -f3 -d':')
    if [[ -z $temp1 ]]; then

        temp1=$(installp -Ld $devsource | grep Netscape.communicator.com | cut -f3 -d':')
       
    fi

    us=$(installp -Ld $devsource | grep 'Netscape.nav-us*')
    us1=$(installp -Ld $devsource | grep 'Netscape.communicator-us*')
    if [[ -z $us1 ]]; then

        us1=$(installp -Ld $devsource | grep Netscape.communicator.us)
       
    fi

  else

    devsource=$dir
    us=$(installp -Ld $devsource | grep 'Netscape.nav-us*')
    us1=$(installp -Ld $devsource | grep 'Netscape.communicator-us*')
    if [[ -z $us1 ]]; then

	us1=$(installp -Ld $devsource | grep Netscape.communicator.us)
	
    fi

    temp=$(installp -Ld $devsource | grep 'Netscape.nav*' | cut -f3 -d':')
    temp1=$(installp -Ld $devsource | grep 'Netscape.communicator*.*.rte' | cut -f3 -d':')
    if [[ -z $temp1 ]]; then

        temp1=$(installp -Ld $devsource | grep Netscape.communicator.com | cut -f3 -d':')
        
    fi

  fi

  oldnet=$(lslpp -lOr -c| grep 'Netscape.nav*' | cut -f3 -d':')
  oldnet1=$(lslpp -lOr -c| grep 'Netscape.communicator*.*.rte' | cut -f3 -d':')
  if [[ -z $oldnet1 ]]; then

      oldnet1=$(lslpp -lOr -c| grep Netscape.communicator.com | cut -f3 -d':') 

  fi

  if [[ -z $oldnet ]] && [[ -z $oldnet1 ]]; then
  #if previously did not have netscape

     if [[ -z $temp ]]; then
     #if navigator is not on the media

        if  [[ -z $temp1 ]]; then
        #if communicator is not on the media

	   if [[ $installtype = "physical" ]]; then

               #media does not have Netscape filesets
               print "RETURN=nonetmediaerr"

	   else
	
	       #directory does not have Netscape filesets
	       print "RETURN=direrr"	
	      
	   fi 
           return 1
           exit 0     

        else
	#media only has communicator

            if [[ -z $us1 ]]; then
            #if media does not contain us encryption

		#uninstall previous version of communicator
                result=`LC_ALL=C lslpp -l | grep Netscape.communicator`
                if [[ -n $result ]]; then
		  /usr/sbin/installp -u 'Netscape.communicator*'
                fi

	        #install export encryption version of netscape communicator
		/usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.communicator.all
		if [[ $? != 0 ]]; then

		     	print "Installation Failed"
			return 1
			exit 0
			
                fi

		grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
		print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment

		if [[ $? = 0 ]]; then

			cp /tmp/environment /etc
			rm /tmp/environment

		fi
	
            else

		#uninstall previous version of communicator
                result=`LC_ALL=C lslpp -l | grep Netscape.communicator`
                if [[ -n $result ]]; then
                  /usr/sbin/installp -u 'Netscape.communicator*'
                fi

	        #install 128 bit encryption version of netscape communicator
		/usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.communicator.all
		if [[ $? != 0 ]]; then

                        print "Installation Failed"
                        return 1
                        exit 0

                fi

		grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
                print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment 

                if [[ $? = 0 ]]; then

                        cp /tmp/environment /etc
                        rm /tmp/environment

                fi

            fi

	    if [[ $from = "tempwebinfo2" ]]; then

                print "RETURN=remote6"

            else
                search=$(lslpp -l | grep 'IMNSearch.rte.com')
                if [[ -z $search ]]; then
                   print "RETURN=searchinstall"
		   exit 0
                else
                   print "RETURN=searchdetected"
                   exit 0
                fi
            fi
        fi
     
      else	
      #if navigator is on media (must be an older bonus pack)
   
         print "RETURN=nschoice"
         print "device="$device
	 print "dir="$dir
         print "from="$from
         print "installtype="$installtype
         exit 0

      fi
  
   else
   #previously had a version of netscape

       if [[ -z $temp ]]; then
       #if navigator is not on the media

          if  [[ -z $temp1 ]]; then
          #if communicator is not on the media

	     if [[ $installtype = "physical" ]]; then

                 #media does not have Netscape filesets
                 print "RETURN=nonetmediaerr"

	     else

		 #directory does not have Netscape filesets
                 print "RETURN=direrr"

	     fi
	     return 1
             exit 0

          else
          #media only has communicator

		if [[ -z $oldnet ]]; then
		#if communicator is currently installed

		    print "comparing versions"
		    temp2=$(installp -Ld $devsource | grep 'Netscape.communicator*.*.rte' | cut -f3 -d':')
		    if [[ -z $temp2 ]]; then

			temp2=$(installp -Ld $devsource | grep Netscape.communicator.com | cut -f3 -d':')

		    fi

		    count=0
		    for i in `echo $oldnet1 | sed 's/\./ /g'`
		    do
		       version1[count]=$i
		       let count="count + 1"
		    done

		    count=0
		    for i in `echo $temp2 | sed 's/\./ /g'`
		    do
		       version2[count]=$i
		       let count="count + 1"
		    done    

		    i=0
		    while [[ $i -lt 4 ]]; do		
		       #compares the versions of netscape

		       if [[ ${version1[i]} -gt ${version2[i]} ]]; then

			  print "RETURN=oldnetvererr"
			  return 1
			  exit 0

		       elif [[ ${version1[i]} -lt ${version2[i]} ]]; then

			  #force install Netscape filesets
			  #checks to see which encrypted version of netscape to use

		          if [[ -z $us1 ]]; then

				#uninstall previous version of communicator
                                result=`LC_ALL=C lslpp -l | grep Netscape.communicator`
                                if [[ -n $result ]]; then
                                  /usr/sbin/installp -u 'Netscape.communicator*'
                                fi

	 		 	#install export encryption version of netscape communicator
				/usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.communicator.all
				if [[ $? != 0 ]]; then

				     print "Installation Failed"
				     return 1
				     exit 0
	
                                fi
			
			 	#make Netscape Communicator the default doc browser
			 	grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
			 	print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment

				 if [[ $? = 0 ]]; then

				     cp /tmp/environment /etc
				     rm /tmp/environment
	
				 fi 

			   else

				 #uninstall previous version of communicator
                                 result=`LC_ALL=C lslpp -l | grep Netscape.communicator`
                                 if [[ -n $result ]]; then
                                   /usr/sbin/installp -u 'Netscape.communicator*'
                                 fi

				 #install 128 bit encryption version of netscape communicator
				 /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.communicator.all
				 if [[ $? != 0 ]]; then

                                     print "Installation Failed"
                                     return 1
                                     exit 0

                                 fi

				 #make Netscape Communicator the default doc browser
				 grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
				 print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment

				 if [[ $? = 0 ]]; then

				     cp /tmp/environment /etc
				     rm /tmp/environment

				 fi

			    fi

			    if [[ $from = "tempwebinfo2" ]]; then

				 print "RETURN=remote6"
				 exit 0

			    else
				 search=$(lslpp -l | grep 'IMNSearch.rte.com')
				 if [[ -z $search ]]; then
				      print "RETURN=searchinstall"
				      exit 0
				 else
				      print "RETURN=searchdetected"
				      exit 0
				 fi
			    fi
			fi
			let i="i + 1"
		     done 
		     
		     if [[ -z $temp ]]; then
	 
			if [[ $from = "tempwebinfo2" ]]; then

			   print "RETURN=remote6"

			else
			   search=$(lslpp -l | grep 'IMNSearch.rte.com')
			   if [[ -z $search ]]; then
			       print "RETURN=searchinstall"
			       exit 0
			   else
	                       print "RETURN=searchdetected"
        	               exit 0
                	   fi
                	fi
		     fi
	        
		 else
		 #communicator currently not installed

		     if [[ -z $us1 ]]; then

			#uninstall previous version of communicator
                         result=`LC_ALL=C lslpp -l | grep Netscape.communicator`
                         if [[ -n $result ]]; then
                           /usr/sbin/installp -u 'Netscape.communicator*'
                         fi

		        #install export encryption version of netscape communicator
			/usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.communicator.all
			if [[ $? != 0 ]]; then

				print "Installation Failed"
				return 1
				exit 0

                        fi
	
		        #make Netscape Communicator the default doc browser
		        grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
		        print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment

   		        if [[ $? = 0 ]]; then

		 	   cp /tmp/environment /etc
			   rm /tmp/environment

                  	fi

	             else

			 #uninstall previous version of communicator
                         result=`LC_ALL=C lslpp -l | grep Netscape.communicator`
                         if [[ -n $result ]]; then
                           /usr/sbin/installp -u 'Netscape.communicator*'
                         fi

			 #install 128 bit encryption version of netscape communicator
			 /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.communicator.all
			 if [[ $? != 0 ]]; then

                                print "Installation Failed"
                                return 1
                                exit 0

                         fi
		
                         #make Netscape Communicator the default doc browser
                         grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
                         print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment 

                         if [[ $? = 0 ]]; then

                             cp /tmp/environment /etc
                             rm /tmp/environment

                         fi

                     fi
		     
		     if [[ $from = "tempwebinfo2" ]]; then

                          print "RETURN=remote6"
                          exit 0

                     else
                          search=$(lslpp -l | grep 'IMNSearch.rte.com')
                          if [[ -z $search ]]; then
                               print "RETURN=searchinstall"
                               exit 0
                          else
                               print "RETURN=searchdetected"
                               exit 0
                          fi
                     fi	     	     		
	         fi
	  fi
	      
     else
     #navigator is on media
	
        print "RETURN=nschoice"
	print "device="$device
	print "dir="$dir
	print "from="$from
	print "installtype="$installtype
	exit 0
		
     fi
			  
  fi

}
	
nsinstall()
{

  navchoice=$1
  device=$2
  dir=$3
  from=$4
  installtype=$5

  if [[ $installtype = "physical" ]]; then

     devsource=$(echo $device | cut -f1 -d' ')
     temp=$(installp -Ld $devsource | grep 'Netscape.nav*' | cut -f3 -d':')
     temp1=$(installp -Ld $devsource | grep 'Netscape.communicator*.*.rte' | cut -f3 -d':')
     if [[ -z $temp1 ]]; then

	temp1=$(installp -Ld $devsource | grep Netscape.communicator.com | cut -f3 -d':')

     fi

     us=$(installp -Ld $devsource | grep 'Netscape.nav-us*')
     us1=$(installp -Ld $devsource | grep 'Netscape.communicator-us*')
     if [[ -z $us1 ]]; then

	us1=$(installp -Ld $devsource | grep Netscape.communicator.com)

     fi

  else

    devsource=$dir
    temp=$(installp -Ld $devsource | grep 'Netscape.nav*' | cut -f3 -d':')
    temp1=$(installp -Ld $devsource | grep 'Netscape.communicator*.*.rte' | cut -f3 -d':')
    if [[ -z $temp1 ]]; then

        temp1=$(installp -Ld $devsource | grep Netscape.communicator.com | cut -f3 -d':')

    fi

    us=$(installp -Ld $devsource | grep 'Netscape.nav-us*')
    us1=$(installp -Ld $devsource | grep 'Netscape.communicator-us*')
    if [[ -z $us1 ]]; then

        us1=$(installp -Ld $devsource | grep Netscape.communicator.com)

     fi
    
  fi

  oldnet=$(lslpp -lOr -c| grep 'Netscape.nav*' | cut -f3 -d':')
  oldnet1=$(lslpp -lOr -c| grep 'Netscape.communicator*.*.rte' | cut -f3 -d':')	
  if [[ -z $oldnet1 ]]; then

	oldnet1=$(lslpp -lOr -c| grep Netscape.communicator.com | cut -f3 -d':')

  fi

  if [[ $navchoice = "navigator" ]]; then

	if [[ -z $oldnet ]]; then
        #if navigator is previously not installed

		if [[ -z $us ]]; then
		#if us encryption is not on media
			
			#uninstall the previous version of navigator
                        result=`LC_ALL=C lslpp -l | grep Netscape.nav`
                        if [[ -n $result ]]; then
                          installp -u 'Netscape.nav*'
                        fi

			#install export encryption of Navigator
			/usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.nav.rte

			#make Netscape Navigator the default doc browser
		 	grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
			print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment
		
			if [[ $? = 0 ]]; then

				cp /tmp/environment /etc
				rm /tmp/environment

			fi

		else
	   	#if US encryption is on media

			#uninstall the previous version of navigator
                        result=`LC_ALL=C lslpp -l | grep Netscape.nav`
                        if [[ -n $result ]]; then
                          installp -u 'Netscape.nav*'
                        fi

                        #install export encryption of Navigator
                        /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.nav-us.rte
	
			#make Netscape Navigator the default doc browser
			grep -v DEFAULT_BROWSER  /etc/environment > /tmp/environment
                        print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment
                
                        if [[ $? = 0 ]]; then

                                cp /tmp/environment /etc
				rm /tmp/environment

                        fi		

                fi
     
         else
         #if Navigator was previously installed
		
		print "comparing versions"
 	        temp2=$(installp -Ld $devsource | grep Netscape.nav | cut -f3 -d':')
       		count=0
       		for i in `echo $oldnet | sed 's/\./ /g'`
       		do
            	    	version1[count]=$i
                	let count="count + 1"
       		done

	        count=0
       		for i in `echo $temp2 | sed 's/\./ /g'`
       		do
        	      	version2[count]=$i
          		let count="count + 1"
       		done

     		i=0
      		while [[ $i -lt 4 ]]; do
         	#compares the versions of netscape

         		if [[ ${version1[i]} -gt ${version2[i]} ]]; then

 		            print "RETURN=oldnetvererr"
 			    return 1
          		    exit 0

 		        elif [[ ${version1[i]} -lt ${version2[i]} ]]; then

 		            #force install Netscape filesets
           		    #checks to see which encrypted version of netscape to use

			    if [[ -z $us ]]; then
			    #if the US encryption of Navigator is not on media

				#uninstall previous version of navigator
                                result=`LC_ALL=C lslpp -l | grep Netscape.navigator`
                                if [[ -n $result ]]; then
                                  /usr/sbin/installp -u 'Netscape.navigator*'
                                fi

				#install export encryption version of netscape navigator
                		/usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.nav.rte

				#make Netscape Navigator default doc browser
				grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
        	                print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment

 	                        if [[ $? = 0 ]]; then
	
       	                            cp /tmp/environment /etc
				    rm /tmp/environment

 	                        fi
				
			    else

				#uninstall previous version of navigator
                                result=`LC_ALL=C lslpp -l | grep Netscape.nav`
                                if [[ -n $result ]]; then
                                  /usr/sbin/installp -u 'Netscape.nav*'	
                                fi

                                #install export encryption version of netscape navigator
                                /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.nav-us.rte

				#make Netscape Navigator default doc browser
				grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
                                print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment

                                if [[ $? = 0 ]]; then
        
                                    cp /tmp/environment /etc
				    rm /tmp/environment

                                fi

 		            fi
			
		            /usr/sbin/chwebconfig -C -o BROWSER -b 'netscape'

 		            if [[ $from = "tempwebinfo2" ]]; then
 
		                print "RETURN=remote6"

 		            #elif [[ $from = "localaccess" ]]; then
           		    else
             			search=$(lslpp -l | grep 'IMNSearch.rte.com')
             			if [[ -z $search ]]; then
                			print "a=0"
                			print "RETURN=searchinstall"
                			exit 0
             			else
                			print "a=0"
                			print "RETURN=searchdetected"
                			exit 0
             			fi

           		    fi	
		        fi
			let i="i + 1"
		 done
          fi	
	  if [[ $from = "tempwebinfo2" ]]; then

 	      print "RETURN=remote6"

 	  else
       	      search=$(lslpp -l | grep 'IMNSearch.rte.com')
       	      if [[ -z $search ]]; then
         	 print "RETURN=searchinstall"
       	      else
          	 print "RETURN=searchdetected"
       	      fi
     	  fi
	   
	  #This is a hack to terminate a TaskGuide variable
  	  print "a=0"	

   else
   #if navchoice=communicator

        if [[ -z $oldnet1 ]]; then
        #if communicator is previously not installed

                if [[ -z $us1 ]]; then
                #if us encryption is not on media

			#uninstall the previous version of Communicator
                        result=`LC_ALL=C lslpp -l | grep Netscape.communicator`
                        if [[ -n $result ]]; then
			  installp -u 'Netscape.communicator*'
                        fi

                        #install export encryption of Communicator
                        /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.communicator.rte


			#make Netscape Communicator default doc browser
			grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
                        print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment

                        if [[ $? = 0 ]]; then
        
                            cp /tmp/environment /etc
			    rm /tmp/environment

                        fi

                else
                #if US encryption is on media

			#uninstall previous version of Communicator
                        result=`LC_ALL=C lslpp -l | grep Netscape.communicator`
                        if [[ -n $result ]]; then
			  installp -u 'Netscape.communicator*'
                        fi

                        #install export encryption of Communicator
                        /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.communicator-us.rte
	
			#make Netscape Communicator default doc browser
                        grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
                        print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment

                        if [[ $? = 0 ]]; then
        
                            cp /tmp/environment /etc
                            rm /tmp/environment

                        fi

                fi

         else
         #if Communicator was previously installed

                print "comparing versions"
                temp2=$(installp -Ld $devsource | grep Netscape.communicator | cut -f3 -d':')
                count=0
                for i in `echo $oldnet1 | sed 's/\./ /g'`
                do
                        version1[count]=$i
                        let count="count + 1"
                done	

                count=0
                for i in `echo $temp2 | sed 's/\./ /g'`
                do
                        version2[count]=$i
                        let count="count + 1"
                done

                i=0
                while [[ $i -lt 4 ]]; do
                #compares the versions of netscape

                        if [[ ${version1[i]} -gt ${version2[i]} ]]; then

                            print "RETURN=oldnetvererr"
			    return 1
                            exit 0

                        elif [[ ${version1[i]} -lt ${version2[i]} ]]; then

                            #force install Netscape filesets
                            #checks to see which encrypted version of netscape to use

                            if [[ -z $us ]]; then
                            #if the US encryption of Communicator is not on media

				#uninstall previous version of communicator
                                result=`LC_ALL=C lslpp -l | grep Netscape.communicator`
                                if [[ -n $result ]]; then
                                  /usr/sbin/installp -u 'Netscape.communicator*'
                                fi

                                #install export encryption version of Commmunicator 
                                /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.communicator.rte

				#make Netscape Communicator default doc browser
               		        grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
                        	print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment

                        	if [[ $? = 0 ]]; then
        
        	                    cp /tmp/environment /etc
                	            rm /tmp/environment

 	                       fi

                            else

				#uninstall previous version of communicator
                                result=`LC_ALL=C lslpp -l | grep Netscape.communicator`
                                if [[ -n $result ]]; then
                                  /usr/sbin/installp -u 'Netscape.communicator*'
                                fi

                                #install export encryption version of netscape Communicator
				/usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f Netscape.communicator-us.rte

				#make Netscape Communicator default doc browser
                                grep -v DEFAULT_BROWSER /etc/environment > /tmp/environment
                                print "DEFAULT_BROWSER=/usr/bin/netscape" >> /tmp/environment

                                if [[ $? = 0 ]]; then
        
                                    cp /tmp/environment /etc
                                    rm /tmp/environment

                               fi


                            fi

                            /usr/sbin/chwebconfig -C -o BROWSER -b 'netscape'

                            if [[ $from = "tempwebinfo2" ]]; then

                                print "RETURN=remote6"

                            #elif [[ $from = "localaccess" ]]; then
                            else
                                search=$(lslpp -l | grep 'IMNSearch.rte.com')
                                if [[ -z $search ]]; then
                                        print "a=0"
                                        print "RETURN=searchinstall"
                                        exit 0
                                else
                                        print "a=0"
                                        print "RETURN=searchdetected"
                                        exit 0
                                fi

                            fi
                        fi
                        let i="i + 1"
                 done
          fi
          if [[ $from = "tempwebinfo2" ]]; then

              print "RETURN=remote6"

          else
              search=$(lslpp -l | grep 'IMNSearch.rte.com')
	      if [[ -z $search ]]; then
                 print "RETURN=searchinstall"
              else
                 print "RETURN=searchdetected"
              fi
          fi

          #This is a hack to terminate a TaskGuide variable
          print "a=0"
	  
   fi
}

dlsinstall()
{
  # Install Document Library Services Search Engine
  device=$1
  remoteserve=$2
  type_conf=$3

  devsource=$(echo $device | cut -f1 -d' ')
  cdversion=$(installp -L -d $devsource | grep IMNSearch.rte.DBCS | cut -f3 -d':')
  oldversion=$(lslpp -lOr | grep IMNSearch.rte.DBCS | cut -f12 -d' ')

  print "remoteserve="$remoteserve
  print "type_conf="$type_conf

  if [[ -z $cdversion ]]; then

        print "RETURN=docerr1"
	return 1
        exit 0

  else
 
     if [[ -z $oldversion ]]; then

        /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f IMNSearch.all

     else

        count=0
        for i in `echo $oldversion | sed 's/\./ /g'`
        do
           version1[count]=$i
           let count="count + 1"
        done

        count=0
        for i in `echo $cdversion | sed 's/\./ /g'`
        do
           version2[count]=$i
           let count="count + 1"
        done

        i=0
        while [[ $i -lt 4 ]]; do

          #compares the versions of the search engine 
          if [[ ${version1[i]} -gt ${version2[i]} ]]; then
            print "RETURN=searcherror"
            exit 0

          elif [[ ${version1[i]} -lt ${version2[i]} ]]; then

            #force install search engine
            /usr/sbin/installp -u IMNSearch.all
	    /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f IMNSearch.all

          fi
          let i="i + 1"
        done

       #PID=$(ps -ef | grep imnadm | grep IMNSearch | cut -c10-15)
       #kill -9 $PID

       #PID=$(ps -ef | grep imqsmdem | grep imqsrv | cut -c10-15)  
       #kill -9 $PID

       #This is a hack to terminate a TaskGuide variable
       print "a=0"
     fi
  fi   
     
     if [[ $? -ne 0 ]]; then
       #Error checking
       print "RETURN=webinfoerror"

     elif [[ $remoteserve = "remoteaccnet" ]]; then
  
       #if path is down the remote user path
       print "RETURN=webserver1"
  
     elif [[ $type_conf = "simple" ]]; then
 
       #if the path is down the simple/no remote user path
       /usr/sbin/chwebconfig -C -o LOCAL -p 49213 -c /var/docsearch/cgi-bin -d /usr/docsearch/html -n localhost
       print "RETURN=installbase"

     elif [[ $type_conf = "advanced" ]]; then
     
       #if the path is the down the advanced path
       print "RETURN=webserver1"

     fi
}

serverinstall()
{
  #Install IHS webserver 
  choice=$1
  device=$2
  dir=$3

  ihstemp=$(lslpp -l | grep http_server)

  if [[ $choice = "physical" ]]; then

    devsource=$(echo $device | cut -f1 -d' ')
    if [[ $devsource != "/usr/sys/inst.images" ]]; then
      /usr/sbin/crfs -v cdrfs -p ro -d $devsource -m /tmp/$$ -A no
      mount -v cdrfs -r $devsource /tmp/$$
      temp=$(LC_ALL=C ls /tmp/$$/usr/sys/inst.images | grep http_server | cut -f11 -d' ')
      unmount /tmp/$$
      rmfs -r /tmp/$$
    else
      temp=$(LC_ALL=C ls $devsource | grep http_server | cut -f11 -d' ')
    fi

    ihsversion=$(installp -Ld $devsource | grep gskre | cut -f3 -d':')
 
    if [[ -z $temp ]]; then
      
       #media does not have IHS filesets
       print "RETURN=docerr1"
       return 1
       exit 0

    else

       if [[ -z $ihstemp ]]; then

	  print "Nothing previously installed"
 
       else

          #uninstall previous IHS
          installp -u 'http_server*'
          installp -u 'gskr*'
       
       fi

       if [[ -z $ihsversion ]]; then

          #install the IHS web server filesets
	  installp -XFaQc -d $devsource http_server
          installp -XFaQc -d $devsource http_server.all
          installp -XFaQc -d $devsource gskrf301.all
	    
	  /usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/HTTPServer/cgi-bin -d /usr/HTTPServer/htdocs

       else

	  installp -XFaQc -d $devsource http_server.all
	  installp -XFaQc -d $devsource gskrf301.all
	  installp -XFaQc -d $devsource gskre301.all

	  /usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/lpp/HTTPServer/share/cgi-bin -d /usr/lpp/HTTPServer/share/htdocs

       fi   

       if [[ $? -eq 0 ]]; then

	   if [[ -z $ihsversion ]]; then

	       print "RETURN=installbase"
	       exit 0

	   else

	       print "RETURN=serverstart"
	       exit 0

	   fi

	else

          print "RETURN=webinfoexit"
	  exit 0
 
        fi
     fi
	
  else
  #Directory choice
 
    devsource=$dir
    temp=$(ls $dir | grep 'http_server.*' | cut -f11 -d' ')
    ihsversion=$(installp -Ld $devsource | grep gskre | cut -f3 -d':')
    currentversion=$(ps -ef | grep /usr/HTTPServer/bin/httpd | grep -v grep)
    currentinit=$(grep ihs /etc/inittab)

    if [[ -z $temp ]]; then
      #media does not have IHS filesets

      print "RETURN=direrr"
      return 1

    else

      if [[ -z $ihstemp ]]; then

	 #IHS not previously installed
 
	 if [[ -z $ihsversion ]]; then

             #install the IHS web server filesets

             installp -XFaQc -d $devsource http_server
             installp -XFaQc -d $devsource http_server.all
             installp -XFaQc -d $devsource gskrf301.all

	     /usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/HTTPServer/cgi-bin -d /usr/HTTPServer/htdocs

         else

             installp -XFaQc -d $devsource http_server.all
             installp -XFaQc -d $devsource gskrf301.all
             installp -XFaQc -d $devsource gskre301.all

	     /usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/lpp/HTTPServer/share/cgi-bin -d /usr/lpp/HTTPServer/share/htdocs

         fi

      else

	 #There is a version of IHS on the computer
	 
	 oldversion=$(lslpp -lc | grep http_server.base.source | cut -f3 -d':')

	 if [[ -z $oldversion ]]; then

		oldversion=$(lslpp -lc | grep http_server.source | cut -f3 -d':')

	 fi


         dirversion=$(installp -Ld $devsource | grep http_server.base.source | cut -f3 -d':')
	 if [[ -z $dirversion ]]; then

		dirversion=$(installp -Ld $devsource | grep http_server.source | cut -f3 -d':')

	 fi

 	 count=0
         for i in `echo $oldversion | sed 's/\./ /g'`
         do
             version1[count]=$i
             let count="count + 1"
         done

         count=0
         for i in `echo $dirversion | sed 's/\./ /g'`
         do
             version2[count]=$i
             let count="count + 1"
         done

         i=0
  
	 while [[ $i -lt 3 ]]; do
         #sees if IHS version is 1.3.6

              if [[ ${version1[i]} -gt ${version2[i]} ]]; then
                   # For IHS 1.3.x (x<6) previously installed
	
		   if [[ -z $currentversion ]]; then

		       print "RETURN=serverstart"
		       exit 0

 	           else

		       print "RETURN=installbase"
		       exit 0

 	           fi	   
	
	      elif [[ ${version1[i]} -lt ${version2[i]} ]]; then
                  #startup 1.3.x (x>6) previously installed

		  installp -u 'http_server*'
 	          installp -u 'gskr*'

 	          if [[ -z $ihsversion ]]; then
 	          #install the IHS web server filesets

             		installp -XFaQc -d $devsource http_server
             		installp -XFaQc -d $devsource http_server.all
             		installp -XFaQc -d $devsource gskrf301.all

			#configure docsearch variables
			/usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/HTTPServer/cgi-bin -d /usr/HTTPServer/htdocs
	 	        print "RETURN=installbase"
		        exit 0

         	  else
   
   	                installp -XFaQc -d $devsource http_server.all
             		installp -XFaQc -d $devsource gskrf301.all
             		installp -XFaQc -d $devsource gskre301.all

			#Configure docsearch variables
			/usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/lpp/HTTPServer/share/cgi-bin -d /usr/lpp/HTTPServer/share/htdocs

                        print "RETURN=serverstart"
                        exit 0
       		  fi
	      fi
	      let i="i + 1"
         done
      fi

      ihsversion=$(installp -Ld $devsource | grep gskre | cut -f3 -d':')
      if [[ -z $ihsversion ]]; then

	    print "RETURN=installbase"

      else

	    print "RETURN=serverstart"

      fi
    fi
  fi

  #This is a hack to terminate a TaskGuide variable
  print "a=0"

}

ihsstartup()
{
  startchoice=$1
  newest="1.3.6"

  ihsversion=$(lslpp -lc | grep http_server.source | cut -f3 -d':')

  if [[ -z $ihsversion ]]; then

	ihsversion=$(lslpp -lc | grep http_server.base.source | cut -f3 -d':')

  fi

  web=$(ps -ef | grep /usr/lpp/HTTPServer/sbin/httpd | grep -v grep)
  
  if [[ -z $web ]]; then

      web=$(ps -ef | grep /usr/HTTPServer/bin/httpd | grep -v grep)

  fi

  init=$(more /etc/inittab | grep ihs)
  lotustemp=$(ps -ef | grep /usr/sbin/httpd | grep -v grep | cut -f4,5 -d' ')
  lotus=$(echo $lotustemp | cut -f1 -d' ')

  if [[ $startchoice = "yes" ]]; then

     if [[ -z $lotus ]]; then

	print "Starting Daemon"

     else

        kill -9 $lotus

     fi

     if [[ -z $web ]]; then
	
	 count=0
         for i in `echo $newest | sed 's/\./ /g'`
         do
             version1[count]=$i
             let count="count + 1"
         done

         count=0
         for i in `echo $ihsversion | sed 's/\./ /g'`
         do
             version2[count]=$i
             let count="count + 1"
         done

         i=0	
	 
	 while [[ $i -lt 3 ]]; do
	 #sees if IHS version is 1.3.6

	      if [[ ${version1[i]} -gt ${version2[i]} ]]; then
		   #startup 1.3.x (x<6) webserver daemon
           	   /usr/lpp/HTTPServer/sbin/httpd
	
		   if [[ -z $init ]]; then

			#add line to if it's 1.3.x (x<6) inittab
           		print "ihshttpd:2:once:/usr/lpp/HTTPServer/sbin/httpd > /dev/console 2>&1" >> /etc/inittab	   
			print "RETURN=installbase"		
			exit 0
	
		   else

			print "RETURN=installbase"
			exit 0
		   fi
   
	      elif [[ ${version1[i]} -lt ${version2[i]} ]]; then

		  #startup 1.3.x (x>=6) webserver daemon
		  /usr/HTTPServer/bin/httpd

		  if [[ -z $init ]]; then      

                        #add line to if it's 1.3.x (x>=6) inittab
			print "ihshttpd:2:once:/usr/HTTPServer/httpd > /dev/console 2>&1" >> /etc/inittab 	
			print "RETURN=installbase"
			exit 0

		  else

			print "RETURN=installbase"
			exit 0

		  fi
	      fi
 	      let i="i + 1"
	 done			

	 #startup 1.3.6 webserver daemon
         /usr/HTTPServer/bin/httpd

         if [[ -z $init ]]; then

              #add line to if it's 1.3.6 inittab
              print "ihshttpd:2:once:/usr/HTTPServer/httpd > /dev/console 2>&1" >> /etc/inittab
              print "RETURN=installbase"
              exit 0

	 else

	      print "RETURN=installbase"
	      exit 0

         fi	      

     fi
 
   else

	print "RETURN=installbase"

   fi
	print "RETURN=installbase"
}

browserchoice1()
{
  advancedchoice1=$1
  print "from=tempwebinfo2"

  #setting default language
  language=$(echo $LANG)
  print "language="$language
  
  #check to see if they want to use netscape
  if [[ $advancedchoice1 = "usenet1" ]]; then
    #Check to see if netscape is installed
    netscape=$(/usr/bin/lslpp -l | grep 'Netscape.*.*rte')
    if [[ -z $netscape ]]; then

	netscape=$(/usr/bin/lslpp -l | grep 'Netscape.*.*.com')

    fi
 
    rm -f /tmp/environment

    if [[ -z $netscape ]]; then
      
      #Netscape is not installed
      print "RETURN=netnotinst1"

    else

      #Add BROWSER variable to /etc/environment
      /usr/sbin/chwebconfig -C -o BROWSER -b 'netscape'
      version=$(/usr/bin/lslpp -qlcOr 'Netscape.nav*.*rte' | cut -f3 -d':')
      version1=$(/usr/bin/lslpp -qlcOr 'Netscape.communicator*.*rte' | cut -f3 -d':')
      if [[ -z $version1 ]]; then

	 version1=$(/usr/bin/lslpp -qlcOr 'Netscape.communicator*.*com' | cut -f3 -d':')

      fi

      #if no navigator previously installed 
      if [[ -z $version ]]; then

	 if [[ -z $version1 ]]; then
	
	      print "RETURN=netscape1"
	      exit 0
	 else

	      print "version1="$version1
	      print "RETURN=netscape2"
              exit 0

	 fi

      else

         if [[ -z $version1 ]]; then

	      print "version="$version
	      print "RETURN=netscape3"
              exit 0

	 else

	      print "version="$version
	      print "version1="$version1
              print "RETURN=netscape4"
	      exit 0

	 fi

      fi
    
   fi
  else

    #if they don't want to use netscape
    print "RETURN=remote5"
  fi
}

browserchoice2()
{
  advancedchoice2=$1
  print "from=localaccess"

  #setting default language
  language=$(echo $LANG)
  print "language="$language

  #check to see if they want to use netscape
  if [[ $advancedchoice2 = "usenet1" ]]; then
    #Check to see if netscape is installed
    netscape=$(/usr/bin/lslpp -l | grep 'Netscape.*.*rte')
    if [[ -z $netscape ]]; then

	netscape=$(/usr/bin/lslpp -l | grep 'Netscape.*.*.com')

    fi

    rm -f /tmp/environment

    if [[ -z $netscape ]]; then

      #Netscape is not installed
      print "RETURN=netnotinst1"

    else

      #Add BROWSER variable to /etc/environment
      /usr/sbin/chwebconfig -C -o BROWSER -b 'netscape'
      version=$(/usr/bin/lslpp -qlcOr 'Netscape.nav*.*rte' | cut -f3 -d':')
      version1=$(/usr/bin/lslpp -qlcOr 'Netscape.communicator*.*rte' | cut -f3 -d':')

      if [[ -z $version1 ]]; then

	 version1=$(/usr/bin/lslpp -qlcOr 'Netscape.communicator*.*com' | cut -f3 -d':')

      fi

      #if no navigator previously installed
      if [[ -z $version ]]; then

         if [[ -z $version1 ]]; then

              print "RETURN=netscape1"
              exit 0
         else

              print "version1="$version1
              print "RETURN=netscape2"
              exit 0

         fi

      else

          if [[ -z $version1 ]]; then

              print "version="$version
              print "RETURN=netscape3"
              exit 0

          else

              print "version="$version
              print "version1="$version1
              print "RETURN=netscape4"
              exit 0

          fi

       fi

    fi     

  else

    #if they don't want to use netscape
    print "RETURN=remote5"
  fi
}      

errorcheck()
{
  from=$1

  if [[ $from = "tempwebinfo2" ]]; then
    print "RETURN=remote6"
  else
    search=$(lslpp -l | grep 'IMNSearch.rte.com')
    if [[ -z $search ]]; then
       print "RETURN=searchinstall"
    else
       print "RETURN=searchdetected"
    fi
  fi
}

simpadv()
{
  simpadvchoice=$1

  print "from=localaccess"
  print "simpadvchoice1="$simpadvchoice 

  #defining default language
  language=$(echo $LANG)
  print "language="$language

  if [[ $simpadvchoice = "simple" ]]; then
    #Check to see if netscape is installed
    netscape=$(/usr/bin/lslpp -l | grep 'Netscape.*.*rte')
    if [[ -z $netscape ]]; then

	 netscape=$(/usr/bin/lslpp -l | grep 'Netscape.*.*.com')

    fi

    rm -f /tmp/environment

    if [[ -z $netscape ]]; then

      #Netscape is not installed
      print "RETURN=netnotinst1"

    else

      #Add BROWSER variable to /etc/environment
      /usr/sbin/chwebconfig -C -o BROWSER -b 'netscape'
      version=$(/usr/bin/lslpp -qlcOr Netscape.nav*.*rte | cut -f3 -d':')
      version1=$(/usr/bin/lslpp -qlcOr 'Netscape.communicator*.*rte' | cut -f3 -d':')

      if [[ -z $version1 ]]; then

	   version1=$(/usr/bin/lslpp -qlcOr 'Netscape.communicator*.*com' | cut -f3 -d':')

      fi

      #if no nvaigator previously installed
      if [[ -z $version ]]; then

	  #if no communicator previously installed 
	  if [[ -z $version1 ]]; then

              print "RETURN=netscape1"
              exit 0
         else

              print "version1="$version1
              print "RETURN=netscape2"
              exit 0

         fi

      else

	 #if no communicator prevoiusly installed
         if [[ -z $version1 ]]; then

              print "version="$version
              print "RETURN=netscape3"
              exit 0

         else

              print "version="$version
              print "version1="$version1
              print "RETURN=netscape4"
              exit 0

         fi

      fi

    fi

  else

      print "RETURN=remoteaccnet"

  fi
}
	
path1()
{
  newnetchoice1=$1
  from=$2

  if [[ $newnetchoice1 = "netmedia" ]]; then
     print "RETURN=netmedia"
  elif [[ $from = "tempwebinfo2" ]]; then
     print "RETURN=remote6"
  elif [[ $from = "localaccess" ]]; then
     search=$(lslpp -l | grep 'IMNSearch.rte.com')
     if [[ -z $search ]]; then
        print "RETURN=searchinstall"
     else
        print "RETURN=searchdetected"
     fi
  fi
} 

path2()
{
  from=$1
  document5choice=$2
  link=$3
  docfiles=$4

  if [[ $document5choice = "document7" ]]; then

     if [[ $from = "base" ]]; then
        print "link=false"
     else
	if [[ $link = "true" ]]; then
	   print "link=true"
	else
	   print "link=false"
	fi
     fi
     print "RETURN=document7"

  elif [[ $document5choice = "document6" ]]; then

     print "docfiles="$docfiles
     print "link=true"
     print "RETURN=document6"

  elif [[ $document5choice = "cancel" ]]; then

     if [[ $from = "base" ]]; then
	print "RETURN=configcomplete"
     else
	if [[ $link = "true" ]]; then
	  print "RETURN=document8"
	else
          print "RETURN=configcomplete"
          print "link="$link
        fi
     fi
  fi
}

path3() 
{
   from=$1
   link=$2

   if [[ $from = "base" ]]; then
      print "RETURN=webinfoexit"
   else
     if [[ $link = "true" ]]; then
        print "RETURN=document8"
      else
        print "RETURN=webinfoexit"
     fi 
   fi 
}

path4()
{
   link=$1
   extchoice=$2

   if [[ $extchoice = "installextdoc" ]]; then
      print "RETURN=installextdoc"
   else
      if [[ $link = "true" ]]; then
         print "RETURN=document8"
      else
         print "RETURN=webinfoexit"
      fi
   fi
}

path5()
{
   remoteserve=$1
   simpadvchoice=$2

   if [[ $remoteserve = "remoteaccnet" ]]; then

      #if path is down the remote user path
      print "RETURN=webserver1"

    elif [[ $simpadvchoice = "simple" ]]; then

      #if the path is down the simple/no remote user path
      /usr/sbin/chwebconfig -C -n localhost -p 49213 -c /var/docsearch/cgi-bin -d /usr/docsearch/html
      print "RETURN=installbase"

    elif [[ $simpadvchoice = "advanced" ]]; then

      #if the path is the down the advanced path
      print "RETURN=webserver1"

    fi
}

path6()
{
   webchoice=$1
   
   if [[ $webchoice = "installihs" ]]; then
      #if they choice to use IHS

      ihs=$(lslpp -l | grep http_server)
      temp=$(lslpp -l | grep http_server.source | cut -f12 -d' ')
      
      if [[ -z $temp ]]; then
	temp=$(lslpp -l | grep http_server.base.source | cut -f7 -d' ')
      fi

      if [[ -z $temp ]]; then
        temp=$(lslpp -l | grep http_server.base.rte)
        temp=$(echo $temp | cut -f2 -d' ')
      fi

      if [[ -z $ihs ]]; then
      #if they do not have IHS	 

	 print "RETURN=installihs"
   
      else
      #if they already have IHS installed it will check what version is currently
      #installed

	 print "ihsversion="$temp
         print "RETURN=ihscheck"	
      #  print "RETURN=installbase"
      
      fi

   else
      #if they choice other server

      print "RETURN=advanced3"

   fi
}

path7()
{
   ihschoice=$1
   ihsversion=$2
   newest="1.3.6"

   init=$(more /etc/inittab | grep ihs)

   if [[ $ihschoice = "new" ]]; then
        print "ihsversion="$ihsversion
        print "RETURN=installihs"

   else

	#ADD CODE
	count=0
        for i in `echo $newest | sed 's/\./ /g'`
        do
            version1[count]=$i
            let count="count + 1"
        done

        count=0
        for i in `echo $ihsversion | sed 's/\./ /g'`
        do
            version2[count]=$i
            let count="count + 1"
        done

        i=0

        while [[ $i -lt 3 ]]; do
        #sees if IHS version is 1.3.6

             if [[ ${version1[i]} -gt ${version2[i]} ]]; then
		  #configures IHS 1.3.x (x<6) doc and cgi-bin directories for documentation use

		  /usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/lpp/HTTPServer/share/cgi-bin -d /usr/lpp/HTTPServer/share/htdocs

	          run=$(ps -ef |grep /usr/lpp/HTTPServer/sbin/httpd | grep -v grep)

                  if [[ -z $run ]]; then
        
                      print "RETURN=serverstart"
		      exit 0
        
                  else

                      print "RETURN=installbase"
		      exit 0

                  fi	  

	     elif [[ ${version1[i]} -lt ${version2[i]} ]]; then
		  
		  #configures IHS 1.3.x (x>6) doc and cgi-bin directories for documentation use 
		  
		  /usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/HTTPServer/cgi-bin -d /usr/HTTPServer/htdocs

		  run=$(ps -ef |grep /usr/HTTPServer/bin/httpd | grep -v grep)

 	          if [[ -z $run ]]; then

 	               print "RETURN=serverstart"
		       exit 0

 	          else

 	               print "RETURN=installbase"
		       exit 0

 	          fi
	     fi
	     let i="i + 1"
	done

	#configures IHS 1.3.6 doc and cgi-bin directories for documentation use

	/usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/HTTPServer/cgi-bin -d /usr/HTTPServer/htdocs

	run=$(ps -ef |grep /usr/HTTPServer/bin/httpd | grep -v grep)

        if [[ -z $run ]]; then

             print "RETURN=serverstart"

        else

             print "RETURN=installbase"

        fi
	

   fi
}

path8()
{
   installchoice1=$1
   from=$2

   if [[ $installchoice1 = "netmedia" ]]; then

	print "RETURN=netmedia" 

   else

 	if [[ $from = "tempwebinfo2" ]]; then

          print "RETURN=remote6"

        else
           
	   search=$(lslpp -l | grep IMNSearch.rte.com)
           if [[ -z $search ]]; then
              print "RETURN=searchinstall"
           else
              print "RETURN=searchdetected"
           fi
        fi	
   fi
}

documenterror()
{
   errorchoice=$1
   occupied=$2
   from=$3
   link=$4

   occupied=$(echo $occupied | cut -f1 -d' ')

   if [[ $errorchoice = "drive" ]]; then
      if [[ $from = "base" ]]; then
         print "RETURN=installbasedoc"
      else
         print "RETURN=installextdoc"
      fi
   elif [[ $errorchoice = "unmount" ]]; then
      unmount $occupied
      if [[ $from = "base" ]]; then
         print "RETURN=installbasedoc"
      else
         print "RETURN=installextdoc"
      fi
   elif [[ $errorchoice = "cancel" ]]; then
      if [[ $from = "base" ]]; then
         print "RETURN=webinfoexit"
      else
         if [[ $link = "true" ]]; then
            print "RETURN=document8"
         else
            print "RETURN=webinfoexit"
         fi
      fi      
    fi
}

docbaseCDinstall() 
{
  docdev=$1
 
  print "from=base"

  devsource=$(echo $docdev | cut -f1 -d' ')
  mounted=$(df | grep $devsource)

  if [[ -z $mounted ]]; then
     #CDROM is free ot be mounted onto

     /usr/sbin/crfs -v cdrfs -p ro -d $devsource -m /tmp/$$ -A no
     mount -v cdrfs -r $devsource /tmp/$$
     temp=$(ls /tmp/$$/usr/sys/inst.images | grep 'bos.html.*.topnav' | cut -f11 -d' ')
     size=$(df | grep /tmp/$$ | cut -f10,11 -d' ')
     let cdsize="$size / 2000"
     print "cdsize="$cdsize
     /usr/sbin/unmount /tmp/$$
     /usr/sbin/rmfs -r /tmp/$$

     if [[ -z $temp ]]; then
        #wrong CD in the CDROM drive

        print "RETURN=docerr1"
	return 1

     else
 
	libfiles=$(/usr/sbin/installp -L -d $devsource | grep html | cut -d":" -f2 | sed 's/$/,/g')
  	sysmgthelp=$(/usr/sbin/installp -L -d $devsource | grep sysmgt.help | grep -v msg | cut -d":" -f2 | sed 's/$/,/g')
	alldocfiles=${libfiles}${sysmgthelp}	
	#/usr/sbin/unmount /tmp/$pid
        #/usr/sbin/rmfs -r /tmp/$pid
        print "docdev="$devsource
	print "alldocfiles="$alldocfiles
        print "RETURN=document5"
     fi

  else
     #CDROM is already mounted to something

     test=$(df | grep $devsource | cut -f3 -d'%')
     occupied=$(echo $test | cut -f1 -d' ')
     print "occupied="$occupied
     print "RETURN=docerr2" 
     return 1

  fi

}

docextCDinstall()
{
  docdev=$1

  print "from=ext"

  devsource=$(echo $docdev | cut -f1 -d' ')
  mounted=$(df | grep $devsource)

  if [[ -z $mounted ]]; then
     #CDROM is free to be mounted onto 

     /usr/sbin/crfs -v cdrfs -p ro -d $devsource -m /tmp/$$ -A no
     mount -v cdrfs -r $devsource /tmp/$$
     size=$(df | grep /tmp/$pid | cut -f10,11 -d' ')
     let cdsize="$size / 2000"
     print "cdsize="$cdsize
     temp=$(ls /tmp/$$/usr/sys/inst.images | grep 'bos.html.*.adapt.hypertext' | cut -f11 -d' ')
     /usr/sbin/unmount /tmp/$$
     /usr/sbin/rmfs -r /tmp/$$

     if [[ -z $temp ]]; then
        #wrong CD in the CDROM drive

        print "RETURN=docerr1"
	return 1

     else

        extlibfiles=$(/usr/sbin/installp -L -d $devsource | grep html | cut -d ":" -f2 | sed 's/$/,/g')
	alldocfiles=${extlibfiles}
        print "docdev="$docdev
        print "alldocfiles="$alldocfiles
        print "RETURN=docmountinst"
     fi

  else

     #CDROM is already mounted to something
  
     test=$(df | grep $devsource | cut -f3 -d'%')
     occupied=$(echo $test | cut -f1 -d' ')
     print "occupied="$occupied
     print "RETURN=docerr2"
     return 1

  fi
}

 
advancedbranch2()
{
  advancedchoice2=$1

  if [[ $advancedchoice2 = "simple3" ]]; then
    # Choice is Lotus Go web server
    #Check to see if Lotus Go is installed

    server=$(/usr/bin/lslpp -q -l -c internet_server.base.httpd)

    rm -f /tmp/environment

    if [[ -z $server ]]; then
      #Server is not installed
      print "RETURN=simple3"
    else

      #Do post install for server
      /usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/lpp/internet/server_root/cgi-bin -d /usr/lpp/internet/server_root/pub

      print "RETURN=document1"
    fi
  else
    # choice is other web server
    print "RETURN=advanced3"
  fi
}

advanced3routine()
{
  server=$1
  cgi=$2
  html=$3
  port=$4

  if [[ $port = "[empty]" ]]; then
     port="80"
  fi

  if [[ $server = "lotus" ]]; then
    #set cgi and html to IBM/Lotus defaults
    cgi="/usr/lpp/internet/server_root/cgi-bin"
    html="/usr/lpp/internet/server_root/pub"
    port="80"

  elif [[ $server = "ibm" ]]; then
    #set cgi and html to IBM/Lotus defaults
    cgi="/usr/lpp/internet/server_root/cgi-bin"
    html="/usr/lpp/internet/server_root/pub"
    port="80"
  fi


  if [[ -d $cgi && -d $html ]]; then
    #Do post install for server

    # Call chwebconfig to configure Documentation server 
    # NON-DEFAULT values (NOT Lotus Go webserver)

    /usr/sbin/chwebconfig -C -o LOCAL -p $port -c $cgi -d $html

    print "RETURN=installbase"
  else
    print "RETURN=advanced4error"
  fi
}

remotebranch1()
{
  print "from=remote1"
  choice=$1
  if [[ $choice = "simple1" ]]; then
    # netscape was chosen
    # Check to see if netscape is installed
    netscape=$(/usr/bin/lslpp -q -l -c Netscape.nav.rte)

    if [[ -z $netscape ]]; then
      #Netscape is not installed
      print "RETURN=simple1"

    else
      #Add BROWSER variable to /etc/environment
      /usr/sbin/chwebconfig -C -o BROWSER -b netscape

      dssclient=$(/usr/bin/lslpp -q -l -c bos.docsearch.client.com)

      if [[ -z $dssclient ]]; then
        # need to install docsearch
        print "RETURN=remote4"
      else
        # get name of remote doc server 
      	print "RETURN=remote6"
      fi
    fi
  else
    # get browser info other than netscape
    print "RETURN=remote5"
  fi
}

remote4command()
{
  device=$1
  #Install DSS CLIENT only
  devsource=$(echo $device | cut -f1 -d' ')
  /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f bos.docsearch.client.com
  RC=$?
  /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $devsource -f bos.docsearch.client.Dt
  
  if [[ $RC -ne 0 ]]; then
    print "RETURN=webinfoerror"
  else
    print "RETURN=remote6"
  fi
}

remote5command()
{

  browser=$1
  from=$2

  /usr/sbin/chwebconfig -C -o BROWSER -b $browser

  #This is a hack to terminate a TaskGuide variable
  print "a=0"

  if [[ $from = "tempwebinfo2" ]]; then
     print "RETURN=remote6"
  elif [[ $from = "localaccess" ]]; then
     search=$(lslpp -l | grep IMNSearch.rte.com)
     if [[ -z $search ]]; then
        print "RETURN=searchinstall"
     else
	print "RETURN=searchdetected"
     fi
  fi 

}

remote6command()
{
  #Add documentation server's hostname to /etc/environment

  machine=$1
  port=$2

  if [[ $machine = "[empty]" ]]; then
     print "RETURN=remoteerr"
     return 0
  fi

  if [[ $port = "[empty]" ]]; then
     port="6411"
  fi

  /usr/sbin/chwebconfig -C -o REMOTE -n $machine -p $port

  #This is a hack to terminate a TaskGuide variable
  print "a=0"

  # Print the relevant environment variable information
  docenvgrep
  print "RETURN=configcomplete"

}

mountdec()
{

  # lists ONLY CD-ROM devices if choice is "mount CD and link library"

  mountinstall=$1
  docdev=$2
  from=$3
  link=$4
  devsource2=$(echo $docdev | cut -f1 -d' ')
  print "devsource2="$devsource2

  if [[ $mountinstall = "mountcd" ]]; then
    # CD mount/link
    value=$(/usr/lib/instl/sm_inst list_devices | grep CD-ROM | awk '{printf("%s!",$0);}')
    devsource=$(echo $docdev | cut -f1 -d' ')

    if [[ $from = "base" ]]; then

       /usr/sbin/crfs -v cdrfs -p ro -d $devsource -m /infocd -A no
       /usr/sbin/mount -v cdrfs -r $devsource /infocd

    else

       /usr/sbin/crfs -v cdrfs -p ro -d $devsource -m /exinfocd -A no
       /usr/sbin/mount -v cdrfs -r $devsource /exinfocd

    fi

    #Link IDD collections
    if [[ $from = "base" ]]; then
       /infocd/linkbasecd
    else
       /exinfocd/linkextcd
    fi

    #This is a hack to terminate a TaskGuide variable
    print "a=0"
    print "alldevice="$value
    print "RETURN=mountcd"

  elif [[ $mountinstall = "document5" ]]; then
    
    # hard drive install
    value=$(/usr/lib/instl/sm_inst list_devices | awk '{printf("%s!",$0);}')
    print "alldevice="$value
    print "RETURN=document5"
  fi

}


mountCD()
{
   device=$1

   devsource=$(echo $device | cut -f1 -d' ')

   /usr/sbin/crfs -v cdrfs -p ro -d $devsource -m /infocd -A no

   mount ${devsource}

   #Link IDD collections
   /infocd/linkbasecd

   #This is a hack to terminate a TaskGuide variable
   print "a=0"

   print "RETURN=webinfoexit"
}

document4install()
{
  doc4options=$1
  docdev=$2
  docudir=$3

  if [[ $doc4options = "physical" ]]; then
    devsource=$docdev
  else
    devsource=$docudir
  fi
  devsource=$(echo $devsource | cut -f1 -d' ')

  #Get all of the book filesets on this media, make them comma separated
  #  to use in listbox plugin
  #alldocfiles=$(installp -L -d $devsource | grep html | cut -d":" -f2 | sed 's/$/,/g')

  libfiles=$(/usr/sbin/installp -L -d $devsource | grep html | cut -d":" -f2 | sed 's/$/,/g')

  sysmgthelp=$(/usr/sbin/installp -L -d $devsource | grep sysmgt.help | grep -v msg | cut -d":" -f2 | sed 's/$/,/g')


  alldocfiles=${libfiles}${sysmgthelp}

  print "alldocfiles="$alldocfiles
  print "RETURN=document5"
}

document_install()
{
  docfiles=$1
  devsource2=$2
  doc7choice=$3
  document5choice=$4
  allfiles=$5
  from=$6
  link=$7

  # need to replace "," with " " in list of books
  allfiles_nocomma=$(echo $allfiles | sed 's/,/ /g')
  docfiles_nocomma=$(echo $docfiles | sed 's/,/ /g')
  
  #Install [ALL] books
  if [[ $document5choice = "all" ]]; then
    bundles_to_install=$allfiles_nocomma
  else
    bundles_to_install=$docfiles_nocomma
  fi

  #Iterate thru list of bundles
  for current_bundle in $bundles_to_install
  do
    /usr/sbin/geninstall -d $devsource2 -I acgNQqwX -Z -f /usr/sys/inst.data/sys_bundles/$current_bundle 
    rc=$?
    #This is a hack to terminate a TaskGuide variable
    #print "a=0"
    if [[ $rc -ne 0 ]]; then
      print "RETURN=webinfoerror"
      exit $rc
    fi
  done

  #This is a hack to terminate a TaskGuide variable
  #print "a=0"
  print "RETURN=configcomplete"
}

docfix()
{
  removelinks=$1
  
  if [[ $removelinks = "true" ]]; then
    #Run IDD's unlink command
    /usr/sbin/resolve_links  
  fi
  print "RETURN=webinfoexit"

}

detectnetscape()
{
  value=$(/usr/lib/instl/sm_inst list_devices | grep -v /usr/sys/inst.images | awk '{printf("%s!",$0);}')
  alldevice=${value%!}
  print "alldevice=$alldevice"
  netinst=$(/usr/bin/lslpp -cL | cut -d':' -f 2 | grep Netscape.communicator.com)
  if [[ -z $netinst ]]; then
    print "RETURN=browsernonetscape"
  else
    print "RETURN=browsernetscape"
  fi
}

netscapeconfig()
{
  # Chose to use installed version of Netscape
  # Make BROWSER variable in /etc/environment point to netscape
        default=$1
        alternate=$2

        if [[ "$default" = "yes" ]]; then
                /usr/sbin/chwebconfig -C -o BROWSER -b 'netscape'
                print "RETURN=tempwebinfo2"
        else
                # See if the path is empty
                if [[ "$alternate" = "[empty]" ]]; then
                        # Empty path - redirect to error panel
                        print "RETURN=netpatherr"
                else
                        # Make BROWSER variable in /etc/environment point to $alternate
                        /usr/sbin/chwebconfig -C -o BROWSER -b $alternate
                        print "RETURN=tempwebinfo2"
                fi
        fi
}

nonetscapeconfig()
{
        default=$1
        alternate=$2

        if [[ $default = "yes" ]]; then
                print "RETURN=netmedia"
        else
                # Configure the browser passed as a parameter

                # See if the path is empty
                if [[ "$alternate" = "[empty]" ]]; then
                        # Empty path - redirect to error panel
                        print "RETURN=netpatherr"
                else
                        # Make BROWSER variable in /etc/environment point to $alternate
                        /usr/sbin/chwebconfig -C -o BROWSER -b $alternate
                        print "RETURN=tempwebinfo2"
                fi
        fi
}

netinstall()
{
        # Installtype is either dir or physical
        installtype=$1

        # Netdev is the device to install from if $installtype=physical
        # Format is "/dev/xxx (Device description)"
        netdev=$(echo $2 | cut -d' ' -f1)

        # Dirpath is the directory to install from if $installtype=dir
        dirpath=$3

        if [[ "$installtype" = "dir" ]]; then
                netdev=$dirpath
        fi

        # Test for Netscape.communicator.com fileset on media
        nsversion=$(installp -Ld $netdev | grep Netscape.communicator.us | cut -d':' -f3)

        # Fileset was not found on media
        if [[ -z $nsversion ]]; then
                # Redirect to appropriate error panel based on $installtype
                if [[ "$installtype" = "dir" ]]; then
                        print "RETURN=direrr"
                else
                        print "RETURN=nonetmediaerr"
                fi

                return 0
        fi

        # Install Netscape.communicator.com fileset
        /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $netdev -f Netscape.communicator.com

        if [[ $? != 0 ]]; then
                print "Installation Failed"
                return 0
        fi

        # If the installation completed successfully, set up netscape
        # as the default browser
  /usr/sbin/chwebconfig -C -o BROWSER -b 'netscape'

  print "RETURN=tempwebinfo2"
}

serverchoice()
{
  selection=$1

  if [[ $selection = "IHS" ]]; then
    # Check for IHS already installed
    ihs=$(/usr/bin/lslpp -cL | cut -d':' -f 2 | grep http_server)
    if [[ -z $ihs ]]; then
      print "RETURN=installihs"
    else
      /usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/HTTPServer/cgi-bin -d /usr/HTTPServer/htdocs -n localhost
      # Print environment variables
      docenvgrep
      print "RETURN=installbase"
    fi
  elif [[ $selection = "lite" ]]; then
    lite=$(/usr/bin/lslpp -l | grep IMNSearch.rte.httpdlite)
    if [[ -z $lite ]]; then
      print "RETURN=serverpatherr"
      return 0
    fi
    /usr/sbin/chwebconfig -C -o LOCAL -p 49213 -c /var/docsearch/cgi-bin -d /usr/docsearch/html -n localhost
     # Print environment variables
    docenvgrep
    print "RETURN=installbase"
  else
    port=$2
    cgidir=$3
    htmldir=$4
    if [[ "$port" = "[empty]" ]]; then
      print "RETURN=servererr"
      return 0
    fi

    if [[ -d $cgidir && -d $htmldir ]]; then
      /usr/sbin/chwebconfig -C -o LOCAL -p $port -c $cgidir -d $htmldir -n localhost
      # Print environment variables
      docenvgrep
      print "RETURN=installbase"
    else
      print "RETURN=serverpatherr"
    fi
  fi
}

ihslicense()
{

  #Installtype is either dir or physical
  installtype=$1

  # Netdev is the device to install from if $installtype=physical
  # Format is "/dev/xxx (Device description)"
  netdev=$(echo $2 | cut -d' ' -f1)

  # Dirpath is the directory to install from if $installtype=dir
  dirpath=$3

  if [[ "$installtype" = "dir" ]]; then
     netdev=$dirpath
  fi

  # Preview IHS licenses
  /usr/lib/instl/sm_inst installp_cmd -apE -d $netdev -f http_server.all

  if [[ $? = 0 ]]; then
     print "RETURN=ihslicenseprompt"
  else
     print "RETURN=installsw_finish_failure_panel"
  fi
}

  
# Function incomplete
ihsinstall()
{
  # Accept license
  accepted=$1
  if [[ "$accepted" = "no" ]]; then
    print "RETURN=serverselect"
    return 0
  fi

  # Installtype is either dir or physical
  installtype=$2

  # Netdev is the device to install from if $installtype=physical
  # Format is "/dev/xxx (Device description)"
  netdev=$(echo $3 | cut -d' ' -f1)

  # Dirpath is the directory to install from if $installtype=dir
  dirpath=$4

  if [[ "$installtype" = "dir" ]]; then
     netdev=$dirpath
  fi

  # Install IHS filesets
  /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $netdev -f gskkm.rte
  /usr/lib/instl/sm_inst installp_cmd -aQNgXGY -d $netdev -f http_server.all

  if [[ $? != 0 ]]; then
     print "RETURN=installsw_finish_failure_panel"
     return 0
  fi

  # If the installation completed successfully, set up ihs
  # as the documentation server
  /usr/sbin/chwebconfig -C -o LOCAL -p 80 -c /usr/HTTPServer/cgi-bin -d /usr/HTTPServer/htdocs -n localhost

  # Start the server
  /usr/HTTPServer/bin/httpd -f /usr/HTTPServer/conf/httpd.conf >/dev/console 2>&1 &

  docenvgrep
  print "RETURN=installbase"
}

docenvgrep()
{
  setbrowser=$(grep "^DEFAULT_BROWSER=" /etc/environment | cut -f2 -d'=')
  docserver=$(grep "^DOCUMENT_SERVER_MACHINE_NAME=" /etc/environment | cut -f2 -d'=')
  docport=$(grep "^DOCUMENT_SERVER_PORT=" /etc/environment | cut -f2 -d'=')
  doclang=$(grep "^DOC_LANG=" /etc/environment | cut -f2 -d'=')
  print "setbrowser=$setbrowser"
  print "docserver=$docserver"
  print "docport=$docport"
  if [[ -z $doclang ]]; then
    print "doclang=C"
  else
    print "doclang=$doclang"
  fi
}

confirmapplet()
{
  cfgassistchoice=$1
  docdir="$2"
  lang="$3"
  cgidir="$4"

  if [[ $cfgassistchoice = "cfgassist2" ]]; then
     errror=$(wsmappletcfg -unconfig)
     if [[ $? = 0 ]]; then
        print "RETURN=cfgassist2"
     else
        print "error="$error
        print "RETURN=cfgassist_fail"
     fi
  elif [[ $cfgassistchoice = "cfgassist3" ]] ; then
     appletcfg "$docdir" "$lang" "$cgidir"
     return;  #appletcfg has its own RETURN
  else 
     print "hostname=$(host $(hostname) | awk '{print $1}')"
     print "RETURN=$cfgassistchoice"
  fi


}

appletcfg()
{
  homedir="$1"
  lang="$2"
  cgidir="$3"
  
  error=$(wsmappletcfg -docdir "$homedir" -cgidir "$cgidir" -lang "$lang" 2>&1)
  if [[ $? = 0 ]]; then
     wsmserver -enable
     print "RETURN=cfgassist3"
  else
     print "error="$error
     print "RETURN=cfgassist_fail"
  fi

}

nav15()
{
   if [[ $1 = "p16" ]]; then
      print "RETURN=p16"
   elif [[ $2 = "p17" ]]; then
      print "RETURN=p17"
   elif [[ $3 = "p18" ]]; then
      print "RETURN=p18"
   else
      print "RETURN=p2"
   fi

   print "p2var=p19"
}

nav16()
{
   if [[ $1 = "p17" ]]; then
      print "RETURN=p17"
   elif [[ $2 = "p18" ]]; then
      print "RETURN=p18"
   else
      print "RETURN=p2"
   fi

   print "p2var=p19"
}

nav17()
{
   #This is the closing screen function that can remove config assistant from
   #inittab
      if [[ $1 = "false" ]]; then
         #Just remove config assistant from inittab
         /usr/lib/assist/exit_assistant -i
      else
	 mkitab -i cron "install_assist:2:wait:/usr/sbin/install_assist </dev/console >/dev/console 2>&1"
      fi
   cleanup
   print "RETURN=sg-quit"
}

runcmd()
{
  #This function does run the command and generate a configassist.log under $HOME
  echo "--------------------Start--------------------" > $HOME/configassist.log
  eval date >> $HOME/configassist.log
  echo "Command = $1" 2>&1 |tee -a $HOME/configassist.log
  eval $1 2>&1 |tee -a $HOME/configassist.log
  echo "---------------------End---------------------" >> $HOME/configassist.log
  eval date >> $HOME/configassist.log
  echo "configassist.log has been generated in $HOME"
}

installcheck()
{
   #This function does the update_all install preview
   devsource=$(echo $1 | cut -f1 -d' ')
   /usr/lib/instl/sm_inst installp_cmd -a -g -c -N -d $devsource -f '_update_all' -p 2>&1
   print "RETURN=sg-exit-done" # MMF - 319117
}

getTime()
{
	value=$(date +"%B")
	print "defmonth="$value
 
        value=$(/usr/bin/locale -k LC_TIME | grep '^mon' | cut -f2 -d'=' | sed "s/\";\"/,/g" | cut -f2 -d'"')
	print "allmonth="$value

	value=$(date +"%d")
	print "defday="$value

	value=$(date +"%Y")
	print "defyear="$value

	if [[ $1 = "p4a" ]]; then
	  value=$(date +"%H")
	  print "defhour="$value
	else
	  value=$(date +"%I")
	  print "defhour="$value
	  value=$(date +"%p")
	  print "ampm="$value
	fi

	value=$(date +"%M")
	print "defminute="$value

	value=$(date +"%S")
	print "defsecond="$value

 	value=$(dspmsg smit.cat -s 30 7 | cut -c21- | awk '{printf("%s,",$0);}')
	print "alltz="$value

	value=$(dspmsg smit.cat -s 30 7 | grep $TZ | cut -c21-)
	print "deftz="$value

}

getFirstPanel()
{
        #Check if automount is enabled
        /usr/bin/lssrc -a | grep cdromd  | grep -v inoperative > /dev/null 2>&1
        if [[ $? -eq 0 ]]; then
           print "CDAUTOMOUNT=yes"
           /usr/sbin/cdutil -sk 
        fi

	/usr/sbin/inulag -qa

        if [[ $? -eq 0 ]]; then
          print "RETURN=license"
	else
	  rm /tmp/.config_lic_not_accepted
	  print "RETURN=p1"
        fi
     
}

showLicense()
{
	/usr/sbin/inulag -lav
	print "\nRETURN=sg-exit-done" # MMF - 319117
}

acceptLicense()
{
	/usr/sbin/inulag -A
	rm /tmp/.config_lic_not_accepted
	print "RETURN=p1"
}

listdevices()
{
        DEFAULT_DEVICE=`grep INSTALL_DEVICE /var/adm/sw/__assistinfo 2>/dev/null | cut -f2 -d'='`
        if [[ -n $DEFAULT_DEVICE ]]
        then
           /usr/lib/instl/sm_inst list_devices | grep -q $DEFAULT_DEVICE
           if [[ $? -ne 0 ]]
           then
              def=$DEFAULT_DEVICE"!"
           fi
        fi
	value=$(/usr/lib/instl/sm_inst list_devices | grep -v /usr/sys/inst.images | awk '{printf("%s!",$0);}')
	print "alldevice=$def$value"
}

detectmozilla()
{
  listdevices
  netinst=$(/usr/bin/lslpp -cL | cut -d':' -f 2 | grep Mozilla.base)
  if [[ -z $netinst ]]; then
    print "RETURN=browsernomozilla"
  else
    print "RETURN=browsermozilla"
  fi
}

mozillaconfig()
{
  # Chose to use installed version of Mozilla
  # Make BROWSER variable in /etc/environment point to mozilla
        default=$1
        alternate=$2

        if [[ "$default" = "yes" ]]; then
                /usr/sbin/chwebconfig -b 'mozilla'
                print "RETURN=serverchoice"
        else
                # See if the path is empty
                if [[ "$alternate" = "[empty]" ]]; then
                        # Empty path - redirect to error panel
                        print "RETURN=netpatherr"
                else
                        # Make BROWSER variable in /etc/environment point to $alternate
                        /usr/sbin/chwebconfig -b "$alternate"
                        print "RETURN=serverchoice"
                fi
        fi
}

nomozillaconfig()
{
#        default=$1
        alternate=$1

#        if [[ $default = "yes" ]]; then
#                print "RETURN=netmedia"
#        else

        # Configure the browser passed as a parameter
        # See if the path is empty
        if [[ "$alternate" = "[empty]" ]]; then
	    # Empty path - redirect to error panel
            print "RETURN=netpatherr"
        else
	    # Make BROWSER variable in /etc/environment point to $alternate
            /usr/sbin/chwebconfig -b "$alternate"
            print "RETURN=serverchoice"
        fi

#        fi
}

checkdevice()
{
	# Check if device is valid
	SAVE_LANG=$LANG
	LANG=C
        devsource=$(echo $1 | cut -d' ' -f1)
	read x 2>/tmp/configassist.checkDevice < $devsource
	READY=`grep "not ready" /tmp/configassist.checkDevice`
	LANG=$SAVE_LANG
	if [ -n "${READY}" ]
	then
	    rm /tmp/configassist.checkDevice
	    print "RETURN=docerrbadmedia"
	    return 1
	fi
}

netinstallmozilla()
{
        # Installtype is either dir or physical
        installtype=$1

        # Netdev is the device to install from if $installtype=physical
        # Format is "/dev/xxx (Device description)"
        netdev=$(echo $2 | cut -d' ' -f1)

        # Dirpath is the directory to install from if $installtype=dir
        dirpath=$3

        if [[ "$installtype" = "dir" ]]; then
                netdev=$dirpath
        fi

        # Test for Mozilla.base fileset on media
        nsversion=$(installp -Ld $netdev | grep Mozilla.base | cut -d':' -f3)

        # Fileset was not found on media
        if [[ -z $nsversion ]]; then
                # Redirect to appropriate error panel based on $installtype
                if [[ "$installtype" = "dir" ]]; then
                        print "RETURN=direrr"
                else
                        print "RETURN=nonetmediaerr"
                fi

                return 0
        fi

        # Install Mozilla.base fileset
        /usr/lib/instl/sm_inst installp_cmd -aQNgXG -d $netdev -f Mozilla.base

        if [[ $? != 0 ]]; then
                print "Installation Failed"
                return 0
        fi

        # If the installation completed successfully, set up mozilla
        # as the default browser
	/usr/sbin/chwebconfig -b 'mozilla'

  print "RETURN=serverchoice"
}

listInfocenterBundles()
{
    docdev=$1
    print "from=base"
    devsource=$(echo $docdev | cut -f1 -d' ')
    SAVE_LANG=$LANG
    LANG=C
    read x 2>/tmp/configassist.checkDevice < $devsource
    READY=`grep "not ready" /tmp/configassist.checkDevice`
    LANG=$SAVE_LANG
    if [ -n "${READY}" ]
    then
	rm /tmp/configassist.checkDevice
	print "RETURN=docerrbadmedia"
	return 1
    else
	alldocfiles=$(/usr/bin/ls /usr/sys/inst.data/sys_bundles | grep infocenter | sed 's/$/,/g')
	if [[ -z $alldocfiles ]]; then
	    #wrong CD in the CDROM drive
	    print "RETURN=docerr1"
	    return 1
	else
	    print "docdev="$devsource
	    print "alldocfiles="$alldocfiles
	    print "RETURN=document5"
	fi
    fi
}

listInfocenterFilesets()
{
    docdev=$1
    print "from=base"
    devsource=$(echo $docdev | cut -f1 -d' ')
    SAVE_LANG=$LANG
    LANG=C
    read x 2>/tmp/configassist.checkDevice < $devsource
    READY=`grep "not ready" /tmp/configassist.checkDevice`
    LANG=$SAVE_LANG
    if [ -n "${READY}" ]
    then
        rm /tmp/configassist.checkDevice
        print "RETURN=docerrbadmedia"
        return 1
    else
        alldocfiles=$(/usr/sbin/geninstall -L -d $devsource | grep infocenter | cut -d":" -f2 | sed 's/$/,/g')
        if [[ -z $alldocfiles ]]; then
            #wrong CD in the CDROM drive
            print "RETURN=docerr1"
            return 1
        else
            print "docdev="$devsource
            print "alldocfiles="$alldocfiles
            print "RETURN=document5"
        fi
    fi
}

docenvgrep2()
{
  setbrowser=$(grep "^DEFAULT_BROWSER=" /etc/environment | cut -f2 -d'=')
  docserver=$(/usr/sbin/chwebconfig | grep IC_DOCUMENT_SERVER_MACHINE_NAME | cut -f2 -d'=')
  docport=$(/usr/sbin/chwebconfig | grep IC_DOCUMENT_SERVER_PORT | cut -f2 -d'=')
  print "setbrowser=$setbrowser"
  print "docserver=$docserver"
  print "docport=$docport"
}

detectIHS()
{
    # checks to see if IBM HTTP Server version 2 is installed and where it is installed
    # IHS2       2.0.27.0   C   P   IBM HTTP Server (/usr/HTTPServer)    
    # lslpp -aL IHS2  

    # checks to see if IBM HTTP Server version 1.3.19.4 or earlier is installed
    # http_server.base.rte    1.3.19.4   C   F   HTTP Server Base Run-Time
    # http_server.base.source 1.3.19.4   C   F   HTTP Server Source Code
    installIHS1=$(lslpp -L | grep http_server)
    installIHS2=$(lslpp -L | grep IHS2)

    # if IHS is installed, make sure it is installed in one of the default locations 
    # by finding the web server's bin directory, either in /usr/HTTPServer or /usr/IBMIHS.
    serverinfo=$(wsmappletcfg -query)
    ihsexe=$(echo $serverinfo | awk -F'|' '{print $5}')
#    direxe=$(dirname $ihsexe)
    print "docdir=$(echo $serverinfo | awk -F'|' '{print $1}')"
    print "cgidir=$(echo $serverinfo | awk -F'|' '{print $2}')"
    print "port=$(echo $serverinfo | awk -F'|' '{print $6}')"
    print "cmd=$ihsexe"
    print "lang=$(wsmappletcfg -querycurrentlang)"
    print "languages=$(wsmappletcfg -querylang)"
    print "hostname=$(hostname)"

#    if [[ -n $installIHS1 && $direxe = "/usr/HTTPServer/bin" ]]; then
    if [[ -n $installIHS1 && -d "/usr/HTTPServer/bin" ]]; then
	print "RETURN=cfgassistconf"
    elif [[ -n $installIHS2 ]]; then
#	if [[ $direxe = "/usr/HTTPServer" || $direxe = "/usr/IBMIHS/bin" ]]; then
	if [[ -d "/usr/HTTPServer" || -d "/usr/IBMIHS/bin" ]]; then
	    print "RETURN=cfgassistconf"
	fi
    else
	print "RETURN=cfgassistIHSnotfound"
    fi
}

shift
"$@" 
# $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} ${12} ${13} ${14} ${15} ${16}
