#! /bin/bash
#
# SyAM Linux Install Script
#   Chris Chisholm
#  October 20, 2005
#
# (changed to multi-file project February 5, 2009)
#

#//include menus and related functions
#########################################
####Menus

#------------------------------------------------------------------------------------------
#Language/Locale Selection

mnuLocale()
{
  insGen_mnuSel=-1
  while [ "$insGen_mnuSel" != "$fc" ]
  do

  clear
  echo -e "\033[1;44;33m================================================================="
  echo -e "|\033[1;36m Please Choose a Language                                       "
  echo -e "\033[1;33m=================================================================\033[0m"
  echo ""
  echo ""
  if [ "$insGen_locale" = "en" ]; then echo -n "*"; else echo -n " "; fi
  echo "[10]English (US)"
  
  if [ "$insGen_locale" = "en_GB" ]; then echo -n "*"; else echo -n " "; fi
  echo "[11]English (UK)"

  if [ "$insGen_locale" = "fr" ]; then echo -n "*"; else echo -n " "; fi
  echo "[12]French"
  
  if [ "$insGen_locale" = "fr_CA" ]; then echo -n "*"; else echo -n " "; fi
  echo "[13]French (Canada)" 

  if [ "$insGen_locale" = "de" ]; then echo -n "*"; else echo -n " "; fi
  echo "[14]German"

  if [ "$insGen_locale" = "pt_BR" ]; then echo -n "*"; else echo -n " "; fi
  echo "[15]Portuguese (Brazil)"

  if [ "$insGen_locale" = "pt" ]; then echo -n "*"; else echo -n " "; fi
  echo "[16]Portuguese (Portugal)"

  if [ "$insGen_locale" = "es" ]; then echo -n "*"; else echo -n " "; fi
  echo "[17]Spanish (Traditional)"

  if [ "$insGen_locale" = "es_AR" ]; then echo -n "*"; else echo -n " "; fi
  echo "[18]Spanish (Mexico)"

  if [ "$insGen_locale" = "ru" ]; then echo -n "*"; else echo -n " "; fi
  echo "[19]Russian"

  if [ "$insGen_locale" = "jp" ]; then echo -n "*"; else echo -n " "; fi
  echo "[20]Japanese"
  
  #echo ""
  #echo ""
  #echo ""
  #echo ""
  #echo ""
  #echo ""
  #echo ""
  #echo ""
  #echo ""
  #echo ""
  #echo ""
  
  echo ""
  echo "                                     ${insMnu_trans[23]}"
  echo ""
  echo " [$fc]next"
  echo ""
  echo -n " enter an option: "

  read insGen_mnuSel

  #handle input

  case $insGen_mnuSel in
   "$fc")
     load_locale $insGen_locale
     ;;
   "10")
     insGen_locale="en"
     ;;
   "11")
     insGen_locale="en_GB"
     ;;
   "12")
     insGen_locale="fr"
     ;;
   "13")
     insGen_locale="fr_CA"
     ;;
   "14")
     insGen_locale="de"
     ;;
   "15")
     insGen_locale="pt_BR"
     ;;
   "16")
     insGen_locale="pt"
     ;;
   "17")
     insGen_locale="es"
     ;;
   "18")
     insGen_locale="es_AR"
     ;;
   "19")
     insGen_locale="ru"
     ;;
   "20")
     insGen_locale="jp"
     ;;

  esac

  done
}


#------------------------------------------------------------------------------------------
#Welcome Menu

mnuWelcome()
{

  insGen_mnuSel=-1
  while [ "$insGen_mnuSel" != "$fc" ] && [ "$insGen_mnuSel" != "$bc" ]
  do

  clear
  echo -e "\033[1;44;33m================================================================="
  echo -en "|\033[1;36m ${insMnu_welcome[0]}"
  if [ ${#insMnu_welcome[@]} -lt 62 ]; then
    for (( i = ${#insMnu_welcome[0]}; i <= 62; i++ ))
    do
      echo -n " "
    done
  fi
  echo ""
  echo -e "\033[1;33m=================================================================\033[0m"
  echo ${insMnu_welcome[1]}
  echo ${insMnu_welcome[2]}
  echo ${insMnu_welcome[3]}
  echo ${insMnu_welcome[4]}
  echo ${insMnu_welcome[5]}
  echo ${insMnu_welcome[6]}
  echo ${insMnu_welcome[7]}
  echo ${insMnu_welcome[8]}
  echo ${insMnu_welcome[9]}
  echo ${insMnu_welcome[10]}
  echo ${insMnu_welcome[11]}
  echo ${insMnu_welcome[12]}
  echo ${insMnu_welcome[13]}
  echo ${insMnu_welcome[14]}
  echo ${insMnu_welcome[15]}
  echo ${insMnu_welcome[16]}
  echo ${insMnu_welcome[17]}
  echo ${insMnu_welcome[18]}
  echo -n ${insMnu_welcome[19]}

  read insGen_mnuSel

  done
}

#------------------------------------------------------------------------------------------
#License Agreement Menu

mnuLicAgree()
{
  insGen_mnuSel=-1
  while [ "$insGen_mnuSel" != "$fc" ] && [ "$insGen_mnuSel" != "$bc" ]
  do

  clear
  echo -e "\033[1;44;33m================================================================="
  echo -en "|\033[1;36m ${insMnu_license[0]}"
  if [ ${#insMnu_license[@]} -lt 62 ]; then
    for (( i = ${#insMnu_license[0]}; i <= 62; i++ ))
    do
      echo -n " "
    done
  fi
  echo ""
  echo -e "\033[1;33m=================================================================\033[0m"
  echo ${insMnu_license[1]}
  echo ${insMnu_license[2]}
  echo ${insMnu_license[3]}
  echo ${insMnu_license[4]}
  echo ${insMnu_license[5]}
  echo ${insMnu_license[6]}
  echo ${insMnu_license[7]}
  echo ${insMnu_license[8]}
  echo ${insMnu_license[9]}
  echo ${insMnu_license[10]}
  echo ${insMnu_license[11]}
  echo ${insMnu_license[12]}
  echo ${insMnu_license[13]}
  echo ${insMnu_license[14]}
  echo ${insMnu_license[15]}
  if [ "$insLicAgree_accepted" = "true" ]; then
    echo ${insMnu_license[16]}
  else
    echo ${insMnu_license[20]}
  fi
  echo ${insMnu_license[17]}
  echo ${insMnu_license[18]}
  echo -n ${insMnu_license[19]}

  read insGen_mnuSel

  #handle user options
  case "$insGen_mnuSel" in
    "$fc") #only allow to continue if agreement is accepted
	if [ "$insLicAgree_accepted" != "true" ]; then
	  insGen_mnuSel=-1 #they didn't agree, so keep them in this menu
 	fi
	;;
    "1") #display the agreement for the user and return them to the menu when they're done
	cat $insGen_license | more
	;;
    "2") #change the 'accepted' variable to true and continue on
	insLicAgree_accepted="true"
	insGen_mnuSel="$fc"
	;;
    "3") #user declines the agreement, abort this script
	exit
	;;
  esac

  done
}

#------------------------------------------------------------------------------------------
#Choose Install Path  Menu

mnuChoosePath()
{
  insGen_mnuSel=-1
  while [ "$insGen_mnuSel" != "$fc" ] && [ "$insGen_mnuSel" != "$bc" ]
  do

  clear
  echo -e "\033[1;44;33m================================================================="
  echo -en "|\033[1;36m ${insMnu_installpath[0]}"
  if [ ${#insMnu_installpath[@]} -lt 62 ]; then
    for (( i = ${#insMnu_installpath[0]}; i <= 62; i++ ))
    do
      echo -n " "
    done
  fi
  echo ""
  echo -e "\033[1;33m=================================================================\033[0m"
  echo ${insMnu_installpath[1]}
  echo ${insMnu_installpath[2]}
  echo ${insMnu_installpath[3]}
  echo ${insMnu_installpath[4]}
  echo ${insMnu_installpath[5]}
  echo ${insMnu_installpath[6]}
  echo ${insMnu_installpath[7]}
  echo "${insMnu_installpath[8]} $insGen_installPath"
  echo ${insMnu_installpath[9]}
  echo ${insMnu_installpath[10]}
  echo ${insMnu_installpath[11]}
  echo ${insMnu_installpath[12]}
  echo ${insMnu_installpath[13]}
  echo ${insMnu_installpath[14]}
  echo ${insMnu_installpath[15]}
  echo ${insMnu_installpath[16]}
  echo ${insMnu_installpath[17]}
  echo ${insMnu_installpath[18]}
  echo -n ${insMnu_installpath[19]}

  read insGen_mnuSel

  #handle user options
  okay="false"
  
  if [ "$insGen_mnuSel" = "1" ]; then
    while [ "$okay" != "true" ]
    do
      old="$insGen_installPath"
      echo -n "${insMnu_trans[26]} " #enter an install path:
      read insGen_installPath
      
      #check for spaces in the install path
      testdir=`echo "$insGen_installPath" | cut -f -1 -d ' '`
      if [ "$testdir" != "$insGen_installPath" ]; then    #there are spaces in the install path
        echo "${insMnu_trans[24]}"  #there can not be spaces in the install path
      elif [ -d "$insGen_installPath" ]; then   #check for existance of install path
        echo -n "$insGen_installPath ${insMnu_trans[25]} [y/n]: " #$insGen_installPath already exists. Overwrite?
        read opt
        if [ "$opt" = "y" ] || [ "$opt" = "Y" ]; then
          okay="true"
        fi
      else
        okay="true"
      fi
    done
  fi

  done

}

#------------------------------------------------------------------------------------------
#Choose Computer Type Menu

mnuComputerType()
{
  insGen_mnuSel=-1
  while [ "$insGen_mnuSel" != "$fc" ] && [ "$insGen_mnuSel" != "$bc" ]
  do

  clear
  echo -e "\033[1;44;33m================================================================="
  echo -en "|\033[1;36m ${insMnu_computertype[0]}"
  if [ ${#insMnu_computertype[@]} -lt 62 ]; then
    for (( i = ${#insMnu_computertype[0]}; i <= 62; i++ ))
    do
      echo -n " "
    done
  fi
  echo ""
  echo -e "\033[1;33m=================================================================\033[0m"
  echo ${insMnu_computertype[1]}
  echo ${insMnu_computertype[2]}
  echo ${insMnu_computertype[3]}
  echo ${insMnu_computertype[4]}
  echo ${insMnu_computertype[5]}
  echo ${insMnu_computertype[6]}
  
  if [ "$insGen_modeSuffix" = "c" ]; then    #if central...
    case "$insGen_modePrefix" in
      "sm")
        echo " [X] ${insMnu_computertype[7]}"
        echo " [ ] ${insMnu_computertype[8]}"
        echo ""
        #echo ""
        #echo ""
      ;;
      "dm")
        echo " [ ] ${insMnu_computertype[7]}"
        echo " [X] ${insMnu_computertype[8]}"
        echo ""
        #echo ""
        #echo ""
      ;;
    esac
  else    #if local...
    case "$insGen_modePrefix" in
      "sm")
        echo " [X] ${insMnu_computertype[7]}"
        echo " [ ] ${insMnu_computertype[8]}"
        if [ "$insGen_vendor" != "Itautec" ] || [ "$insGen_boardchecking" = "false" ]; then
        	echo " [ ] ${insMnu_computertype[9]}"
        fi
        #echo ""
        #echo ""
        #echo ""
      ;;
      "dm")
        echo " [ ] ${insMnu_computertype[7]}"
        echo " [X] ${insMnu_computertype[8]}"
        if [ "$insGen_vendor" != "Itautec" ] || [ "$insGen_boardchecking" = "false" ]; then
        	echo " [ ] ${insMnu_computertype[9]}"
        fi
        #echo ""
        #echo ""
        #echo ""
      ;;
      "nm")
        echo " [ ] ${insMnu_computertype[7]}"
        echo " [ ] ${insMnu_computertype[8]}"
        if [ "$insGen_vendor" != "Itautec" ] || [ "$insGen_boardchecking" = "false" ]; then
        	echo " [X] ${insMnu_computertype[9]}"
        fi
        #echo ""
        #echo ""
        #echo ""
      ;;
    esac
  fi 

  echo ${insMnu_computertype[10]}
  echo ${insMnu_computertype[11]}
  echo ${insMnu_computertype[12]}
  
  if [ "$insGen_modeSuffix" = "c" ]; then
    echo ${insMnu_computertype[13]}
    echo ${insMnu_computertype[14]}
    echo ""
    #echo ""
    #echo ""
  else
    echo ${insMnu_computertype[13]}
    echo ${insMnu_computertype[14]}
    if [ "$insGen_vendor" != "Itautec" ] || [ "$insGen_boardchecking" = "false" ]; then
    	echo ${insMnu_computertype[15]}
    fi
    #echo ""
    #echo ""
    #echo ""
  fi
    
  echo ${insMnu_computertype[16]}
  echo ${insMnu_computertype[17]}
  echo ${insMnu_computertype[18]}
  echo -n ${insMnu_computertype[19]}

  read insGen_mnuSel

  #handle user options
  if [ "$insGen_modeSuffix" = "c" ]; then   #if this is a central type
    case "$insGen_mnuSel" in
      "1")
        insGen_modePrefix="sm"
        ;;
      "2")
  	    insGen_modePrefix="dm"
        ;;
    esac
  else    #local...
    if [ "$insGen_vendor" != "Itautec" ] || [ "$insGen_boardchecking" = "false" ]; then
      case "$insGen_mnuSel" in
        "1")
          insGen_modePrefix="sm"
        ;;
        "2")
          insGen_modePrefix="dm"
        ;;
	    "3")
	      insGen_modePrefix="nm"
	    ;;
      esac
    else
      case "$insGen_mnuSel" in
        "1")
          insGen_modePrefix="sm"
        ;;
        "2")
          insGen_modePrefix="dm"
        ;;
      esac
    fi
  fi


  done

}

#------------------------------------------------------------------------------------------
#Choose Interface Menu

mnuChooseInterface()
{
  insGen_mnuSel=-1
  while [ "$insGen_mnuSel" != "$fc" ] && [ "$insGen_mnuSel" != "$bc" ]
  do

  clear
  echo -e "\033[1;44;33m================================================================="
  echo -en "|\033[1;36m ${insMnu_interfacetype[0]}"
  if [ ${#insMnu_interfacetype[@]} -lt 62 ]; then
    for (( i = ${#insMnu_interfacetype[0]}; i <= 62; i++ ))
    do
      echo -n " "
    done
  fi
  echo ""
  echo -e "\033[1;33m=================================================================\033[0m"
  echo ${insMnu_interfacetype[1]}
  echo ${insMnu_interfacetype[2]}
  echo ${insMnu_interfacetype[3]}
  echo ${insMnu_interfacetype[4]}
  echo ${insMnu_interfacetype[5]}
  echo ${insMnu_interfacetype[6]}
  
  case "$insGen_modeSuffix" in
      "l")
      echo " [X] ${insMnu_interfacetype[7]}"
      echo " [ ] ${insMnu_interfacetype[8]}"
      echo ""
      ;;
      "a")
      echo " [ ] ${insMnu_interfacetype[7]}"
      echo " [X] ${insMnu_interfacetype[8]}"
      echo ""
      ;;
  esac
  
  echo ${insMnu_interfacetype[9]}
  echo ${insMnu_interfacetype[10]}
  echo ${insMnu_interfacetype[11]}
  echo ${insMnu_interfacetype[12]}
  echo ${insMnu_interfacetype[13]}
  echo ${insMnu_interfacetype[14]}
  echo ${insMnu_interfacetype[15]}    
  echo ${insMnu_interfacetype[16]}
  echo ${insMnu_interfacetype[17]}
  echo ${insMnu_interfacetype[18]}
  echo -n ${insMnu_interfacetype[19]}

  read insGen_mnuSel

  #handle user options
  case "$insGen_mnuSel" in
   "1")
     insGen_productType="local"
     insGen_modeSuffix="l"
     ;;
   "2")
     insGen_productType="agent"
     insGen_modeSuffix="a"
     ;;
  esac

  done

}

#------------------------------------------------------------------------------------------
#Choose RMI Port Menu

mnuChooseRMI()
{
  insGen_mnuSel=-1
  while [ "$insGen_mnuSel" != "$fc" ] && [ "$insGen_mnuSel" != "$bc" ]
  do

  clear
  echo -e "\033[1;44;33m================================================================="
  echo -en "|\033[1;36m ${insMnu_rmiport[0]}"
  if [ ${#insMnu_rmiport[@]} -lt 62 ]; then
    for (( i = ${#insMnu_rmiport[0]}; i <= 62; i++ ))
    do
      echo -n " "
    done
  fi
  echo ""
  echo -e "\033[1;33m=================================================================\033[0m"
  echo ${insMnu_rmiport[1]}
  echo ${insMnu_rmiport[2]}
  echo ${insMnu_rmiport[3]}
  echo ${insMnu_rmiport[4]}
  echo ${insMnu_rmiport[5]}
  echo "${insMnu_rmiport[6]} $insGen_RMIport"
  echo ${insMnu_rmiport[7]}
  echo ${insMnu_rmiport[8]}
  echo ${insMnu_rmiport[9]}
  echo ${insMnu_rmiport[10]}
  echo ${insMnu_rmiport[11]}
  echo ${insMnu_rmiport[12]}
  echo ${insMnu_rmiport[13]}
  echo ${insMnu_rmiport[14]}
  echo ${insMnu_rmiport[15]}
  echo ${insMnu_rmiport[16]}
  echo ${insMnu_rmiport[17]}
  echo ${insMnu_rmiport[18]}
  echo -n ${insMnu_rmiport[19]}

  read insGen_mnuSel

  #handle user options
  if [ "$insGen_mnuSel" = "1" ]; then
    echo -n "${insMnu_trans[8]} " #enter a new port number: 
    read insGen_RMIport
  fi


  done

}

#------------------------------------------------------------------------------------------
#Choose SSL Menu

mnuChooseSSL()
{
  insGen_mnuSel=-1
  while [ "$insGen_mnuSel" != "$fc" ] && [ "$insGen_mnuSel" != "$bc" ]
  do

  clear
  echo -e "\033[1;44;33m================================================================="
  echo -en "|\033[1;36m ${insMnu_ssl[0]}"
  if [ ${#insMnu_ssl[@]} -lt 62 ]; then
    for (( i = ${#insMnu_ssl[0]}; i <= 62; i++ ))
    do
      echo -n " "
    done
  fi
  echo ""
  echo -e "\033[1;33m=================================================================\033[0m"
  echo ${insMnu_ssl[1]}
  echo ${insMnu_ssl[2]}
  echo ${insMnu_ssl[3]}
  echo ${insMnu_ssl[4]}
  echo ${insMnu_ssl[5]}
  echo ${insMnu_ssl[6]}
  if [ "$insGen_SSL" = "false" ]; then
    echo "   [ ]${insMnu_ssl[7]}"
    echo "   [X]${insMnu_ssl[8]}"
  else
    echo "   [X]${insMnu_ssl[7]}"
    echo "   [ ]${insMnu_ssl[8]}"
  fi
  echo ${insMnu_ssl[9]}
  echo ${insMnu_ssl[10]}
  echo ${insMnu_ssl[11]}
  echo ${insMnu_ssl[12]}
  echo ${insMnu_ssl[13]}
  echo ${insMnu_ssl[14]}
  echo ${insMnu_ssl[15]}
  echo ${insMnu_ssl[16]}
  echo ${insMnu_ssl[17]}
  echo ${insMnu_ssl[18]}
  echo -n ${insMnu_ssl[19]}

  read insGen_mnuSel

  #handle user input
  if [ "$insGen_mnuSel" = "1" ]; then
    insGen_SSL="true"
  fi
  if [ "$insGen_mnuSel" = "2" ]; then
    insGen_SSL="false"
  fi

  done

}

#------------------------------------------------------------------------------------------
#License Agreement Menu

mnuSummary()
{
  insGen_mnuSel=-1
  while [ "$insGen_mnuSel" != "$fc" ] && [ "$insGen_mnuSel" != "$bc" ]
  do

  clear
  echo -e "\033[1;44;33m================================================================="
  echo -en "|\033[1;36m ${insMnu_summary[0]}"
  if [ ${#insMnu_summary[@]} -lt 62 ]; then
    for (( i = ${#insMnu_summary[0]}; i <= 62; i++ ))
    do
      echo -n " "
    done
  fi
  echo ""
  echo -e "\033[1;33m=================================================================\033[0m"
  echo ${insMnu_summary[1]}
  echo ${insMnu_summary[2]}
  echo ${insMnu_summary[3]}
  echo ${insMnu_summary[4]}
  echo ${insMnu_summary[5]}
  echo ${insMnu_summary[6]}
  echo ${insMnu_summary[7]}
  echo ${insMnu_summary[8]}
  echo ${insMnu_summary[9]}
  echo ${insMnu_summary[10]}
  echo ${insMnu_summary[11]}
  echo ${insMnu_summary[12]}
  echo ${insMnu_summary[13]}
  echo ${insMnu_summary[14]}
  echo ${insMnu_summary[15]}
  echo ${insMnu_summary[16]}
  echo ${insMnu_summary[17]}
  echo ${insMnu_summary[18]}
  echo -n ${insMnu_summary[19]}

  read insGen_mnuSel

  done

}

#------------------------------------------------------------------------------------------
#---------------
#Load Locale
#
#populates the arrays used to display the menus in the selected
#locale.  the menu text is stored in the 'language' folder.  one
#folder exists for each menu, and each contains the various menu
#texts in their respective languages.
#
# $1 is the locale string (i.e., 'en' 'pt_BR' 'de', etc)
#

load_locale()
{
  #load license agreement for chosen language
  insGen_license="$insGen_tempdir/lic/license-$1.txt"	
  
  #misc installer translations
    x=0
    file="$insGen_tempdir/language/misc_install/$1.mnu"
    
    exec 3<&0
    exec 0<$file
    while read line
    do
      insMnu_trans[x]="$line"    
      x=`expr $x + 1`
    done
    exec 0<&3 3<&-
  
  #welcome menu
    x=0
    file="$insGen_tempdir/language/mnu_welcome/$1.mnu"
  
    #replace tokens in language files    
    replace_tok "@@@prod_name@@@" "$insGen_prodName" $file
    
    exec 3<&0     #save stdin to filedescriptor '3'
    exec 0<$file  #$file becomes stdin
    while read line
    do
      insMnu_welcome[x]="$line"
      x=`expr $x + 1`
    done
    exec 0<&3 3<&-  #return to normal stdin and free filedescriptor '3'
    
  #license agreement menu
    x=0
    file="$insGen_tempdir/language/mnu_license/$1.mnu"
    
    exec 3<&0
    exec 0<$file
    while read line
    do
      insMnu_license[x]="$line"    
      x=`expr $x + 1`
    done
    exec 0<&3 3<&-
        
  #choose install path menu
    x=0
    file="$insGen_tempdir/language/mnu_installpath/$1.mnu"
    
    exec 3<&0
    exec 0<$file
    while read line
    do
      insMnu_installpath[x]="$line"     
      x=`expr $x + 1`
    done
    exec 0<&3 3<&- 
    
   #choose computer type
    x=0
    file="$insGen_tempdir/language/mnu_computertype/$1.mnu"
    
    exec 3<&0
    exec 0<$file
    while read line
    do
      insMnu_computertype[x]="$line"      
      x=`expr $x + 1`
    done
    exec 0<&3 3<&-
   
   #choose interface type menu
    x=0
    file="$insGen_tempdir/language/mnu_interfacetype/$1.mnu"
    
    exec 3<&0
    exec 0<$file
    while read line
    do
      insMnu_interfacetype[x]="$line"      
      x=`expr $x + 1`
    done
    exec 0<&3 3<&-
        
   #choose RMI port menu
    x=0
    file="$insGen_tempdir/language/mnu_rmiport/$1.mnu"
    
    exec 3<&0
    exec 0<$file
    while read line
    do
      insMnu_rmiport[x]="$line"      
      x=`expr $x + 1`
    done
    exec 0<&3 3<&-
    
   #SSL menu
    x=0
    file="$insGen_tempdir/language/mnu_ssl/$1.mnu"
    
    exec 3<&0
    exec 0<$file
    while read line
    do
      insMnu_ssl[x]="$line"      
      x=`expr $x + 1`
    done
    exec 0<&3 3<&-
    
   #summary menu
    x=0
    file="$insGen_tempdir/language/mnu_summary/$1.mnu"
    
    exec 3<&0
    exec 0<$file
    while read line
    do
      insMnu_summary[x]="$line"      
      x=`expr $x + 1`
    done
    exec 0<&3 3<&-
}
#---------------
#Menu Flow Control
#
#this menu controls the flow of menus.  it is passed two variables,
#one being the name of the menu that was just visited, the other
#being the nav option (back or next) the user selected at that menu.
#it sets global variable 'insGen_nextFunc' to the name of the next
#menu that should get displayed (called from the main routine)
#

menu_flow_ctrl()
{
  insGen_mnuPrev=$1  #menu this was the previous menu
  insGen_mnuSel=$2   #the menu choice of that menu

  #echo $insGen_mnuPrev
  #echo $insGen_mnuSel

  case $insGen_mnuPrev in
    "start")
        insGen_nextFunc="mnuLocale"
        ;;
    "mnuLocale")
        if [ "$insGen_mnuSel" = "$fc" ]; then
          insGen_nextFunc="mnuWelcome"
        fi
        ;;
    "mnuWelcome")
        if [ "$insGen_mnuSel" = "$bc" ]; then
          insGen_nextFunc="mnuLocale"
        elif [ "$insGen_mnuSel" = "$fc" ]; then
          insGen_nextFunc="mnuLicAgree"
        fi
        ;;
    "mnuLicAgree")
        if [ "$insGen_mnuSel" = "$bc" ]; then
          insGen_nextFunc="mnuWelcome"
        elif [ "$insGen_mnuSel" = "$fc" ]; then
          insGen_nextFunc="mnuChoosePath"
        fi
        ;;
    "mnuChoosePath")
        if [ "$insGen_mnuSel" = "$bc" ]; then
          insGen_nextFunc="mnuLicAgree"
        elif [ "$insGen_mnuSel" = "$fc" ]; then
          insGen_nextFunc="mnuComputerType"
        fi
        ;;
    "mnuComputerType")
        if [ "$insGen_mnuSel" = "$bc" ]; then
          insGen_nextFunc="mnuChoosePath"
        elif [ "$insGen_mnuSel" = "$fc" ]; then
          if [ "$insGen_productType" = "central" ]; then
            insGen_nextFunc="mnuChooseRMI"
          else
            insGen_nextFunc="mnuChooseInterface"
          fi
        fi
        ;;  
    "mnuChooseInterface")
        if [ "$insGen_mnuSel" = "$bc" ]; then
          insGen_nextFunc="mnuComputerType"
        elif [ "$insGen_mnuSel" = "$fc" ]; then
    	    if [ "$insGen_modeSuffix" = "a" ]; then	#if this is an agent install don't ask about SSL
    	  		insGen_SSL="false"
    	    	insGen_nextFunc="mnuSummary"
    	    else
    	    	insGen_nextFunc="mnuChooseSSL"
    	    fi
        fi
        ;;
    "mnuChooseRMI")
        if [ "$insGen_mnuSel" = "$bc" ]; then
          if [ "$insGen_productType" = "central" ]; then
            insGen_nextFunc="mnuComputerType"
          else
            insGen_nextFunc="mnuChooseInterface"
          fi
        elif [ "$insGen_mnuSel" = "$fc" ]; then
          insGen_nextFunc="mnuChooseSSL"
        fi
        ;;
    "mnuChooseSSL")
        if [ "$insGen_mnuSel" = "$bc" ]; then
          if [ "$insGen_productType" = "central" ]; then
            insGen_nextFunc="mnuChooseRMI"
          else
            insGen_nextFunc="mnuChooseInterface"
          fi
        elif [ "$insGen_mnuSel" = "$fc" ]; then
          insGen_nextFunc="mnuSummary"
        fi
        ;;
    "mnuSummary")
        if [ "$insGen_mnuSel" = "$bc" ]; then
          if [ "$insGen_modeSuffix" = "a" ]; then
            insGen_nextFunc="mnuChooseInterface"
          else
            insGen_nextFunc="mnuChooseSSL"
          fi
        elif [ "$insGen_mnuSel" = "$fc" ]; then
      	  insGen_nextFunc="install"
      	fi
        ;;
  esac

}
#---------------
#function copy default translations
copyDefTrans()
{
  case "$insGen_locale" in
    "en")
        for (( i = 0; i <= 15; i++ ))
        do
          insTrans_def[$i]=${insTrans_en[$i]}
        done
      ;;
    "en_GB")
        for (( i = 0; i <= 15; i++ ))
        do
          insTrans_def[$i]=${insTrans_en_GB[$i]}
        done
      ;;
    "de")
        for (( i = 0; i <= 15; i++ ))
        do
          insTrans_def[$i]=${insTrans_de[$i]}
        done
      ;;
    "fr")
        for (( i = 0; i <= 15; i++ ))
        do
          insTrans_def[$i]=${insTrans_fr[$i]}
        done
      ;;
    "fr_CA")
        for (( i = 0; i <= 15; i++ ))
        do
          insTrans_def[$i]=${insTrans_fr_CA[$i]}
        done
      ;;
    "es")
        for (( i = 0; i <= 15; i++ ))
        do
          insTrans_def[$i]=${insTrans_es[$i]}
        done
      ;;
    "es_AR")
        for (( i = 0; i <= 15; i++ ))
        do
          insTrans_def[$i]=${insTrans_es_AR[$i]}
        done
      ;;
    "pt")
        for (( i = 0; i <= 15; i++ ))
        do
          insTrans_def[$i]=${insTrans_pt[$i]}
        done
      ;;
    "pt_BR")
        for (( i = 0; i <= 15; i++ ))
        do
          insTrans_def[$i]=${insTrans_pt_BR[$i]}
        done
      ;;
    "jp")
        for (( i = 0; i <= 15; i++ ))
        do
          insTrans_def[$i]=${insTrans_jp[$i]}
        done
      ;;
    "ru")
        for (( i = 0; i <= 15; i++ ))
        do
          insTrans_def[$i]=${insTrans_ru[$i]}
        done
      ;;
  esac
    
}

#//include general functions
#---------------
#Error Exit Function
#
#this function exits with a specified error.  is it used to standardize
#the way the script exits when a required command was not successful
#

errexit()
{
  echo -e "\033[1;31m[${insTrans_def[2]}]\033[0m" #error
  exit
}
#---------------
#Probe for File/Folder
#
#checks for the existance of a file or folder
#

probe()
{
  if [ -e "$1" ]; then
    insGen_probe="true"
  else
    insGen_probe="false"
  fi
}
#---------------
#Replace Token
#
#replaces a token in a file with a variable.  this is used
#mostly for adding the install directory into config files
#

replace_tok()
{
	tok=$1	#token to replace
	var=$2	#value to replace it with
	file=$3	#file to do it to	
	
	rm -f tempqpazf > /dev/null 2> /dev/null
	sed s%"$tok"%"$var"% $file > /dev/null  >> templqpazf && mv -f templqpazf $file

}
#---------------
#unixEOL
#
#converts a DOS file with CR/LF EOL characters to UNIX
#EOL characters
#

unix_EOL()
{

  #convert from the DOS CR/LF file that sed apparently makes by default
  sed s%.$%% $1 > /dev/null >> templqpazf && mv -f templqpazf $1

}

#//include functions that handle the actual install, and support of install
#---------------
#Add Service
#
#adds a service to the system's default runlevels
#

add_service()
{
	serv=$1
	addsrv_err=0
	
	#chkconfig is the redhat/suse way of adding runlevels
	chkconfig --add $serv > /dev/null 2> /dev/null
  if [ "$?" != "0" ]; then #simply calling the command didn't work...
  	if [ -x "/sbin/chkconfig" ]; then	#...check for non-path existance of chkconfig
	    /sbin/chkconfig --add $serv > /dev/null 2> /dev/null
	    if [ "$?" != "0" ]; then
				addsrv_err=1
	    fi
	  else
	  	addsrv_err=1
	  fi
	fi
	
	#if chkconfig worked, break out of this function
	if [ $addsrv_err == 0 ]; then
		return
	fi
	addsrv_err=0	#reset error check
	
	#rc-update is the gentoo way of adding runlevels  
	rc-update add $serv default > /dev/null 2> /dev/null
	if [ "$?" != "0" ]; then
		if [ -x "/sbin/rc-update" ]; then #check for rc-update if it wasn't in the system path
			/sbin/rc-update add $serv default > /dev/null 2> /dev/null
			if [ "$?" != "0" ]; then
				addsrv_err=1
	    fi
	  else
	  	addsrv_err=1
	  fi
	fi
	
	#if rc-update worked, break out of this function
	if [ $addsrv_err == 0 ]; then
		return
	fi
	addsrv_err=0	#reset error check

	#update-rc.d is the debian/ubuntu way of adding runlevels
	if [ $serv == "smad_remote_console" ]; then
		update-rc.d -f $serv stop 20 0 1 6 . &> /dev/null
		if [ "$?" != "0" ]; then
			if [ -x "/sbin/update-rc.d" ]; then #check for rc-update if it wasn't in the system path
				/sbin/update-rc.d -f $serv stop 20 0 1 6 .  &> /dev/null
				if [ "$?" != "0" ]; then
					addsrv_err=1
		    	fi
		  	else
		  		addsrv_err=1
		  	fi
		fi
	else
		update-rc.d -f $serv defaults 20 1  > /dev/null 2> /dev/null
		# - commented this out because it complained it was already there and would cause exit.
		# ln -s /etc/init.d/$serv  /etc/rc2.d/S20$serv
		if [ "$?" != "0" ]; then
			if [ -x "/sbin/update-rc.d" ]; then #check for rc-update if it wasn't in the system path
				/sbin/update-rc.d -f $serv defaults 20 1  > /dev/null 2> /dev/null
				ln -s /etc/init.d/$serv  /etc/rc2.d/S20$serv
				if [ "$?" != "0" ]; then
					addsrv_err=1
		   		fi
		  	else
		  		addsrv_err=1
		  	fi
		fi
	fi
	#if all methods were tried and none worked, exit with failure
	if [ $addsrv_err == 1 ]; then
		verbose echo "service install problem"
		verbose echo $serv
		errexit
	fi
}
#---------------
#Pre-Install Routine
#
#handles some basic things like temp directory setup,
#some directory probing and package exctraction
#

preinstall()
{
  ##probe for system folders (i.e., which folder acts as /etc/init.d)
  #probe for 'init.d' (check some known possibilities)
  probe "/etc/init.d"
  if [ "$insGen_probe" = "true" ]; then
    insGen_initd="/etc/init.d"
  else
    errexit
  fi

  #probe for 'pam.d'
  probe "/etc/pam.d"
  if [ "$insGen_probe" = "true" ]; then
    insGen_pamd="/etc/pam.d"
  else
    errexit
  fi

	
  #check to see if the product exists... if so, check for upgrade possibility
  ans=0
  insGen_installerr="false"

  verbose echo "${insTrans_def[1]}" #checking for previous versions...

  if [ -e "$insGen_initd/smad" ]; then	
   	
  	#find the path of the current install
  	#ret=`ls -l "$insGen_initd/smad" | awk '{print $11}'` #find out where the init.d/smad symlink references
  	ret=`readlink $insGen_initd/smad`
  	
  	if [ "$?" = "0" ]; then
    	insGen_currInstall=`echo $ret | sed -e 's%/smad$%%'` #cut off the "/smad" part of the path to get the dir the product is currently in
    	
    	#we now know where the current install is located
    	
    	#verify that the install type is the same.. e.g., make sure they're both central or local
    	currProd=`cat $insGen_initd/smad | grep MODE=`
    	currType=`expr substr $currProd 6 2`
    	currMode=`expr substr $currProd 8 1`
    	
    	if [ "$insGen_modeSuffix" = "c" ]; then
    		if [ "$currMode" != "c" ]; then
					verbose echo "${insTrans_def[14]}"
					errexit
				fi
    	elif [ "$insGen_modeSuffix" != "c" ]; then
    		if [ "$currMode" = "c" ]; then
					verbose echo "${insTrans_def[15]}"
					errexit
				fi
    	fi
    	
    	#determine which version it is  		
  		if [ -e "$insGen_currInstall/version" ]; then
  			ver=`cat $insGen_currInstall/version | grep ".[.].."` > /dev/null 2> /dev/null
  			
  			#remove the '.' character from version numbers for integer comparison
  			verThis=${insGen_thisVersion/./}
  			verCurr=${ver/./}
   			if [ $verThis -le $verCurr ]; then #if this version is less than or equal to the one currently installed, we can't upgrade
  				verbose echo "${insTrans_def[7]}" #a previous installation was detected.  please uninstall before reinstalling.
  				exit
  			elif [ $verCurr -ge 310 ]; then #only upgrade from version at or bove 3.10 (see bug 1346)
  				if [ "$insGen_silent" != "true" ]; then
	  				verbose echo "${insTrans_def[8]}" #A previous installation was detected.  Would you like to upgrade [1:yes 2:no]?
		    		read ans
		    		if [ "$ans" != "1" ]; then
	    			verbose echo "${insTrans_def[10]}"	#install aborted
						exit
					fi
				else
					ans=1 #assume that if this is a silent installation, we DO want an upgrade.  if we don't, change this to ans=0 manually, and uncomment the 'exit' on the next line
					#exit #uncomment this line if ans=0 is used.
				fi
			fi
  		  			
  		else #version file not there... this is likely a 3.00 version
  		
  			verbose echo "${insTrans_def[7]}" #a previous installation was detected.  please uninstall before reinstalling.
  			exit
				
  		fi
  		
    else
    	verbose echo "${insTrans_def[11]}"	#warning: previous installation detected but the folder was not found
    	verbose echo "${insTrans_def[12]}"	#continuing with full install..."
  	fi
  fi
  
  #establish a temporary directory
  rm -rf $insGen_tempdir  #remove temp folder if it's there
  mkdir -p $insGen_tempdir
  if [ "$?" != "0" ]; then
    verbose echo $insErr_tempdir
    errexit
  fi

  #extract (untar) install files to temp folder
  verbose echo -n "${insTrans_def[6]} "  #extracting files to temp folder (please be patient)...
  tar -xf $insGen_insPackage -C $insGen_tempdir > /dev/null 2> /dev/null
  if [ "$?" != "0" ]; then
    verbose echo $insErr_untar
    errexit
  fi
  verbose echo -e "\033[1;32m${insMnu_trans[0]}\033[0m"
  
  #move common files from /temp/common to /temp
  cp -rf $insGen_tempdir/common/* $insGen_tempdir > /dev/null 2> /dev/null
  #rm -rf $insGen_tempdir/common > /dev/null 2> /dev/null
  
  #do we perform upgrade actions?
  if [ "$ans" = "1" ]; then
  	insGen_upgrade="true"
  	upgrade_install #if yes launch upgrade_install
  fi
}
#---------------
#Just Before Install
#
#this gets called just before the install() routine.  the reason for this 
#is that a function is needed that is called before the install, but after
#the the user has chosen all their options, or in the case of an upgrade,
#after all the information has been gathered.  the reason to build a whole
#function for this instead of just putting the code as the first thing in
#the install routine is that things in here may need to be called at certain
#times depending on if this is an upgrade, or normal install.  the install
#routine is shared between the two methods and is called "at the same time"
#

just_before_install()
{
  #move files based on chosen computer type (server/desktop/notebook)  
  case "$insGen_modePrefix" in
    "sm")
      cp -rf $insGen_tempdir/server/* $insGen_tempdir #> /dev/null 2> /dev/null
      insGen_fulltype="server"  #used to replace tokens in smcd and smwd
      insGen_fulltypesrvc="SmcService"  #used to replace tokens in smcd and smwd
    ;;
    "dm")
      cp -rf $insGen_tempdir/desktop/* $insGen_tempdir #> /dev/null 2> /dev/null
      insGen_fulltype="desktop"  #used to replace tokens in smcd and smwd
      #insGen_fulltypesrvc="DmcService"  #used to replace tokens in smcd and smwd
      insGen_fulltypesrvc="SmcService"  #used to replace tokens in smcd and smwd
    ;;
    "nm")
      cp -rf $insGen_tempdir/notebook/* $insGen_tempdir #> /dev/null 2> /dev/null
      insGen_fulltype="notebook"  #used to replace tokens in smcd and smwd
      #insGen_fulltypesrvc="DmcService"  #used to replace tokens in smcd and smwd
      insGen_fulltypesrvc="SmcService"  #used to replace tokens in smcd and smwd
    ;;
  esac
  
}
#---------------
#Install Routine
#
#this function performs the installation.  it relies on other functions
#to perform the many actions required by the install.
#

install()
{
  clear

  #create the install directory
  rm -rf "$insGen_installPath" > /dev/null 2> /dev/null
  mkdir -p "$insGen_installPath" > /dev/null 2> /dev/null
  if [ "$?" != "0" ]; then	#couldn't make the directory
    verbose echo $insErr_installPath
    errexit
  fi
  
  #cleanup computer type folders (all files should now be in the temp folder)
  rm -rf $insGen_tempdir/server #> /dev/null 2> /dev/null
  rm -rf $insGen_tempdir/desktop #> /dev/null 2> /dev/null
  rm -rf $insGen_tempdir/notebook #> /dev/null 2> /dev/null
   
  #replace some tokens that were previously set up in the packaging stage in build.xml
  replace_tok "@@@prodMode@@@" "$insGen_fulltype" $insGen_tempdir/system_monitor/conf/smcdwrap.conf
  replace_tok "@@@prodModeService@@@" "$insGen_fulltypesrvc" $insGen_tempdir/system_monitor/conf/smcdwrap.conf
  replace_tok "@@@prodMode@@@" "$insGen_fulltype" $insGen_tempdir/jetty/conf/smwdwrap.conf
  
  #install components
  case "$insGen_productType" in
    "local")
	install_java
	install_agent "basic"
	install_jetty
    ;;
    "central")
	install_java
	install_agent "central"
	install_jetty
	install_SMC
	install_javadb
    ;;
    "agent")
	install_java
	install_agent "basic"
    ;;
  esac
  
  install_vnc_console
  
  #install documentation
  cp -rf $insGen_tempdir/docs/$insGen_locale $insGen_installPath/docs
  
  #install license
  cp $insGen_tempdir/lic/license-$insGen_locale.txt $insGen_installPath/license
  
  #create a version file
  echo "$insGen_thisVersion" > "$insGen_installPath/version"
  echo "prod=$insGen_modePrefix$insGen_modeSuffix" >> "$insGen_installPath/version"
  echo "locale=$insGen_locale" >> "$insGen_installPath/version"
  echo "rmi=$insGen_RMIport" >> "$insGen_installPath/version"
  echo "ssl=$insGen_SSL" >> "$insGen_installPath/version"
  echo "dbversion=1" >> "$insGen_installPath/version"

  #prepare the uninstaller
  verbose echo -n "${insMnu_trans[20]} " #Preparing the uninstaller... 
  cp $insGen_tempdir/uninstall $insGen_installPath
  #unix_EOL "$insGen_installPath/uninstall"
  replace_tok "@@@install_path@@@" "$insGen_installPath" $insGen_installPath/uninstall
  replace_tok "@@@locale@@@" "$insGen_locale" $insGen_installPath/uninstall
  chmod 755 $insGen_installPath/uninstall
  verbose echo -e "\033[1;32m${insMnu_trans[0]}\033[0m"

  #delete temp folder
  verbose echo -n "${insMnu_trans[21]} " #Cleaning up temp files...
  #rm -rf $insGen_tempdir
  verbose echo -e "\033[1;32m${insMnu_trans[0]}\033[0m"

  verbose echo -e "\033[1;34m"
  verbose echo "--- ${insMnu_trans[22]} ---" #--- installation complete ---
  verbose echo -e "\033[0m"

}
#---------------
#Install Java
#
#installs java to the system
#

install_java()
{
  #install java to 'installpath/java'
  verbose echo -n "${insMnu_trans[9]} "  #installing java (will not affect your system java)... 
  cp -fR $insGen_tempdir/java $insGen_installPath
  verbose echo -e "\033[1;32m${insMnu_trans[0]}\033[0m"

  #update java.security with correct .login file location
  replace_tok "@@@java_home@@@" "$insGen_installPath/java" "$insGen_installPath/java/lib/security/java.security"

  chmod 777 $insGen_installPath/java/bin/*

  #echo -e "\033[1;34m"
  #echo "--- ${insMnu_trans[10]} ---" #--- java installed and set up ---
  #echo -e "\033[0m"

}
#---------------
#Install Java DB
#
#installs the Derby database to the system.
#
#

install_javadb()
{
  verbose echo -n "${insMnu_trans[17]} " #installing smc...
  verbose echo -e "\033[1;32m${insMnu_trans[0]}\033[0m"

  #copy files
  cp -rf $insGen_tempdir/javadb $insGen_installPath

  #change file permissions
  chmod 777 $insGen_installPath/javadb/smdb

  #symlink smdb to the system init.d
  ln -fs $insGen_installPath/javadb/smdb $insGen_initd

  #register smcd with the system and start it
  verbose echo -n "${insMnu_trans[18]} " #registering SMC smcd with the system...

  add_service "smdb"

  verbose echo -e "\033[1;32m${insMnu_trans[0]}\033[0m"

  #start SMC
  $insGen_initd/smdb start  

  #echo -e "\033[1;34m"
  #echo "--- ${insMnu_trans[19]} ---" #--- SMC installed and set up ---
  #echo -e "\033[0m"

}
#---------------
#Install Agent
#
#installs the agent to the system
#

install_agent()
{
  #install the agent
  verbose echo "install path: $insGen_installPath"
  verbose echo -n "${insMnu_trans[11]} " #installing the agent...
  cp -rf $insGen_tempdir/system_monitor $insGen_installPath
  cp -f $insGen_tempdir/SupportDir/etc/init.d/smad $insGen_installPath
  cp -f $insGen_tempdir/SupportDir/etc/init.d/smad_remote_console $insGen_initd
  cp -f $insGen_tempdir/SupportDir/$insGen_locale/* $insGen_installPath/system_monitor/remote_console/class
  verbose echo -e "\033[1;32m${insMnu_trans[0]}\033[0m"

  if [ "$insGen_thisVersion" > "3.451" ]; then
  	cp -f $insGen_tempdir/additional/raid/libstorelibir.so $insGen_installPath/system_monitor/agent &> /dev/null
  fi
  
  #if this is not a central install, remove SMC files from system_monitor
  if [ "$1" = "basic" ]; then
    #rm -f $insGen_installPath/system_monitor/alerts.properties
    rm -f $insGen_installPath/system_monitor/event_log.log
    rm -rf $insGen_installPath/system_monitor/conf
    rm -rf $insGen_installPath/system_monitor/bin
    rm -f $insGen_installPath/system_monitor/smcd
  fi
  
  #if this is librix (or appears to be librix), copy librix specific VNC files
  if [ -f "/etc/gentoo-release" ] && [ -f "/etc/librix-release" ]; then #librix 2.0 for sure
  	cp -f $insGen_tempdir/additional/librix_smad/smad-librix.sh $insGen_installPath/smad
  	cp -rf $insGen_tempdir/additional/librix_vnc/remote_console_librix_2/* "$insGen_installPath/system_monitor/remote_console"
  	cp -rf $insGen_tempdir/additional/librix_vnc/remote_console_librix_2/.vnc/* "$insGen_installPath/system_monitor/remote_console/.vnc"
  	replace_tok "@@@install_dir@@@" "$insGen_installPath" $insGen_installPath/system_monitor/remote_console/vncserver
  elif [ -f "/etc/gentoo-release" ]; then	#likely librix 3.0. no librix-release, so impossible to know for sure
    cp -f $insGen_tempdir/additional/librix_smad/smad-librix.sh $insGen_installPath/smad
  	cp -rf $insGen_tempdir/additional/librix_vnc/remote_console_librix_3/* "$insGen_installPath/system_monitor/remote_console"
  	cp -rf $insGen_tempdir/additional/librix_vnc/remote_console_librix_3/.vnc/* "$insGen_installPath/system_monitor/remote_console/.vnc"
  	replace_tok "@@@install_dir@@@" "$insGen_installPath" $insGen_installPath/system_monitor/remote_console/vncserver
  fi
  
  #if this is fedora core 11, copy specific VNC files
  res=`grep -i "fedora" /etc/*release | wc -l` 2> /dev/null
  if [ $res -gt 0 ]; then
  	cp -f $insGen_tempdir/additional/fedore_core11_vnc/vncserver "$insGen_installPath/system_monitor/remote_console"
  	cp -f $insGen_tempdir/additional/fedore_core11_vnc/.vnc/xstartup "$insGen_installPath/system_monitor/remote_console/.vnc"
  	cp -f $insGen_tempdir/additional/fedore_core11_vnc/initd/smad_remote_console "$insGen_initd"
  fi
  
  #if this is CentOS, fonts folder specific VNC files
  res=`grep -i "CentOS" /etc/*release | wc -l` 2> /dev/null
  if [ $res -gt 0 ]; then
        mkdir /usr/X11R6/
        mkdir /usr/X11R6/lib
        mkdir /usr/X11R6/lib/X11
        ln -s /usr/share/X11/fonts /usr/X11R6/lib/X11/fonts
  fi
  
  #if this is suse 10.2 copy specific VNC files
  res=`grep -i "suse" /etc/*release | wc -l` 2> /dev/null
  if [ $res -gt 0 ]; then
  	cp -f $insGen_tempdir/additional/suse_10.2_vnc/vncserver "$insGen_installPath/system_monitor/remote_console"
  	cp -f $insGen_tempdir/additional/suse_10.2_vnc/.vnc/xstartup "$insGen_installPath/system_monitor/remote_console/.vnc"
  	cp -f $insGen_tempdir/additional/suse_10.2_vnc/initd/smad_remote_console "$insGen_initd"
  fi
  
  #check for ubuntu, if detected perform extra remote console operations
  #Fixes remote console for xfce4 and kills vino-server so remote console will run.
  res=`grep -i ubuntu /etc/*release | wc -l` 2> /dev/null
  if [ $res -gt 0 ]; then
  	cp -f $insGen_tempdir/additional/ubuntu_vnc/vncserver "$insGen_installPath/system_monitor/remote_console"
  	cp -f $insGen_tempdir/additional/ubuntu_vnc/Xtightvnc "$insGen_installPath/system_monitor/remote_console"
  	cp -f $insGen_tempdir/additional/ubuntu_vnc/initd/smad_remote_console "$insGen_initd"
  	cp -rf $insGen_tempdir/additional/ubuntu_vnc/.vnc/* "$insGen_installPath/system_monitor/remote_console/.vnc"
	cp -f /usr/NX/lib/libjpeg.so.62 /usr/lib 2> /dev/null
  	cp -f /usr/lib/i386-linux-gnu/libjpeg.so.62 /usr/lib 2> /dev/null
    killall vino-server 2> /dev/null
    chmod -x /usr/lib/vino/vino-server 2> /dev/null
  	if [ -e /usr/bin/xfce4-session ]; then
  		cp -f "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_xfce4" "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_console"
  	elif [ -e /usr/bin/startkde ]; then
  		cp -f "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_kde" "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_console"
  	elif [ -e /usr/bin/gnome-session ]; then
  		cp -f "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_gnome" "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_console"
  	fi
  		cp -f "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_console" "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup"
  	  	
  	chmod 777 "$insGen_installPath/system_monitor/remote_console/vncserver"
  	chmod 777 "$insGen_installPath/system_monitor/remote_console/Xtightvnc"
  	chmod 755 "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup"*
  fi
  
  #debian remote console (uses the same special files as ubuntu)
   res=`grep -i debian /etc/debian_version | wc -l` 2> /dev/null
  if [ $res -gt 0 ]; then
  	cp -f $insGen_tempdir/additional/ubuntu_vnc/vncserver "$insGen_installPath/system_monitor/remote_console"
  	cp -f $insGen_tempdir/additional/ubuntu_vnc/Xtightvnc "$insGen_installPath/system_monitor/remote_console"
  	cp -f $insGen_tempdir/additional/ubuntu_vnc/initd/smad_remote_console "$insGen_initd"
  	cp -rf $insGen_tempdir/additional/ubuntu_vnc/.vnc/* "$insGen_installPath/system_monitor/remote_console/.vnc"
  	
  	if [ -e /usr/bin/gnome-session ]; then
  		cp -f "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_gnome" "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_console"
  	elif [ -e /usr/bin/startkde ]; then
  		cp -f "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_kde" "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_console"
  	elif [ -e /usr/bin/xfce4-session ]; then
  		cp -f "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_xfce4" "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_console"
  	fi
  		cp -f "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup_console" "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup"
  	  	
  	chmod 777 "$insGen_installPath/system_monitor/remote_console/vncserver"
  	chmod 777 "$insGen_installPath/system_monitor/remote_console/Xtightvnc"
  	chmod 755 "$insGen_installPath/system_monitor/remote_console/.vnc/xstartup"*
  fi
  
  
  #edit agent.properties
  replace_tok "locale=en" "locale=$insGen_locale" "$insGen_installPath/system_monitor/agent/agent.properties"

  #add install path to smad script
  replace_tok "INSTALLDIR=" "INSTALLDIR=\"$insGen_installPath/system_monitor/agent\"" "$insGen_installPath/smad"
  #unix_EOL "$insGen_installPath/smad"
  
  #set the correct product mode in smad
  replace_tok "MODE=SMA" "MODE=$insGen_modePrefix$insGen_modeSuffix" "$insGen_installPath/smad"
  
  replace_tok "@@@install_path@@@" "$insGen_installPath" "$insGen_installPath/system_monitor/remote_console/vncserver"
  replace_tok "@@@install_path@@@" "$insGen_installPath" "$insGen_initd/smad_remote_console"

  #change file permissions
  chmod 777 $insGen_installPath/smad > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/agent/smad > /dev/null 2> /dev/null
  chmod 755 $insGen_installPath/system_monitor/agent/fixguid > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/agent/libsnsrlib.so > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/agent/libsyamcpu.so > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/agent/libsyamdata.so > /dev/null 2> /dev/null
  chmod 777 $insGen_initd/smad_remote_console > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/remote_console/* > /dev/null 2> /dev/null
  chmod 600 $insGen_installPath/system_monitor/remote_console/.vnc/passwd > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/remote_console/.vnc/vncpasswd > /dev/null 2> /dev/null
  chmod 755 $insGen_installPath/system_monitor/remote_console/.vnc/xstartup > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/agent/libstdc++.so.5 > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/agent/arcconf > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/agent/libsyamraid.so > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/agent/libmegalib.so > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/agent/libezlicenser20.so > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/agent/libgcc_s.so.1 > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/system_monitor/agent/libsyamraid.so > /dev/null 2> /dev/null
  chmod 755 $insGen_installPath/system_monitor/agent/idlex > /dev/null 2> /dev/null
  
  #copy c lib to /usr/lib
  if [ ! -e /usr/lib/libstdc++.so.5 ]; then
  	cp -f $insGen_installPath/system_monitor/agent/libstdc++.so.5 /usr/lib &> /dev/null
  fi
  
  #create symbolic links in init.d for smad
  ln -fs $insGen_installPath/smad $insGen_initd

  #register the service with the system
  verbose echo -n "${insMnu_trans[12]} " #registering agent smad with the system...

  add_service "smad"
  add_service "smad_remote_console"
 
  #disable remote console in runlevels
  chkconfig --level 0123456 smad_remote_console off > /dev/null 2> /dev/null
  /sbin/chkconfig --level 0123456 smad_remote_console off > /dev/null 2> /dev/null
  
  verbose echo -e "\033[1;32m${insMnu_trans[0]}\033[0m"

  #start the agent
  $insGen_initd/smad start

}
#---------------
#Install Jetty
#
#installs jetty to the system
#

install_jetty()
{
  #install jetty web server
  verbose echo -n "${insMnu_trans[14]} " #installing the web server...

  cp -rf $insGen_tempdir/jetty $insGen_installPath
  cp -f $insGen_tempdir/SupportDir/etc/pam.d/syam $insGen_pamd  #used for login
  
  #if this is alt linux, add a line to PAM.D file
  if [ -f "/etc/altlinux-release" ]; then
  	echo '#%PAM-1.0' > /etc/pam.d/syam
  	echo 'auth required pam_tcb.so shadow fork prefix=$2y$ count=8 nullok' >> /etc/pam.d/syam
  fi

  verbose echo -e "\033[1;32m${insMnu_trans[0]}\033[0m"

  #convert DOS EOLs to UNIX EOLs
  #unix_EOL $insGen_pamd/syam
  #unix_EOL $insGen_installPath/jetty/bin/findPamLib
  #unix_EOL $insGen_installPath/jetty/bin/smwd
  
	#determine if the 32 or 64 bit syamlogin should be used, and remove the other
   if [ `uname -i` = "x86_64" ]; then
    mv "$insGen_installPath/jetty/bin/syamlogin64" "$insGen_installPath/jetty/syamlogin">  /dev/null 2>  /dev/null
    rm -rf "$insGen_installPath/jetty/bin/syamlogin32"
   elif [ `uname -i` = "unknown" ]; then
    if [ `uname -m` = "x86_64" ]; then
     mv "$insGen_installPath/jetty/bin/syamlogin64" "$insGen_installPath/jetty/syamlogin">  /dev/null 2>  /dev/null
     rm -rf "$insGen_installPath/jetty/bin/syamlogin32"
    fi
   fi
   mv "$insGen_installPath/jetty/bin/syamlogin32" "$insGen_installPath/jetty/syamlogin">  /dev/null 2>  /dev/null
   rm -rf "$insGen_installPath/jetty/bin/syamlogin64"



  #remove smc_fr.jsp (leave only sml_fr.jsp)
  rm -f $insGen_installPath/jetty/webapps/syam/smc_fr.jsp

  #change file permissions
  chmod 777 $insGen_installPath/jetty/wrapper > /dev/null 2> /dev/null
  #chmod 777 $insGen_installPath/jetty/bin/findPamLib
  chmod 777 $insGen_installPath/jetty/bin/smwd > /dev/null 2> /dev/null
  chmod 777 $insGen_installPath/jetty/syamlogin > /dev/null 2> /dev/null
  chmod +x $insGen_installPath/jetty/bin/syamimr > /dev/null 2> /dev/null

  #use findPamLib to find the correct PAM library and update smwd
  #$insGen_installPath/jetty/bin/findPamLib $insGen_installPath/jetty/bin/smwd

  #edit syam.properties
  replace_tok "mode=sml" "mode=$insGen_modePrefix$insGen_modeSuffix" "$insGen_installPath/jetty/webapps/syam/WEB-INF/syam.properties"
  replace_tok "locale=en" "locale=$insGen_locale" "$insGen_installPath/jetty/webapps/syam/WEB-INF/syam.properties"
  
  #enable SSL if selected
  if [ "$insGen_SSL" = "true" ]; then
    #generate keystore
    replace_tok "@@@install_path@@@" "$insGen_installPath" "$insGen_installPath/jetty/bin/ssl_config"
    chmod 777 $insGen_installPath/jetty/bin/ssl_config
    $insGen_installPath/jetty/bin/ssl_config localhost 123456 123456
    
    #modify syam.xml to comment the http listener and uncomment the SSL listener
    replace_tok "<!--@@@http\ -->" "<!--@@@http" "$insGen_installPath/jetty/etc/syam.xml"
    replace_tok "<!--\ @@@http\ -->" "@@@http\ -->" "$insGen_installPath/jetty/etc/syam.xml"
    replace_tok "@@@ssl\ -->" "<!--\ @@@ssl\ -->" "$insGen_installPath/jetty/etc/syam.xml"
    replace_tok "<!--@@@ssl" "<!--@@@ssl\ -->" "$insGen_installPath/jetty/etc/syam.xml"
      
  fi
  
  #symlink smwd to the system init.d
  ln -fs $insGen_installPath/jetty/bin/smwd $insGen_initd

  #register smwd with the system and start it
  verbose echo -n "${insMnu_trans[15]} " #registering webserver smwd with the system...

	add_service "smwd"

  verbose echo -e "\033[1;32m${insMnu_trans[0]}\033[0m"

  #start jetty
  $insGen_initd/smwd start
  verbose echo ""
  
  #echo -e "\033[1;34m"
  #echo "--- ${insMnu_trans[16]} ---" #--- web server installed and set up ---
  #echo -e "\033[0m"

}
#---------------
#Install SMC
#
#installs the SMC to the system.  since most files are installed along
#with the agent, this really just adds smcd as a service and starts it
#

install_SMC()
{
  verbose echo -n "${insMnu_trans[17]} " #installing smc...
  verbose echo -e "\033[1;32m${insMnu_trans[0]}\033[0m"

  #replace DOS EOLs with UNIX EOLs
  #unix_EOL "$insGen_installPath/system_monitor/smcd"

  #remove sml_fr.jsp and move smc_fr.jsp to the correct folder
  rm -f $insGen_installPath/jetty/webapps/syam/sml_fr.jsp
  cp -f $insGen_tempdir/jetty/webapps/syam/smc_fr.jsp $insGen_installPath/jetty/webapps/syam

  #edit syam.properties  
  replace_tok "rmi_port=1099" "rmi_port=$insGen_RMIport" "$insGen_installPath/jetty/webapps/syam/WEB-INF/syam.properties"     
  
  #change file permissions
  chmod 777 $insGen_installPath/system_monitor/smcd

  #symlink smcd to the system init.d
  ln -fs $insGen_installPath/system_monitor/smcd $insGen_initd

  #register smcd with the system and start it
  verbose echo -n "${insMnu_trans[18]} " #registering SMC smcd with the system...

  add_service "smcd"

  verbose echo -e "\033[1;32m${insMnu_trans[0]}\033[0m"

  #start SMC
  $insGen_initd/smcd start  

  #echo -e "\033[1;34m"
  #echo "--- ${insMnu_trans[19]} ---" #--- SMC installed and set up ---
  #echo -e "\033[0m"

}
install_vnc_console()
{
	echo ""
}


#//include upgrade-related functions here
#---------------
#Upgrade Install Routine
#
#performs the 'upgrade' part of the update install.  after saving some 
#files and performing other upgrade-related tasts, the regular install 
#continues as normal.
#
upgrade_install()
{			
	#find out about the current install
	upgrade_find_options
	
	#load_locale
	load_locale $insGen_locale
	
	#needs to be called before upgrade_backup
	just_before_install
	
	#move files that need to be saved to the temp folder
	upgrade_backup
	
	#uninstall current install
	echo 1 | "$insGen_currInstall/uninstall" > /dev/null 2> /dev/null
	
	#install the product without the menu system
	install
}
#---------------
#Upgrade- Find Menu Option
#
#the normal installation gets many options from the user. this function
#looks at the current install to populate those values.  
#
upgrade_find_options()
{
	
	#get the locale
	insGen_locale=`cat "$insGen_currInstall/system_monitor/agent/agent.properties" | sed -e 's%locale=%%'`
	
	#get the computer type (server/desktop/notebook)
	insGen_modePrefix=`cat $insGen_currInstall/version | grep prod` > /dev/null 2> /dev/null
	insGen_modePrefix=${insGen_modePrefix:5:2} > /dev/null 2> /dev/null
	
	if [ -e "$insGen_currInstall/system_monitor/agent/libezlicenser20.so" ]; then
		insGen_productType="central"
		insGen_modeSuffix="c"
		
		#get the current RMI port info
		insGen_RMIport=`cat "$insGen_currInstall/jetty/webapps/syam/WEB-INF/syam.properties" | sed -e '1d' -e '2d' -e'4d' -e 's%rmi_port=%%'`
		
		#get SSL information
		ssl=`cat "$insGen_currInstall/jetty/etc/syam.xml" | sed -n '/<!--@@@ssl -->/p'` > /dev/null 2> /dev/null
		if [ ${#ssl} -gt 1 ]; then #this means that SSL was enabled
			insGen_SSL="true"
		else #SSL was not enabled
			insGen_SSL="false"
		fi
		
	else
		if [ -d "$insGen_currInstall/jetty" ]; then
		
			insGen_productType="local"
			insGen_modeSuffix="l"
			
			#get SSL information
			ssl=`cat "$insGen_currInstall/jetty/etc/syam.xml" | sed -n '/<!--@@@ssl -->/p'` > /dev/null 2> /dev/null
			if [ ${#ssl} -gt 1 ]; then #this means that SSL was enabled
				insGen_SSL="true"
			else #SSL was not enabled
				insGen_SSL="false"
			fi
			
		else
			insGen_productType="agent"
			insGen_modeSuffix="a"			
		fi
	fi
	
	#set the install path to the current install path
	insGen_installPath="$insGen_currInstall"
}
#---------------
#Upgrade- Backup
#
#this backs up all the files that need to be backed up.  it places
#all the files that need to be moved over into the temp folder. 
#they are then automatically moved from the temp folder to the install
#folder when the install occursd
#this way the install naturally restores them to the correct spot.
#
upgrade_backup()
{	
	#backup /system_monitor files
	cp -f $insGen_currInstall/system_monitor/alerts.properties $insGen_tempdir/system_monitor > /dev/null 2> /dev/null 
	cp -f $insGen_currInstall/system_monitor/*.log $insGen_tempdir/system_monitor > /dev/null 2> /dev/null
	cp -f $insGen_currInstall/system_monitor/managed_systems.dat $insGen_tempdir/system_monitor > /dev/null 2> /dev/null
	
	#backup /system_monitor/agent files
	#cp -f $insGen_currInstall/system_monitor/agent/.ezl20ck $insGen_tempdir/system_monitor/agent > /dev/null 2> /dev/null
	cp -f $insGen_currInstall/system_monitor/agent/si.dat $insGen_tempdir/system_monitor/agent > /dev/null 2> /dev/null
	#cp -f $insGen_currInstall/system_monitor/agent/rcd.dat $insGen_tempdir/system_monitor/agent > /dev/null 2> /dev/null
	cp -f $insGen_currInstall/system_monitor/agent/ntarg.dat $insGen_tempdir/system_monitor/agent > /dev/null 2> /dev/null
	cp -f $insGen_currInstall/system_monitor/agent/ctx.dat $insGen_tempdir/system_monitor/agent > /dev/null 2> /dev/null
	cp -f $insGen_currInstall/system_monitor/agent/agt.dat $insGen_tempdir/system_monitor/agent > /dev/null 2> /dev/null
	cp -f $insGen_currInstall/system_monitor/agent/*.log $insGen_tempdir/system_monitor/agent > /dev/null 2> /dev/null

	#backup jetty/logs	
	cp -f $insGen_currInstall/jetty/logs/*.log $insGen_tempdir/jetty/logs > /dev/null 2> /dev/null
}

#//include variables here.  this is not a function, just variables
#############################################
##### Variables
#####
##### WARNING: EDIT ONLY WITH UNIRED!!!!!!!!!
#####
#############################################

#---------------
#error messages

insErr_mustUninstall="${insTrans_def[0]}" #You must uninstall the product before you can install it again
insErr_installPath="${insTrans_def[5]} "  #Could not create the install path... make sure you have full permissions 
insErr_tempdir="${insTrans_def[3]}"		  #Could not create temp folder... make sure you have full permissions to $insGen_tempdir
insErr_untar="${insTrans_def[4]}"		  #Could not untar the install package

#---------------
#general / global variables

fc="9"
bc="8"

insGen_locale="en"	#this is specified in build.xml

insGen_insPackage="install_package.tar"
insGen_tempdir="./temp"
insGen_startdir=`pwd`

insGen_mnuSel=6
insGen_prodName="SyAM System Client 4.70"
insGen_nextFunc="start"

insGen_initd=""
insGen_pamd=""

insGen_thisVersion="4.70"
insGen_installPath="/syam"
insGen_productType="local" 
insGen_modePrefix="dm"   #default value, changed under 'choose computer type' menu
insGen_modeSuffix="l"
insGen_RMIport="10999"
insGen_SSL="false"
insGen_silent="false"

insGen_vendor="SyAM"
insGen_boardchecking="false"

if [ $insGen_modeSuffix = "l" ]; then
     insGen_productType="local"    #this is possibly changed to 'agent' under the 'choose interface type' menu
else
     insGen_productType="central"
fi

insGen_probe="false"

#---------------
#menu text arrays

insMnu_welcome[0]=""
insMnu_license[0]=""
insMnu_installpath[0]=""
insMnu_computertype[0]=""
insMnu_interfacetype[0]=""
insMnu_rmiport[0]=""
insMnu_ssl[0]=""
insMnu_summary[0]=""

#---------------
#installer translation arrays
insMnu_trans[0]=""  #special translations used in menus and other places (messages, etc)

#---------------
#translations for items that the user might see before the language files are extracted

insTrans_def[0]="" #depending on the default language, arrays below are loaded into this one for use

insTrans_en[0]="You must uninstall the product before you can install it again"
insTrans_en[1]="checking for previous versions..."
insTrans_en[2]="error"
insTrans_en[3]="Could not create temp folder... make sure you have full permissions to $insGen_tempdir"
insTrans_en[4]="Could not untar the install package"
insTrans_en[5]="Could not create the install path... make sure you have full permissions"
insTrans_en[6]="extracting files to temp folder (please be patient)..."
insTrans_en[7]="a previous installation was detected.  please uninstall before reinstalling."
insTrans_en[8]="A previous installation was detected.  Would you like to upgrade [1:yes 2:no]?"
insTrans_en[9]="All the files needed for the upgrade have been saved.  The product will now be uninstalled, then reinstalled with the saved files."
insTrans_en[10]="install aborted"
insTrans_en[11]="warning: previous installation detected but the folder was not found"
insTrans_en[12]="continuing with will installation"
insTrans_en[13]="your product types do not match!  you must upgrade a server to a server, desktop to a desktop, or notebook to a notebook"
insTrans_en[14]="your product modes do not match!  local or agent versions may not be upgraded to central versions"
insTrans_en[15]="your product modes do not match!  central versions may not be upgraded to local or agent-only versions"

insTrans_ru[0]="?? ?????? ??????? ?????????? ??????????? ????? ????????? ????????."
insTrans_ru[1]="???? ????? ?????????? ?????? ????????..."
insTrans_ru[2]="????????? ??????"
insTrans_ru[3]="?? ??????? ??????? ????? ????????? ??????... ????????? ????? ?????? ???????."
insTrans_ru[4]="?? ??????? ???????? tar ????? ???????????????? ??????."
insTrans_ru[5]="?? ??????? ??????? ??????????????? ?????... ????????? ????? ?????? ???????."
insTrans_ru[6]="????????? ????????? ????? (????? ?????? ????????? ?????)..."
insTrans_ru[7]="??????? ?????????? ?????? ????????. ??????????, ??????????????? ?? ????? ?????????? ????? ??????. "
insTrans_ru[8]="?????????? ??????????? ?????????? ??????. ?????????? ?????????? ??? ????????????? ????????? [1:?? 2:???]?"
insTrans_ru[9]="??? ?????, ??????????? ??? ?????????? ????????? ?????????. ????????? ????? ???????, ?, ?????, ????? ??????????? ? ??????????? ??????????? ??????."
insTrans_ru[10]="??????????? ?? ???????"
insTrans_ru[11]="??????????????: ?????????? ??????????? ??????????, ?? ????? ?? ???????"
insTrans_ru[12]="?????????? ? ???????????"
insTrans_ru[13]="?????? ??????????????? ??????? ?? ?????????! ????????? ????? ????? ???????? ?????? ????????? ???????????, ? ??????????? ? ???????????, ??????????????, ?????? ??????????? ? ?????????.  "
insTrans_ru[14]="????????????? ????? ?????????? ?? ????????????????! ??????????????? ????? ???????????? ??????????? ?? ????? ???????? ????????????? ????????? ?????????? ??????????? ??? ??????.  "
insTrans_ru[15]="????????????? ????? ?????????? ?? ????????????????! ??????????????? ????? ?????????? ??????????? ??? ?????? ?? ????? ???????? ????????????? ?????? ???????????? ???????????."

insTrans_jp[0]="????????????????????????????"
insTrans_jp[1]="??????????????…"
insTrans_jp[2]="???"
insTrans_jp[3]="temp??????????????????????????"
insTrans_jp[4]="?????? ??????????????"
insTrans_jp[5]="?????????????????????????????"
insTrans_jp[6]="temp??????????????????????…"
insTrans_jp[7]="????????????????????????????????????????????????"
insTrans_jp[8]="??????????????????????????  [1:yes 2:no]"
insTrans_jp[9]="?????????????????????????????????????????????????????????????????????"
insTrans_jp[10]="???????????????"
insTrans_jp[11]="??:????????????????????????????????"
insTrans_jp[12]="?????????????"
insTrans_jp[13]="???????????????????????????????????????????????????????"
insTrans_jp[14]="??????????????????????????? ??????????? ???????????????????"
insTrans_jp[15]="????????????????????? ?????? ??????????? ???????????????????"

insTrans_en_GB[0]="You must uninstall the product before you can install it again"
insTrans_en_GB[1]="checking for previous versions..."
insTrans_en_GB[2]="error"
insTrans_en_GB[3]="Could not create temp folder... make sure you have full permissions to $insGen_tempdir"
insTrans_en_GB[4]="Could not untar the install package"
insTrans_en_GB[5]="Could not create the install path... make sure you have full permissions"
insTrans_en_GB[6]="extracting files to temp folder (please be patient)..."
insTrans_en_GB[7]="a previous installation was detected.  please uninstall before reinstalling."
insTrans_en_GB[8]="A previous installation was detected.  Would you like to upgrade [1:yes 2:no]?"
insTrans_en_GB[9]="All the files needed for the upgrade have been saved.  The product will now be uninstalled, then reinstalled with the saved files."
insTrans_en_GB[10]="install aborted"
insTrans_en_GB[11]="warning: previous installation detected but the folder was not found"
insTrans_en_GB[12]="continuing with will installation"
insTrans_en_GB[13]="your product types do not match!  you must upgrade a server to a server, desktop to a desktop, or notebook to a notebook"
insTrans_en_GB[14]="your product modes do not match!  local or agent versions may not be upgraded to central versions"
insTrans_en_GB[15]="your product modes do not match!  central versions may not be upgraded to local or agent-only versions"

insTrans_de[0]="Sie müssen das alte Produkt deinstallieren, bevor Sie mit der Installation beginnen können"
insTrans_de[1]="Frühere Versionen werden gesucht..."
insTrans_de[2]="fehler"
insTrans_de[3]="Der gewünschte Folder konnte nicht kreiert werden... Stellen Sie den Zugriff sicher $insGen_tempdir"
insTrans_de[4]="Konnte das Package nicht einwandfrei installieren"
insTrans_de[5]="Der gewünschte Pfad konnte nicht kreiert werden... Stellen Sie Ihre Zugriffsrechte sicher"
insTrans_de[6]="Dateien werden in Temp-Folder extrahiert (bitte haben Sie etwas Geduld)..."
insTrans_de[7]="Eine frühere Version wurde gefunden. Vor Neuinstallation bitte entfernen."
insTrans_de[8]="A previous installation was detected.  Would you like to upgrade [1:yes 2:no]?"
insTrans_de[9]="All the files needed for the upgrade have been saved.  The product will now be uninstalled, then reinstalled with the saved files."
insTrans_de[10]="install aborted"
insTrans_de[11]="warning: previous installation detected but the folder was not found"
insTrans_de[12]="continuing with will installation"
insTrans_de[13]="your product types do not match!  you must upgrade a server to a server, desktop to a desktop, or notebook to a notebook"
insTrans_de[14]="your product modes do not match!  local or agent versions may not be upgraded to central versions"
insTrans_de[15]="your product modes do not match!  central versions may not be upgraded to local or agent-only versions"

insTrans_fr[0]="You must uninstall the product before you can install it again"
insTrans_fr[1]="checking for previous versions..."
insTrans_fr[2]="error"
insTrans_fr[3]="Could not create temp folder... make sure you have full permissions to $insGen_tempdir"
insTrans_fr[4]="Could not untar the install package"
insTrans_fr[5]="Could not create the install path... make sure you have full permissions"
insTrans_fr[6]="extracting files to temp folder (please be patient)..."
insTrans_fr[7]="a previous installation was detected.  please uninstall before reinstalling."
insTrans_fr[8]="A previous installation was detected.  Would you like to upgrade [1:yes 2:no]?"
insTrans_fr[9]="All the files needed for the upgrade have been saved.  The product will now be uninstalled, then reinstalled with the saved files."
insTrans_fr[10]="install aborted"
insTrans_fr[11]="warning: previous installation detected but the folder was not found"
insTrans_fr[12]="continuing with will installation"
insTrans_fr[13]="your product types do not match!  you must upgrade a server to a server, desktop to a desktop, or notebook to a notebook"
insTrans_fr[14]="your product modes do not match!  local or agent versions may not be upgraded to central versions"
insTrans_fr[15]="your product modes do not match!  central versions may not be upgraded to local or agent-only versions"

insTrans_fr_CA[0]="You must uninstall the product before you can install it again"
insTrans_fr_CA[1]="checking for previous versions..."
insTrans_fr_CA[2]="error"
insTrans_fr_CA[3]="Could not create temp folder... make sure you have full permissions to $insGen_tempdir"
insTrans_fr_CA[4]="Could not untar the install package"
insTrans_fr_CA[5]="Could not create the install path... make sure you have full permissions"
insTrans_fr_CA[6]="extracting files to temp folder (please be patient)..."
insTrans_fr_CA[7]="a previous installation was detected.  please uninstall before reinstalling."
insTrans_fr_CA[8]="A previous installation was detected.  Would you like to upgrade [1:yes 2:no]?"
insTrans_fr_CA[9]="All the files needed for the upgrade have been saved.  The product will now be uninstalled, then reinstalled with the saved files."
insTrans_fr_CA[10]="install aborted"
insTrans_fr_CA[11]="warning: previous installation detected but the folder was not found"
insTrans_fr_CA[12]="continuing with will installation"
insTrans_fr_CA[13]="your product types do not match!  you must upgrade a server to a server, desktop to a desktop, or notebook to a notebook"
insTrans_fr_CA[14]="your product modes do not match!  local or agent versions may not be upgraded to central versions"
insTrans_fr_CA[15]="your product modes do not match!  central versions may not be upgraded to local or agent-only versions"

insTrans_es[0]="You must uninstall the product before you can install it again"
insTrans_es[1]="checking for previous versions..."
insTrans_es[2]="error"
insTrans_es[3]="Could not create temp folder... make sure you have full permissions to $insGen_tempdir"
insTrans_es[4]="Could not untar the install package"
insTrans_es[5]="Could not create the install path... make sure you have full permissions"
insTrans_es[6]="extracting files to temp folder (please be patient)..."
insTrans_es[7]="a previous installation was detected.  please uninstall before reinstalling."
insTrans_es[8]="A previous installation was detected.  Would you like to upgrade [1:yes 2:no]?"
insTrans_es[9]="All the files needed for the upgrade have been saved.  The product will now be uninstalled, then reinstalled with the saved files."
insTrans_es[10]="install aborted"
insTrans_es[11]="warning: previous installation detected but the folder was not found"
insTrans_es[12]="continuing with will installation"
insTrans_es[13]="your product types do not match!  you must upgrade a server to a server, desktop to a desktop, or notebook to a notebook"
insTrans_es[14]="your product modes do not match!  local or agent versions may not be upgraded to central versions"
insTrans_es[15]="your product modes do not match!  central versions may not be upgraded to local or agent-only versions"

insTrans_es_AR[0]="You must uninstall the product before you can install it again"
insTrans_es_AR[1]="checking for previous versions..."
insTrans_es_AR[2]="error"
insTrans_es_AR[3]="Could not create temp folder... make sure you have full permissions to $insGen_tempdir"
insTrans_es_AR[4]="Could not untar the install package"
insTrans_es_AR[5]="Could not create the install path... make sure you have full permissions"
insTrans_es_AR[6]="extracting files to temp folder (please be patient)..."
insTrans_es_AR[7]="a previous installation was detected.  please uninstall before reinstalling."
insTrans_es_AR[8]="A previous installation was detected.  Would you like to upgrade [1:yes 2:no]?"
insTrans_es_AR[9]="All the files needed for the upgrade have been saved.  The product will now be uninstalled, then reinstalled with the saved files."
insTrans_es_AR[10]="install aborted"
insTrans_es_AR[11]="warning: previous installation detected but the folder was not found"
insTrans_es_AR[12]="continuing with will installation"
insTrans_es_AR[13]="your product types do not match!  you must upgrade a server to a server, desktop to a desktop, or notebook to a notebook"
insTrans_es_AR[14]="your product modes do not match!  local or agent versions may not be upgraded to central versions"
insTrans_es_AR[15]="your product modes do not match!  central versions may not be upgraded to local or agent-only versions"

insTrans_pt[0]="Você precisa desinstalar o produto antes de reinstalar novamente"
insTrans_pt[1]="Verificando versões anteriores..."
insTrans_pt[2]="erro"
insTrans_pt[3]="Não foi possível criar uma pasta temporária... Verifique se sua senha possui acesso total ao sistema $insGen_tempdir"
insTrans_pt[4]="Não foi possível untar o pacote de instalação"
insTrans_pt[5]="Não foi possível criar o atalho para a instalação... Verifique se sua senha possui acesso total ao sistema"
insTrans_pt[6]="Extraindo arquivos para uma pasta temporária (por favor aguarde)..."
insTrans_pt[7]="Uma versão anterior foi encontrada. Por favor desinstale antes de continuar com a instalação"
insTrans_pt[8]="A previous installation was detected.  Would you like to upgrade [1:yes 2:no]?"
insTrans_pt[9]="All the files needed for the upgrade have been saved.  The product will now be uninstalled, then reinstalled with the saved files."
insTrans_pt[10]="install aborted"
insTrans_pt[11]="warning: previous installation detected but the folder was not found"
insTrans_pt[12]="continuing with will installation"
insTrans_pt[13]="your product types do not match!  you must upgrade a server to a server, desktop to a desktop, or notebook to a notebook"
insTrans_pt[14]="your product modes do not match!  local or agent versions may not be upgraded to central versions"
insTrans_pt[15]="your product modes do not match!  central versions may not be upgraded to local or agent-only versions"

insTrans_pt_BR[0]="Você precisa desinstalar o produto antes de reinstalar novamente"
insTrans_pt_BR[1]="Verificando versões anteriores..."
insTrans_pt_BR[2]="erro"
insTrans_pt_BR[3]="Não foi possível criar uma pasta temporária... Verifique se sua senha possui acesso total ao sistema $insGen_tempdir"
insTrans_pt_BR[4]="Não foi possível untar o pacote de instalação"
insTrans_pt_BR[5]="Não foi possível criar o atalho para a instalação... Verifique se sua senha possui acesso total ao sistema"
insTrans_pt_BR[6]="Extraindo arquivos para uma pasta temporária (por favor aguarde)..."
insTrans_pt_BR[7]="Uma versão anterior foi encontrada. Por favor desinstale antes de continuar com a instalação"
insTrans_pt_BR[8]="A previous installation was detected.  Would you like to upgrade [1:yes 2:no]?"
insTrans_pt_BR[9]="All the files needed for the upgrade have been saved.  The product will now be uninstalled, then reinstalled with the saved files."
insTrans_pt_BR[10]="install aborted"
insTrans_pt_BR[11]="warning: previous installation detected but the folder was not found"
insTrans_pt_BR[12]="continuing with will installation"
insTrans_pt_BR[13]="your product types do not match!  you must upgrade a server to a server, desktop to a desktop, or notebook to a notebook"
insTrans_pt_BR[14]="your product modes do not match!  local or agent versions may not be upgraded to central versions"
insTrans_pt_BR[15]="your product modes do not match!  central versions may not be upgraded to local or agent-only versions"


#//include command-line checking and silent mode support
#---------------
# Check Silent
#
# looks for silent parameters to perform a totally silent install
# NOTE: call this parameter like so: 
#   check_silent $*
# in this way, all program parameters are passed into the function
#
command_line_parameters()
{
	if [[ "$1" == "-silent" ]]; then
		insGen_silent="true"
		insGen_locale=$2
		insGen_modePrefix=$3
		insGen_RMIport=$4
		insGen_SSL=$5
		
		#if the suffix given says this is agent only, set it
		if [ "$insGen_modeSuffix" == "l" ]; then
			if [ "$6" == "a" ] || [ "$6" == "A" ]; then
				insGen_modeSuffix="a"
				insGen_productType="agent"
			fi
		fi
	fi
}
#---------------
# Verbose Command
#
# runs a command only if this is not a silent install
# (mostly used for echo commands)
#
verbose()
{
	if [[ "$insGen_silent" == "false" ]]; then
		$*
	fi
}

#########################################
####Main Area (starts running here)

#check command line parameters, mostly used for silent support
command_line_parameters "$@"

#set up some default translations for the installer
copyDefTrans

#run the pre-install routine.  upgrades are detected and run here.
preinstall

if [ "$insGen_silent" == "true" ]; then
	just_before_install  #performs some last-minute functions
	install #the last menu has finished, run the install routine
else
	#if this is not an upgrade install, run through the normal process
	if [ "$insGen_upgrade" != "true" ]; then
		
		#menu system.. stay here until aborted or install begins
		while [ "$insGen_nextFunc" != "install" ]
		do
		
		  #decide what the next menu should be
		  menu_flow_ctrl "$insGen_nextFunc" "$insGen_mnuSel"
		
		  #call the menu that was determined to be next
		  case $insGen_nextFunc in
		    "mnuLocale")
		     mnuLocale
		     ;;
		    "mnuWelcome")
		    	mnuWelcome
		    	;;
		    "mnuLicAgree")
		    	mnuLicAgree
		    	;;
		    "mnuChoosePath")
		    	mnuChoosePath
		    	;;
		    "mnuComputerType")
		    	mnuComputerType
		    	;;
		    "mnuChooseInterface")
		    	mnuChooseInterface
		    	;;
		    "mnuChooseRMI")
		    	mnuChooseRMI
		    	;;
		    "mnuCollectInfo")
		    	mnuCollectInfo
		    	;;
		    "mnuChooseSSL")
		    	mnuChooseSSL
		    	;;
		    "mnuSummary")
		    	mnuSummary
		    	;;
		    "install")
		    	just_before_install  #performs some last-minute functions
		    	install #the last menu has finished, run the install routine
		    	;;
		  esac
		
		done
	
	fi
fi
rm -rf temp

########################################





















