syntax error near unexpected token '{


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users syntax error near unexpected token '{
# 1  
Old 05-14-2010
Bug syntax error near unexpected token '{

Hi,

I am running the following script through cygwin and getting below mentioned error.
*******************************************
Code:
#!/bin/sh
 
# constants
WORK_DIR="deploy"
INFOFILE="deploy.info"
INTROFILE="Intro.sh"
CMGMT_PKG="com.kintana.cmgmt.deploy"
DEPLOY_PREFIX="mitg"
 
FS_HOMEFILE="fs_home.jar"
FS_WARFILE="fs_war.jar"
FS_MSFILE="fs_multiserv.jar"
 
BACKUP_NAME="BACKUP"
LOG_DIR="logs"
 
# by default, a deployment requires the server to be stopped (hence the 1)
# if a specific deployment needs the server running, set it to 0 in 
# deploy.info
REQUIRES_SERVER_STOPPED=1
 
# utility programs
QUERYTOOL="$CMGMT_PKG.RunDeployQuery"
DEPLOYREPORT="$CMGMT_PKG.DeployReport"
 
#
# test if "echo -n" is supported
#
foo=`echo -n foo`
if [ "x$foo" = "xfoo" ]; then
    _ECHO_TYPE=1
else
    _ECHO_TYPE=2
fi
 
#
# echoing a string without a newline comes in two
# flavors:
# 1. echo -n <text>
# 2. echo "<text>\c"
#
# usually one platform supports one of them and
# not both.
#
necho() {
   if [ $_ECHO_TYPE = 1 ]; then
      echo -n "$@"
   else
      echo "$@\c"
   fi
}
 
###
## Get Tablespaces - separate scripts for each one.  No longer rely on 
#     KINS_TABLESPACES
#
queryTablespace() {
    TS_QUERY="$1"
    TS_TYPE="$2"
 
    # blank out the tablespace before queying for it
    TABLESPACE=
    TABLESPACE=`$JAVA_HOME/bin/java $QUERYTOOL "$TS_QUERY" $KNTA_HOME`
 
    if [ "$?" != "0" ]; then 
        errorMessage "Error when trying to determine the  $TS_TYPE Tablespace."
    fi
 
    if [ "$TABLESPACE" = "" ]; then
        errorMessage "Could not determine $TS_TYPE Tablespace."
    fi
}
 
getDataTablespace() {
    queryTablespace \
        "SELECT TABLESPACE_NAME 
         FROM USER_TABLES 
         WHERE TABLE_NAME = 'KNTA_USERS'" \
         DATA
 
    DATA_TABLESPACE=$TABLESPACE
}
 
getIndexTablespace() {
    queryTablespace \
        "select tablespace_name  
         from user_indexes 
         where index_name = 'KNTA_USERS_U1'" \
         INDEX
 
    INDEX_TABLESPACE=$TABLESPACE
}
 
getClobTablespace() {
    queryTablespace \
       "select s.tablespace_name 
        from user_segments s, all_lobs a 
        where a.table_name = 'KNTA_NOTIFICATIONS' 
        and   a.column_name = 'PARENT_TEXT' 
        and   s.segment_name = a.segment_name"  \
       CLOB
 
    CLOB_TABLESPACE=$TABLESPACE
}
 
 
###
## getTablespace is deprecated and should no longer be used.  Use the functions
## above, which is far more robust.  This is only being included in case 
## custom scripts are using it.
#
getTablespaceValue() {
    type=$1
 
    $JAVA_HOME/bin/java $QUERYTOOL \
        "select NAME 
        from KINS_TABLESPACES where TYPE='$type'" \
        $KNTA_HOME
}
 
getTablespace() {
    TABLESPACE=`getTablespaceValue $1`
 
 
    if [ "$TABLESPACE" = "" ]; then
        echo "ERROR: Could not determine $1 tablespsace.  This information "
        echo "       is normally contained in the KINS_TABLESPACES table,"
        echo "       which is created during installation"
        exit 1;
    fi
}
 
 
###
##
#
checkForNewDeployScript() {
    # only do something if kDeploy.sh is included in the bundled
    if [ -f "$PATCHHOME/kDeploy.sh" ]; then
        CURRFILE=`cat bin/kDeploy.sh`
        NEWFILE=`cat $PATCHHOME/kDeploy.sh`
 
        # if the files are different, copy the file to bin and force the user
        # to rerun the script
        if [ "$CURRFILE" != "$NEWFILE" ]; then
            # back up the existing kDeploy.sh
            cp bin/kDeploy.sh bin/kDeploy.sh.$DEPLOY_ID
            # cp the new script
            cp $PATCHHOME/kDeploy.sh bin/kDeploy.sh
            # the user must rerun kDeploy.sh
            echo
            echo "NOTE: This deployment includes a new version of kDeploy.sh, which has been"
            echo "copied to bin.  Please rerun kDeploy.sh.  You can use -S to skip the"
            echo "kDeploy.sh check if needed."
            echo
            exit 55
        fi
    fi
}
 
 
###
## Checks to see if the file system version is greater than the minimum 
#  version required.  This is used to tie deployments to a minimum SP
#
checkFileSystemVersion() {
 
    if [ ! -f "$KNTA_HOME/conf/version.txt" ]; then
        errorMessage "Cannot find file $KNTA_HOME/conf/version.txt!" \
            "This file contains the file system version information.  This" \
            "deployment cannot be installed until this issue is resolved."
    fi
 
    FS_VERSION=`cat $KNTA_HOME/conf/version.txt`
 
    if [ "$_ECHO_TYPE" = "1" ]; then 
        FS_VERSION_NO=`echo -n $FS_VERSION | sed -e 's/.*,//'`
        DEPENDS_ON_VERSION_NO=`echo -n $DEPENDS_ON_VERSION | sed -e 's/.*,//'`
    else
        FS_VERSION_NO=`echo $FS_VERSION | sed -e 's/.*,//'`
        DEPENDS_ON_VERSION_NO=`echo $DEPENDS_ON_VERSION | sed -e 's/.*,//'`    
    fi
    
    if [ "$FS_VERSION_NO" -lt "$DEPENDS_ON_VERSION_NO" ]; then
        # If the variable MINIMUM_SP_REQUIRED is set, use it in the 
        # error message.  If not, just report the build number.  It is not
        # of much use to the user but is all we will have.  This should not
        # be the norm
        if [ "$MINIMUM_SP_REQUIRED" != "" ]; then
            errorMessage "In order to install this deployment you must be on " \
                "$MINIMUM_SP_REQUIRED or later.  Please install the latest" \
                "Service Pack before continuing."
        else
            errorMessage "In order to install this deployment your filesystem "\
                "must at least be on build number $DEPENDS_ON_VERSION." \
                "Your filesystem looks to be on $FS_VERSION"
        fi
    fi
}
 
 
loginfo() {
    LOGS=$KNTA_HOME/logs/$WORK_DIR/$VERSION/$DEPLOY_ID
    mkdir -p $LOGS
}
 
 
filesysJarExtract() {
    JARF=$1
    EXTRACT_DIR=$2;
    FILESYS=$PATCHHOME/$JARF
 
    if [ ! -f "$FILESYS" ]; then
        return 0
    fi
    
    # If the back up directory exists, do not back up again.
    if [ -f "$KNTA_HOME/$BACKUP_NAME/$DEPLOY_ID" ]; then
       return 0
    fi
 
    echo "  Extracting $JARF ($EXTRACT_DIR)"
 
    # Find files that we will need to install
    cd $EXTRACT_DIR
 
    # Backup the files in KNTA_HOME if they exist
    FILELIST=tmp.$$.lst
    $JAR tf $FILESYS 1> $FILELIST 2>&1
 
    if [ "$DO_NOT_BACKUP" != "1" ]; then
        BKUP_DIR=$KNTA_HOME/$BACKUP_NAME/$DEPLOY_ID/$JARF        
        for A_FILE in `cat $FILELIST`; do
            if [ -f "$EXTRACT_DIR/$A_FILE" ]; then
                A_DIR=`dirname $A_FILE`
                mkdir -p $BKUP_DIR/$A_DIR
                cp "$EXTRACT_DIR/$A_FILE" "$BKUP_DIR/$A_FILE"
            fi
        done
    fi
 
    # Copy everything in KPATCH_HOME to KNTA_HOME
    UNJAR=$LOGS/jarxvf.$$.log
    $JAR xvf $FILESYS 1> $UNJAR 2>&1
 
    if [ "$?" != "0" ]; then
        echo  "ERROR: $JAR xf $FILESYS failed.";
        echo "       Please see $UNJAR for more information."
        exit 1;
    fi
 
    \rm -f $FILELIST
}
 
### =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
## KDEPLOY STANDARD DEPLOYMENTS: All must start with DPL_
#
#  Function for recompiling JSP files
#
DPL_RECOMPILE_JSPS() {
 
    JSP_LOG=$LOGS/RecompileJSPs.$$.log
 
    echo
    echo "+++"
    echo "+++ Recompiling JSP Files"
    echo "+++    log file: $JSP_LOG"
    echo "+++"
 
    cd $KNTA_HOME/bin
    sh kJSPCompiler.sh -all 1> $JSP_LOG 2>&1
}
 
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# IMPORTCONTENT: Use this for importing content into a Running ITG Schema.
# To use this you need:
#
# 1  DEPENDS_ON to be at least SP3
# 2  REQUIRES_SERVER_RUNNING=1
# 3  CONTENT_TO_IMPORT=1
# 4  phases/content/XXX/Content directory that contains the content zip files
# 5  solutions.properties file needed
#
DPL_IMPORTCONTENT() {
 
    CONTENT_FULL_DIRECTORY="$PATCHHOME/phases/content"
 
    echo
    echo +++
    echo +++ Importing ITG Content
    echo +++    :  $CONTENT_FULL_DIRECTORY
    echo +++
 
    if [ ! -d "$CONTENT_FULL_DIRECTORY" ]; then
        errorMessage "The content directory $CONTENT_DIRECTORY does not exist"
    fi
    
    if [ "$_ECHO_TYPE" = "1" ]; then
      REL_LOGS=`echo -n $LOGS |sed -e "s#${KNTA_HOME}/##"`
    else
        REL_LOGS=`echo $LOGS |sed -e "s#${KNTA_HOME}/##"`
    fi
    
    importContent  \
        "$kintana_user" \
        "$kintana_pass" \
        "$CONTENT_FULL_DIRECTORY" \
        "." \
        "com.kintana.core.server.tools.ContentImporter" \
        "-zip_logs $REL_LOGS"
 
}
 
DPL_FILESYSTEM() {
    echo
    echo +++
    echo +++ Applying Filesystem Changes
    echo +++
 
    # get the root level files
    filesysJarExtract $FS_HOMEFILE "$KNTA_HOME"
 
    # loop through all the multiple servers and deploy the war level files
    for servhome in $KNTA_HOME/server/*/deploy/itg.war; do
       filesysJarExtract $FS_WARFILE $servhome
    done
 
    for ms in $KNTA_HOME/server/*; do
        if [ -d "$ms" ]; then
            filesysJarExtract $FS_MSFILE $ms
        fi
    done
}
 
DPL_DATABASE() {
    echo
    echo +++
    echo +++ Applying Database Changes
    echo +++
 
    DRIVER="$PATCHHOME/phases/db/$DEPLOY_ID.sql"
 
    if [ -f "$DRIVER" ]; then
      run_SQL_script \
            "$DRIVER" "$INDEX_TABLESPACE $CLOB_TABLESPACE"
    else 
          errorMessage "File $DRIVER does not exists."
    fi
}
 
DPL_DASHBOARD() {
    echo
    echo +++
    echo +++ Applying Dashboard Changes
    echo +++
    
    DSH_DIR="$PATCHHOME/phases/dashboard"    
    
    if [ -f "$DSH_DIR/dashboard-content.xml" ]; then
       cd $KNTA_HOME/utilities/ant
       . ./antenv
       cd $KNTA_HOME
       getServerConfVariable JDBC_URL
       getServerConfVariable DB_USERNAME
 
       SPLOG_DIR=$KNTA_HOME/$LOG_DIR/$DEPLOY_ID
       mkdir -p $KNTA_HOME/$LOG_DIR/$DEPLOY_ID
       
       echo "  Importing Dashboard Database Changes."
       kAnt -l $SPLOG_DIR/dsh-import.log -f "$DSH_DIR/dashboard-utils.xml" import-content -Ddsh.content.xml="$DSH_DIR/dashboard-content.xml" -Ddsh.jdbc.url="$P_JDBC_URL" -Ddsh.jdbc.user="$P_DB_USERNAME" -Ddsh.jdbc.pswd="$PASSWORD"
       
       if [ "$?" != 0 ]; then
          errorMessage "Dashboard Data Import Failed."
       else
          echo "  Import Succeeded."
       fi
       
       # Go back to the bin dir.
       cd $KNTA_HOME/bin
       
    else
       echo "  Skipping.  No Dashboard data to import"
    fi
}
 
DPL_VERSIONTRACKING() {
    echo
    echo +++
    echo +++ Updating Version Information
    echo +++
    
    VSN_DIR="$PATCHHOME/phases/versionTracking"
    
    cd $KNTA_HOME/utilities/ant
    . ./antenv
    cd $KNTA_HOME
    getServerConfVariable JDBC_URL
    getServerConfVariable DB_USERNAME
 
    SPLOG_DIR=$KNTA_HOME/$LOG_DIR/$DEPLOY_ID
    mkdir -p $KNTA_HOME/$LOG_DIR/$DEPLOY_ID
 
    echo "  Updating version information."
    kAnt -l $SPLOG_DIR/version-update.log -f "$VSN_DIR/version-utils.xml" update-version -Ditg.home="$KNTA_HOME" -Ditg.patch.dir="$PATCHHOME" -Ditg.jdbc.url="$P_JDBC_URL" -Ditg.jdbc.user="$P_DB_USERNAME" -Ditg.jdbc.pswd="$PASSWORD"
 
 
    if [ "$?" != 0 ]; then
      errorMessage "Version Update Failed."
    else
      echo "  Version Update Succeeded."
    fi
 
    # Go back to the bin dir.
    cd $KNTA_HOME/bin
}
 
DPL_UPDATEHTML() {
    echo
    cd $KNTA_HOME/bin
    sh kUpdateHtml.sh
}
 
### =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
#h
#hkDeploy.sh
#h---------
#hThis is the driver script for installing Mercury ITG deployments. 
#h
#hUsage: sh kDeploy.sh <parameters>
#h         -f                  : Force the reinstallation of the deployments
#h         -h                  : Usage
#h         -i <DEPLOYMENT_ID>  : patch to install       
#h         -k <PASSWORD>       : Mercury ITG schema password 
#h         -l                  : List all installed deployments only.
#h         -u <KNTA_USER>      : Mercury ITG userid to use for migrations
#h         -p <KNTA_PASSWORD>  : Password to KNTA_USER (see -u)
#h         -X                  : Do not re-extract the deployments
#h         -B                  : Do not back up file system changes
#h         -D                  : Directory in which to find deployment bundles
#h         -S                  : Skip check for new version of kDeploy.sh
#h         -best-practices     : Install licensed Best Practice content
#h         -tidy               : Delete deployment backup files
#h         -lang <language to install> : language to install
#h
 
install_LP() {
    FILE=$1
    LANG=$2
    DEPLOY_ID="Lang_Pack"
 
    # Grep out just the filename from LP_FILE
    if [ "$_ECHO_TYPE" = "1" ]; then 
      LP_FILE=`echo -n $FILE | sed -e 's/.*\/ITG/ITG/'`
    else
        LP_FILE=`echo $FILE | sed -e 's/.*\/ITG/ITG/'`
    fi
    
    LP_INSTALL_DIR="$KNTA_HOME/deploy/LP"
    REQUIRES_SERVER_STOPPED=1
 
    loginfo
    isServerRunning
 
    cd $KNTA_HOME/utilities/ant
    . ./antenv
    cd $KNTA_HOME
    getServerConfVariable JDBC_URL
    getServerConfVariable DB_USERNAME
 
    # get requierd Tablespace info
    getDataTablespace
    getIndexTablespace
    getClobTablespace
 
    echo
    echo +++
    echo +++ Installing language pack $LP_FILE
    echo +++
 
    mkdir -p $LP_INSTALL_DIR
    mv $MAIN_LP_DIR/$LP_FILE $LP_INSTALL_DIR
 
    # Remove old best-practices directory if it exists
    if [ -d "$LP_INSTALL_DIR/BestPractices" ]; then
        rm -rf $LP_INSTALL_DIR/BestPractices/*
    fi
 
    cd $LP_INSTALL_DIR
    $JAR xvf $LP_INSTALL_DIR/$LP_FILE
    if [ "$?" != "0" ]; then
        echo "ERROR: $JAR xf $$LP_INSTALL_DIR/$LP_FILE failed.";
        exit 1;
    fi
 
    SPLOG_DIR=$KNTA_HOME/$LOG_DIR/$DEPLOY_ID
    mkdir -p $KNTA_HOME/$LOG_DIR/$DEPLOY_ID
 
    LP_CORE_FILE="$LP_INSTALL_DIR/itgcore-language-pack_$LANG.zip"
    LP_PM_FILE="$LP_INSTALL_DIR/pm-language-pack_$LANG.zip"
    LP_I18N_DUMP_FILE="$LP_INSTALL_DIR/orig.i18n.gold.dmp.file"
    INSTALLER_DIR="$KNTA_HOME/install_$VERSION"
 
    # Parse P_jdbc_url to get some specific info
    if [ "$_ECHO_TYPE" = "1" ]; then
        jdbc_info=`echo -n $P_JDBC_URL | awk -F@ '{print $2}'`
        db_sid=`echo -n $jdbc_info | awk -F: '{print $3}'`
    else
        jdbc_info=`echo $P_JDBC_URL | awk -F@ '{print $2}'`
        db_sid=`echo $jdbc_info | awk -F: '{print $3}'`
    fi
    
    echo "Installing Language Pack for language $LANG."
 
    # Extract filesystem into various server directories
    for ms in $KNTA_HOME/server/*; do
        SERVER_DIR="$ms"
        if [ -d "$ms" ]; then
            extract_LP_fs $LP_CORE_FILE $ms
            extract_LP_fs $LP_PM_FILE $ms
        fi
    done
 
    # Drop the existing i18n tables (if any) and re-import
    run_SQL_script "$LP_INSTALL_DIR/i18n_drop_tables.sql"
 
    if [ "$_ECHO_TYPE" = "1" ]; then
        uc_LANG=`echo -n $uc_LANG | tr a-z A-Z`
    else
        uc_LANG=`echo $uc_LANG | tr a-z A-Z`
    fi
    
       if [ "$LANG" = "es" ]; then 
            LOCALE="$LANG" 
       elif [ "$LANG" = "it" ]; then 
            LOCALE="$LANG" 
       elif [ "$LANG" = "pt_BR" ]; then
            LOCALE="$LANG"
       else 
            LOCALE=$LANG'_'$uc_LANG 
       fi 
 
    kAnt -l $SPLOG_DIR/install_lp.log -f "$LP_INSTALL_DIR/deploy-LP.xml" deploy-lang-pack -Dknta.home="$KNTA_HOME" -Dbuild.lang="$LANG" -Dlocale="$LOCALE" -Dlp.install.dir="$LP_INSTALL_DIR" -Di18n.conf.file="$LP_INSTALL_DIR/i18nTool.conf" -Dserver.dir="$SERVER_DIR" -Dinstaller.dir="$INSTALLER_DIR" -Djdbc.url="$P_JDBC_URL" -Djdbc.user="$P_DB_USERNAME" -Djdbc.pswd="$PASSWORD" -Djdbc.info="$jdbc_info" -Djdbc.sid="$db_sid" -Djava.home="${JAVA_HOME}" -Ddata.tablespace="$DATA_TABLESPACE" -Dindex.tablespace="$INDEX_TABLESPACE" -Dclob.tablespace="$CLOB_TABLESPACE"
 
    if [ "$?" != 0 ]; then
      errorMessage "Language Pack Install Failed."
    fi
 
    # Only for PLT, run the i18nDBUpdates.sql. 
    if [ "$LANG" = "ja" ]; then
        echo "Untranslate some strings for PLTs"
        run_SQL_script "$LP_INSTALL_DIR/i18nDBUpdates.sql"
    fi
 
    echo " Language Pack Install Succeeded."
 
    exit 0;
}
 
extract_LP_fs() {
    FILE=$1
    DIR=$2
 
    cd $DIR
    unzip -o $FILE
 
    echo "Done unzipping $FILE"
    # Go back to the bin dir.
    cd $KNTA_HOME/bin
}
 
 
#
# Set up the solutions
#
installBestPractices() {
    CONTENT_HOME="integration/mercury/bestpractices"
    DEPLOY_ID="BestPractices"
    DESCRIPTION="Mercury_ITG_Best_Practices"
    REQUIRES_SERVER_STOPPED=0
 
    echo
    echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
    echo "         Mercury IT Governance Best Practice Content"
    echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
    echo
    echo "You have chosen to install the Mercury IT Governance Best Practice"
    echo "Content. This licensed content is a collection of best practice"
    echo "processes that will enable you to efficiently run your IT department."
    echo "This content supports functions like Portfolio Management, Project"
    echo "and Program Management, and Demand Management."
    echo
 
    loginfo
    is_current_patch_installed
    isServerRunning
    getKintanaLogin
    
    if [ "$_ECHO_TYPE" = "1" ]; then
        REL_LOGS=`echo -n $LOGS |sed -e "s#${KNTA_HOME}/##"`
    else
        REL_LOGS=`echo $LOGS |sed -e "s#${KNTA_HOME}/##"`
    fi
    
    # import the content
    ${JAVA_HOME}/bin/java com.kintana.core.server.tools.ContentImporter \
        -username "$kintana_user" \
        -password "$kintana_pass" \
        -sol_home "$CONTENT_HOME" \
        -zip_logs "$REL_LOGS"
    
    if [ "$?" != "0" ]; then
        echo
        echo "ERROR: The content did not import successfully"
        exit 1;
    fi
 
    # run the post-content configurations
    ${JAVA_HOME}/bin/java com.kintana.core.server.tools.BestPracticeSetup \
        -password "$PASSWORD" \
        -itg_home "$KNTA_HOME" \
        -logs "$LOGS"
 
    if [ "$?" != "0" ]; then
        echo
        echo "ERROR: Final Best Practice configuration failed."
        exit 1;
    fi
    
    update_patch_list $DEPLOY_ID
 
    echo
    echo "Mercury ITG Best Practices have been deployed."
 
    exit 0;
}
 
chooseDeployment() {
    DEPLOYS_AVAIL=0
    for i in $DEPLOYMENT_HOME/$DEPLOY_PREFIX-$VERSION-*.jar; do
        AST=""
        if [ -f "$i" ]; then
            if [ "$DEPLOYS_AVAIL" = "0" ]; then
                echo
                echo "The following deployments are available for installation"
                echo "(* already deployed)"
                echo
            fi
            DEPLOYS_AVAIL=`expr $DEPLOYS_AVAIL + 1`
            
            if [ "$_ECHO_TYPE" = "1" ]; then
                F_ID=`echo -n $i | awk -F- ' { print $3 }' | sed -e 's/\.jar//'`
            else
                F_ID=`echo $i | awk -F- ' { print $3 }' | sed -e 's/\.jar//'`
            fi
            
            is_patch_installed $F_ID
 
            if [ "$?" = "0" ]; then
                AST="*"
            fi
 
            necho "  $DEPLOYS_AVAIL) $F_ID $AST"
            eval "DEPLOY_$DEPLOYS_AVAIL=$F_ID"
        fi
    done
 
    if [ "$DEPLOYS_AVAIL" = "0" ]; then
        errorMessage "There is nothing to deploy." \
                     "Either use -i <ID> to specify a deployment, or" \
                     "-D <Deployment Directory> to look for deployments in" \
                     "another location."
    else
        echo 
        echo "Choose a deployment or (q)uit: ";
        read CHOICE
 
        if [ "$CHOICE" = "q" ]; then
            exit 0;
        fi
 
        if [ "$_ECHO_TYPE" = "1" ]; then
            DEPLOY_ID=`eval echo -n \\$DEPLOY_$CHOICE`
        else
            DEPLOY_ID=`eval echo \\$DEPLOY_$CHOICE`
        fi
        
        if [ "$DEPLOY_ID" = "" ]; then
            errorMessage "Invalid choice.  Please rerun kDeploy.sh"
        fi
    fi
}
 
findDeploymentHome() {
    if [ "$DEPLOYMENT_HOME" = "" ]; then
        if [ "$ITG_DEPLOYMENT_HOME" != "" ]; then
            DEPLOYMENT_HOME="$ITG_DEPLOYMENT_HOME"
        else
            DEPLOYMENT_HOME="$KNTA_HOME"
        fi
    fi
}
 
 
###
## Prompts for Y/N and ensures that a Y is a Y
#
yesOrNo() {
    ynvar="$1"
 
    # get the value
    read YN_RESP
 
    # if a "y" is entered, switch to a Y (so we don't have to check both
    # every time
    if [ "$YN_RESP" = "y" ]; then
        YN_RESP="Y"
    fi
 
    # save the value to the variable specified
    eval "$ynvar=$YN_RESP"
}
 
errorMessage() {
  echo
  echo "ERROR: $1"
  shift
 
  while [ "$1" != "" ]; 
  do
    echo "       $1"
    shift;
  done
 
  echo
  exit 1;
}
 
###############################################################################
###
## addServerConfVariable(): Adds a new server.conf variable, only if it does
#                           not exist.
addServerConfVariable() {
  variable=$1
  value=$2
 
  SERVERCONF=../server.conf
 
  # back up the old one
  cp $SERVERCONF $SERVERCONF.save
 
  grep "^$variable" $SERVERCONF 1> /dev/null 2>&1
 
  if [ "$?" != 0 ]; then
      necho >> $SERVERCONF
      necho "$variable=$value" >> $SERVERCONF
  fi
}
 
###
## checkJavaHome(): checks to see if the the environment variable JAVA_HOME
#                   is set.
#
checkJavaHome() {
  if [ "$JAVA_HOME" = "" ]; then
    errorMessage "You must set JAVA_HOME before running kDeploy.sh."
  fi
}
 
###
## checkForJar():  Checks to see if the jar command is available.  It is needed
#                  by the install program.
#
checkForJar() {
  tmpjarfile=tmp.$$.jar
 
  # use $JAR
  JAR=$JAVA_HOME/bin/jar
  
  # run the jar command
  $JAR cvf $tmpjarfile kDeploy.sh 1> /dev/null 2>&1
 
  if [ "$?" != 0 ]; then
    errorMessage "Could not execute $JAR properly.";
  fi
 
  \rm -f $tmpjarfile
}
 
###
## promptFor():
#
promptFor() {
  prompt=$1
  mode=$2
  value=$3
 
  # see if value already has a value
  if [ "$_ECHO_TYPE" = "1" ]; then
      df_valcmd=`echo -n eval echo -n \\$$value`
  else
      df_valcmd=`echo eval echo \\$$value`
  fi
  df_val=`$df_valcmd`
 
  if [ "$df_val" = "" ]; then
    if [ "$mode" != "" ]; then
      stty $mode
    fi
 
    necho $prompt
    read df_val
    stty echo 
 
    necho
  fi
 
  echo
  eval "$value=$df_val"
}
 
serverStatus() {
  OUTPUT="isServerRunning.$$"
  cd "$KNTA_HOME"
 
  ${JAVA_HOME}/bin/java com.kintana.core.server.tools.CheckStatus -source kStatus.sh $@  1> $OUTPUT 2>&1
  
  cat $OUTPUT | grep "mode:" 1> /dev/null 2>&1
 
  necho $?
 
  cd bin
  \rm -f $OUTPUT
}
 
###
## isServerRunning()
#
isServerRunning() {
  STAT=`serverStatus`
 
  if [ "$STAT" != "$REQUIRES_SERVER_STOPPED" ]; then
    if [ "$REQUIRES_SERVER_STOPPED" = "1" ]; then
        errorMessage "In order to deploy, the server must be" \
            "stopped.  Please stop the server before running kDeploy.sh."
    else
        errorMessage "In order to deploy, the server must be" \
            "running.  Please start the server before running kDeploy.sh."
    fi
  fi
}
 
###
## run_SQL_script
#
run_SQL_script() {
  cd $runDir
  s_script=$1
  s_param=$2
  s_user=$3
  s_pass=$4
 
  if [ "$s_user" = "" ]; then
    s_user="$P_DB_USERNAME"
    s_pass="$PASSWORD"
  fi
 
  if [ "$_ECHO_TYPE" = "1" ]; then
      s_prefix=`echo -n $s_script | sed -e 's#.*/##' | sed -e 's/\..*//'`
  else
      s_prefix=`echo $s_script | sed -e 's#.*/##' | sed -e 's/\..*//'`
  fi
  s_log=$LOGS/$s_prefix.$$.log
 
  sqlminus $s_user $s_pass $P_JDBC_URL $s_script "$s_param" $s_log "$s_error"
 
  if [ $? -ne 0 ]; then
    echo
    echo "ERROR: $s_script failed!"
    if [ "$s_message" != "" ]; then
      echo "       Please consult $s_log for more information"
    fi
    exit 23
  fi
}
 
###
## patchReport(): Prints out a report of the patches currently installed on
#                 the server.
#
patchReport() {
  echo
  $JAVA_HOME/bin/java $DEPLOYREPORT $KNTA_HOME
  echo
}
 
###
## get_patch_list
#
get_patch_list() {
    P_LIST=`$JAVA_HOME/bin/java $QUERYTOOL \
        "select distinct DEPLOYMENT_ID 
        from KINS_DEPLOYMENTS where VERSION='$VERSION'" \
        $KNTA_HOME`
 
    for i in $P_LIST; do
        D_ID=$i
        if  [ "$HOST_TYPE" = "WINDOWS" ]; then
            D_ID=`Winstrip $D_ID`
        fi
        LIST="$LIST:$D_ID"
    done
 
    # DEPLOYED LIST is now a ':' separated list of patches, ripe for 
    # grepping
    if [ "$_ECHO_TYPE" = "1" ]; then
        DEPLOYED_LIST="`echo -n $LIST | sed -e 's/ /:/g'`:"
    else
        DEPLOYED_LIST="`echo $LIST | sed -e 's/ /:/g'`:"
    fi
}
 
###
## is_patch_compatible - loop through the deploys with which this one is 
#                        incompatible and make sure not of them exist.
#
is_patch_compatible() { DEP_INCOMPAT=
    for x in $INCOMPATIBLE_WITH; do
        is_patch_installed "$x"
        if [ "$?" = "0" ]; then
            DEP_INCOMPAT="$DEP_INCOMPAT $x"
        fi
    done
 
    if [ "$DEP_INCOMPAT" != "" ]; then
        errorMessage \
            "$DEPLOY_ID is not compatible with$DEP_INCOMPAT and cannot be" \
            "deployed in this instance."
    fi
}
 
###
## is_patch_installed
#
is_patch_installed() {
  lookfor=$1
  
  necho $DEPLOYED_LIST | grep ":$lookfor:" 1> /dev/null 2>&1
  return "$?"
}
 
###
## is_current_patch_installed
#
is_current_patch_installed() {
  if [ "$FORCE_INSTALL" = "1" ]; then
    return
  fi
 
  if [ "$EXTENDED_VERSION" != "" ]; then
     _CHECK_ID=$DEPLOY_ID"_"$EXTENDED_VERSION
  else
     _CHECK_ID=$DEPLOY_ID
  fi
 
  is_patch_installed "$_CHECK_ID"
 
  if [ "$?" = "0" ]; then
    echo 
    echo "This deployment has already been installed.  Would you like to "
    echo "reinstall it? (y/n)" 
    read YN
 
    if [ "$YN" = "y" -o "$YN" = "Y" ]; then
        necho 
    else
        exit 1
    fi
  fi
}
 
###
## is_patch_dependency_installed
#
is_patch_dependency_installed() {
  DEP_MISSING=
 
  for x in $DEPENDENT_ON; do
    is_patch_installed "$x"
    if [ "$?" != "0" ]; then
        DEP_MISSING="$DEP_MISSING $x"
    fi
  done
 
  # Create a comma (,) delimited list of patch dependencies not installed.
  if [ "$_ECHO_TYPE" = "1" ]; then
      DEP_MISSING=`echo -n "$DEP_MISSING" | sed 's/^[ ]*//' |sed 's/ /, /g'`
  else
      DEP_MISSING=`echo "$DEP_MISSING" | sed 's/^[ ]*//' |sed 's/ /, /g'`
  fi
  
  if [ "$DEP_MISSING" != "" ]; then
    errorMessage "This patch has dependencies that have not yet been " \
                 "installed.  " \
                 " " \
                 "Required: $DEP_MISSING"
 
  fi
}
 
###
## update_patch_list
#
update_patch_list() {
  tmp_patch_number="$1"
  tmp_version_number=$VERSION
 
  if [ "$_ECHO_TYPE" = "1" ]; then
      tmp_desc=`echo -n $DESCRIPTION | sed -e 's/ /_/g'`
  else
      tmp_desc=`echo $DESCRIPTION | sed -e 's/ /_/g'`
  fi
  
  if [ "$KNTA_CLIENT_VERSION" != "" ]; then
     tmp_desc="${tmp_desc}_${KNTA_CLIENT_VERSION}"
  fi
  
  if [ "$EXTENDED_VERSION" != "" ]; then
     tmp_desc="${tmp_desc}_[${EXTENDED_VERSION}]"
     tmp_patch_number="${tmp_patch_number}_${EXTENDED_VERSION}"
  fi
 
  if [ "no$tmp_patch_number" = "no" ]; then
    echo "update_patch_list:  no patch number specified"
    return 26
  else
    run_SQL_script  \
      "db/update_patch_table.sql" \
      "$tmp_patch_number $tmp_version_number $tmp_desc"
  fi
}
 
###
## update_patch_list_with_current
#
update_patch_list_with_current() {
  update_patch_list "$DEPLOY_ID"
}
 
###
## update_client_version(): Bumps the client version
#
update_client_version() {
  if [ "$KNTA_CLIENT_VERSION" != "" ]; then
    # this changes the value in the database
    run_SQL_script "db/update_client_version.sql" $KNTA_CLIENT_VERSION
  fi
}
 
###
## sourceVariables():  Run kVariables.sh
#
sourceVariables() {
  runDir=`pwd`
  cd ..
  KNTA_HOME=`pwd`
 
  if [ -f bin/kVariables.sh ];
  then
    cd "$KNTA_HOME/bin"
    . ./kVariables.sh
    . ./SQLMinus.sh
    cd "$runDir"
  else
    errorMessage "You must run this script from the bin directory."
  fi
}
 
###
## getDatabaseVersion(): Gets the version from the database, in the form of
#                        the first three numbers smushed together.
#
getDatabaseVersion() {
    VERSION=`$JAVA_HOME/bin/java $QUERYTOOL  \
        "select max(version_number) from knta_version_history"  \
        $KNTA_HOME`
 
    if [ "$?" != "0" -o "$VERSION" = "" ]; then
        echo "ERROR: Could not determine the version of the Mercury ITG server!";
        echo "       Patch cannot be applied."
        exit 1;
    fi
 
    VERSION=`echo $VERSION | awk -F. '{ print $1$2$3 }'`
}
 
###
## removePrevPatches(): If true, remove the classes/com directory to get
#                       rid of any patches.
#
removePrevPatches() {
  if [ "$REMOVE_PREVIOUS_PATCHES" = "1" ]; then
    \rm -rf $KNTA_HOME/server/*/deploy/itg.war/WEB-INF/classes/*
  fi
}
 
###
##
# importContent():  used to import content for Solutions
#                     $1 = knta user with which to perform the install
#                     $2 = knta passwd
#                     $3 = directory where the content is stored
#                     $4 = list of comma separated zip content bundles
importContent() {
    # these four are absolutely required
    knta_username=$1
    knta_passwd=$2
    content_dir=$3
    
    if [ "$_ECHO_TYPE" = "1" ]; then
        directories=`echo -n $4 | sed -e 's#,# #g'`
    else
        directories=`echo $4 | sed -e 's#,# #g'`
    fi
    
    # Did the caller specify the tool to use?
    imp_tool=$5
 
    # what about some extra parameters?
    imp_params="$6"
 
    if [ "$HOST_TYPE" = "UNIX" ]; then
        ulimit -n 1000
        umask 022
    fi
 
    # DEFAULT import tool
    if [ "$imp_tool" = "" ]; then
        imp_tool="com.kintana.$SOLUTION_DIR.util.ContentImporter"
    fi
 
    CWD=`pwd`
    cd $KNTA_HOME
    for directory in $directories; do
        echo "Importing bundle ${content_dir}/${directory}"
        ${JAVA_HOME}/bin/java $imp_tool \
            -username $knta_username \
            -password $knta_passwd \
            -zip_path ${content_dir}/${directory} $imp_params
        RETURN_VALUE=$?
        if [ $RETURN_VALUE != 0 ]; then
            echo "-->Import of $directory failed"
            exit $RETURN_VALUE
        else
            echo "-->Import of $directory successful"
        fi
    done
    cd $CWD
}
 
 
###
##
# verifyServerStarted(): verifies the server is started, loops until it can 
#                        connect
#
verifyServerStarted(){
    CWD=`pwd`
    cd $KNTA_HOME/bin
 
    connection=0
    until [ "$connection" = '1' ]; do
        echo
        echo "Verifying connection to the Mercury ITG server..."
 
        STAT=`serverStatus`
 
    if [ "$STAT" != "0" ]; then
            echo
            echo " Please start the server to continue the installation"
            echo "[hit enter when done]"
            read tmp
        else
            connection=1
            echo "Connection successful!"
            echo ""
        fi
    done
    cd $CWD
 
}
 
###
##
# getKintanaLogin(): prompt the user for a kintana user and kintana passwd,
#                    verifies login/passwd pair, loops until correct pair is
#                    given
#
getKintanaLogin(){
    validuser=0;
    until [ "$validuser" = 1 ]; do
        if [ "$kintana_user" = "" ]; then
            echo
            echo "Please enter a valid Mercury ITG logon username: "
            read kintana_user
            stty echo
        fi
 
        if [ "$kintana_pass" = "" ]; then
            echo
            stty -echo 
            echo "Please enter the password for $kintana_user: "
            read kintana_pass
            stty echo 
        fi
 
        echo
        echo "Verifying username/password..."
        #
        # make sure that the username/password is valid
        #
        cd $KNTA_HOME
        ${JAVA_HOME}/bin/java com.kintana.ac.importer.Accelerator \
            -username $kintana_user -password $kintana_pass -check_logon \
            -zip_logs $LOGS
        if [ "$?" != "0" ]; then
            echo "ERROR: invalid username/password pair ($kintana_user)"
            kintana_user=
            kintana_pass=
        else
            validuser=1
        fi
 
        echo
    done
}
 
setServerMode() {
    CWD=`pwd`
    cd $KNTA_HOME/bin
 
    SSM_PASSWORD="$PASSWORD"
 
    if [ "$2" != "" ]; then
        SSM_PASSWORD="$2"
    fi
 
    sh setServerMode.sh $1 $SSM_PASSWORD
    cd $CWD
}
 
###
## Functions for cleaning up
#
 
Find() {
    for i in `ls -1 "$1"`; do
        if [ -d "$1/$i" ]; then
            Find "$1/$i"
        else
            if [ -f "$1/$i" ]; then 
                necho $1/$i;
            fi
        fi 
    done
}
 
###
## This function is used to ensure that any trace of a Windows-style end of
#  line character is removed from a string.  This means that all deployment
#  IDs must end in 0-9, a-z, A-Z, -, or _.  
#
Winstrip() {
    WSTR=$1
    if [ "$HOST_TYPE" = "WINDOWS" ]; then
        WSTR=`echo -n $WSTR | sed -e 's/[^0-9A-Za-z\-\_]$//'`
    fi
    echo $WSTR
}
 
###
## Given the ID and type (pre-5.5 everything was a patch, after that they 
#  were deployment) clean up the "temporary" files that were created when 
#  deploying.  This amounts to:
#     1) HOME/deploy/VER/ID
#     2) Any file.ID created as a backup
#
CleanupFiles() {
    ID=$1
    TYPE=$2
    FLIST=$3
 
    ID=`Winstrip $ID`
 
    echo
    echo "Cleaning up $TYPE $ID"
    if [ -d "$KNTA_HOME/$TYPE/$ID" ]; then
        necho "    rm -rf $KNTA_HOME/$TYPE/$ID"
        if [ "$CLN_CONT" != "M" ]; then
          \rm -rf $KNTA_HOME/$TYPE/$ID
        fi
    fi
 
    if [ "$_ECHO_TYPE" = "1" ]; then
        PID=`echo -n $ID | sed -e 's/.*\///'`
    else
        PID=`echo $ID | sed -e 's/.*\///'`
    fi
    
    for f in `grep "\.$PID" $FLIST`; do
        necho "    rm -f $f"
        # removing files is always a little scary.  Check to make sure that
        # the file is ACTUALLY a file before removing it.
        if [ -f "$f" ]; then
            if [ "$CLN_CONT" != "M" ]; then
                # do not use -r here!
                \rm -f $f
            fi
        fi
    done
    BKUP_DIR="$KNTA_HOME/$BACKUP_NAME/$PID"
    if [ -d $BKUP_DIR ]; then
       echo 
       echo "    rm -rf $BKUP_DIR"
       if [ "$CLN_CONT" != "M" ]; then
           \rm -rf $BKUP_DIR
       fi
       
    fi
}
 
###
## Cleanup - gets a list of installed patches and deployments and cleans up
#            the HOME directory.
#
Cleanup() {
    CLN_PATCH_LIST=
    CLN_DEPLOY_LIST=
 
    echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
    echo "                       DEPLOYMENT CLEANUP"
    echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
    echo
    echo "Looking for installed deployments/patches backup/deployment files"
    echo "to remove.  This will not affect the behavior of your server.  The"
    echo "files that are cleaned up are either:"
    echo
    echo "  1) STAGING files that are only needed for the duration of the "
    echo "     deployment (these are found in the deploy/ directory and are "
    echo "     created whenever kDeploy.sh is run)"
    echo "  2) BACKUP files.  Whenever a deployment is installed any file that"
    echo "     is overwritten is first backed up to file.<ID>.  Over time this"
    echo "     can amount to a lot of extra files that are not needed."
    echo
 
    echo "Would you like to continue? (Y/N/M) :"
    echo "  [Y] to continue"
    echo "  [N] to cancel"
    echo "  [M] to list the files that would have been deleted."
    echo "      (files will NOT be deleted)"
    read CLN_CONT
 
    # if NO, then don't
    if [ "$CLN_CONT" = "N" -o "$CLN_CONT" = "n" ]; then
        echo
        echo "Cleanup canceled."
        exit 1;
    fi
 
    # if MAYBE, then
    if [ "$CLN_CONT" = "M" -o "$CLN_CONT" = "m" ]; then
        CLN_CONT="M"
    fi
 
    # patches!
    KINS_PATCHES_EXISTS=`$JAVA_HOME/bin/java $QUERYTOOL \
        "select count(*) \
        from USER_TABLES
        where TABLE_NAME='KINS_PATCHES'" \
        $KNTA_HOME`
    KINS_PATCHES_EXISTS=`Winstrip $KINS_PATCHES_EXISTS`    
 
    if [ "$KINS_PATCHES_EXISTS" != "0" ]; then
        CLN_PATCH_LIST=`$JAVA_HOME/bin/java $QUERYTOOL \
            "select distinct VERSION||'/'||PATCH_NUMBER 
            from KINS_PATCHES" \
            $KNTA_HOME`
    fi
 
    # get the list of deployments (no table check needed)
    CLN_DEPLOY_LIST=`$JAVA_HOME/bin/java $QUERYTOOL \
            "select distinct VERSION||'/'||DEPLOYMENT_ID 
            from KINS_DEPLOYMENTS" \
            $KNTA_HOME`
 
 
    echo "Getting a list of files on the server (this could take a few minutes)"
    CLN_FILE_LIST=$KNTA_HOME/logs/clean_filelist.$$
    Find $KNTA_HOME 1> $CLN_FILE_LIST 2>&1
 
    for i in $CLN_PATCH_LIST; do
          CleanupFiles $i patches $CLN_FILE_LIST
    done
    for i in $CLN_DEPLOY_LIST; do
          CleanupFiles $i deploy $CLN_FILE_LIST
    done
 
    \rm -f $CLN_FILE_LIST
 
    echo
    echo "Complete."
 
    exit;    
}
 
###############################################################################
 
## if this script is being called from another via . kDeploy.sh, don't 
## continue
necho $0 | grep kDeploy.sh 1> /dev/null 2>&1
 
if [ "$?" = "0" ]; then
 
sourceVariables
 
#
# Look to see if there is a new kDeploy.sh file (kDeploy.sh.new).  If there is,
# ask the user to rename the file.  Shell scripts don't like to be overwritten
# while they are running
#
if [ -f "kDeploy.sh.new" ]; then
    echo
    echo "NOTE: A previous patch installation has installed a new version"
    echo "      of kDeploy.sh.  Please rename the file kDeploy.sh.new to"
    echo "      kDeploy.sh before installing more patches/solutions."
    exit;
fi
 
#
# parse the command line options here
#
while [ "x$1" != "x" ]; do
  #
  # look to see if the value is a valid command line switch
  #
  case "$1" in
    "-h") grep "^#h" $0 | sed -e 's/^..//';  exit 0;;
    "-Q") shift; CL_PARAM_FILE=$1;          shift;;
    "-i") shift; DEPLOY_ID=$1;              shift;;
    "-k") shift; PASSWORD=$1;               shift;;
    "-u") shift; kintana_user=$1;           shift;;
    "-p") shift; kintana_pass=$1;           shift;;
    "-X")        DO_NOT_EXTRACT=1;          shift;;
    "-B")        DO_NOT_BACKUP=1;           shift;;
    "-f")        FORCE_INSTALL=1;           shift;;
    "-l")        LIST_PATCHES_ONLY=1;       shift;;
    "-D") shift; DEPLOYMENT_HOME=$1;        shift;;
    "-S")        SKIPKDEPLOYCHECK=1;        shift;;
 
 
    "-best-practices")  INSTALL_BEST_PRACTICES=1;  shift;;
    "-skip")             shift; SKIP_PHASE=$1;      shift;;
    "-tidy")             CLEANUP_PATCHES=1;         shift;;
    "-lang") shift;      ORIG_LANG=$1;              shift;;
 
    *) errorMessage "$1 is not a valid command-line argument.";;
  esac
done
 
# General JAVA checks.  Need to make sure that everything we need is here.
checkJavaHome;
checkForJar;
 
# Determine where to look for deployment files
findDeploymentHome;
 
# We cannot do any checks until we get the PASSWORD, and make sure that
# it is correct
if [ "$PASSWORD" = "" ]; then
    sqlmGetPassword
fi
 
# get the version from the database -- we are going to need it
getDatabaseVersion
 
# get the list of patches installed on this instance.  This will be needed
# in several places
get_patch_list
 
#
# 
if [ "$CLEANUP_PATCHES" = "1" ]; then
    Cleanup
fi
 
#
# Install the Best Practice Content!
if [ "$INSTALL_BEST_PRACTICES" = "1" ]; then
    installBestPractices;
fi
 
#
# Install the Language Pack!
if [ "$ORIG_LANG" != "" ]; then
    MAIN_LP_DIR="$KNTA_HOME/work"
 
    if [ "$ORIG_LANG" != "pt_BR" ]; then
        if [ "$_ECHO_TYPE" = "1" ]; then
            ORIG_LANG=`echo -n $ORIG_LANG | tr A-Z a-z`
        else
            ORIG_LANG=`echo $ORIG_LANG | tr A-Z a-z`
        fi
    fi        
 
    # Handle special gib case
    if [ "$ORIG_LANG" = "gib" ]; then
        LANG="ja"    
        uc_LANG="jp"
    else
        LANG=$ORIG_LANG
        uc_LANG=$LANG
    fi
 
    # ACTUAL BUNDLE NAMES ARE LIKE - ITG-700-LP-<lang>.jar
    LP_FILE="$MAIN_LP_DIR/ITG-$VERSION-LP-$LANG.jar"
    if [ ! -f "$LP_FILE" ]; then
        errorMessage "The language pack for $LANG is not available in $MAIN_LP_DIR" 
    fi
    install_LP $LP_FILE $LANG;
fi
 
# if nothing is specified, look for a list of patches
if [ "$DEPLOY_ID" = "" -a "$LIST_PATCHES_ONLY" != "1" ]; then
    chooseDeployment
fi
 
#
#  For Re-bundle checking expect "_" follow by "R1"
#
#  Now we are stripping "_R<version>" from DEPLOY_ID
#
 
if [ "$_ECHO_TYPE" = "1" ]; then
    EXTENDED_VERSION=`echo -n $DEPLOY_ID | awk 'BEGIN{FS="_"}{print $2}'`
    DEPLOY_ID=`echo -n $DEPLOY_ID | awk 'BEGIN{FS="_"}{print $1}'`
else
    EXTENDED_VERSION=`echo $DEPLOY_ID | awk 'BEGIN{FS="_"}{print $2}'`
    DEPLOY_ID=`echo $DEPLOY_ID | awk 'BEGIN{FS="_"}{print $1}'`
fi
 
# Get log location info 
loginfo
 
#
# Make sure that the patch to be applied exists.
# 
#
if [ "$EXTENDED_VERSION" != "" ]; then
   PATCHJAR=$DEPLOYMENT_HOME/$DEPLOY_PREFIX-$VERSION-$DEPLOY_ID"_"$EXTENDED_VERSION.jar
else
   PATCHJAR=$DEPLOYMENT_HOME/$DEPLOY_PREFIX-$VERSION-$DEPLOY_ID.jar
fi
 
PATCHHOME=$KNTA_HOME/$WORK_DIR/$VERSION/$DEPLOY_ID
 
if [ ! -f "$PATCHJAR" -a "$LIST_PATCHES_ONLY" != "1" ]; then
  errorMessage "$PATCHJAR does not exist." \
               "Patch cannot be applied."
fi
 
# If the user just wants a list of patches, print it out here and exist.  This
# is the -l option
if [ "$LIST_PATCHES_ONLY" = "1" ]; then
  patchReport;
  exit 0;
fi
 
# If the patch exists, extract it -- we need information from it.  Relevant 
# patch information is contained in $INFOFILE.  Only extract if the user
# permits it
cd ..
mkdir -p $WORK_DIR/$VERSION
 
if [ "$DO_NOT_EXTRACT" != "1" ]; then
  echo "Extracting patch files"
  if [ -d $PATCHHOME ]; then
    \rm -rf $PATCHHOME
  fi
  $JAR xf $PATCHJAR 1> $LOGS/extract.$$.log 2<&1
fi
 
if [ "$?" != "0" ]; then
  errorMessage "Could not extract jar file."
fi
 
if [ -f "$PATCHHOME/$INFOFILE" ]; then
  . $PATCHHOME/$INFOFILE
else
  errorMessage "The $INFOFILE file could not be found.  The patch" \
               "file was not properly extracted."
fi
 
# Check to see if there is a new version of kDeploy.sh shipped with the bundle.
if [ "$SKIPKDEPLOYCHECK" != "1" ]; then
    checkForNewDeployScript
fi
 
# print out intro if it exists
if [ -f "$PATCHHOME/$INTROFILE" ]; then
    . $PATCHHOME/$INTROFILE
fi
 
 
# deployment run in phases.  The phases are listed in the variable $PHASES.  
# check to make sure that each PHASE is accounted for.
if [ "$PHASES" != "" ]; then
    echo "Checking deployment phases"
 
    for phase in $PHASES; do
        # standard phases begin with DPL_
        necho "$phase" | grep "^DPL_" 1> /dev/null 2>&1
 
        if [ "$?" != "0" ]; then
            if [ ! -f "$PATCHHOME/$phase.sh" ]; then
                errorMessage "Phase sanity check failed for $phase."
            fi
        fi
    done
else
    #
    PHASES="DPL_FILESYSTEM DPL_DATABASE"
fi
 
# (1) check to see if the patch is already installed and...
# (2) make sure that the dependent patches are installed as well and finally...
# (3) exit if any of the incompatible deployments are installed
# (4) is the dependent file system version what it needs to be?
is_current_patch_installed
is_patch_dependency_installed
is_patch_compatible
 
if [ "$DEPENDS_ON_VERSION" != "" ]; then
  checkFileSystemVersion
fi
 
# the server cannot be running, unless the user specifies that it is okay
isServerRunning
 
# Patches MAY require SYSTEM access -- if $INFOFILE says so.  
if [ "$REQUIRES_SYSTEM_ACCESS" = "1" ]; then
  echo 
  promptFor "Please enter the System-Level database user:" "echo" "SYSTEM_USER"
  promptFor "Please enter the password for $SYSTEM_USER:" "-echo" "SYSTEM_PASS"
fi
 
# Do we need to import content?  If so let's ask.  We need to specify this 
# in a variable because the files will not exist on the file system when 
# we are here.
if [ "$CONTENT_TO_IMPORT" = "1" ]; then
    getKintanaLogin
fi
 
# remove the previous patches (classes/com directory).  THIS IS CONTROLLED BY
# $INFOFILE
removePrevPatches
 
if [ "$CL_PARAM_FILE" != "" ]; then
    if [ -f "$CL_PARAM_FILE" ]; then
        echo "Running $CL_PARAM_FILE..."
        . $CL_PARAM_FILE
    fi
fi
 
# Get thet tablespaces that are needed
getIndexTablespace
getClobTablespace
 
#
# Run the PHASES
#
for phase in $PHASES; do
    # standard phases begin with DPL_
    if [ "$phase" != "$SKIP_PHASE" ]; then
        necho "$phase" | grep "^DPL_" 1> /dev/null 2>&1
 
        if [ "$?" = "0" ]; then
            $phase
        else
            . $PATCHHOME/$phase.sh
        fi
    fi
done;
 
echo "phases complete."
 
# update the client version.  THIS IS CONTROLLED BY $INFOFILE
update_client_version
 
# update the patch list in the database
update_patch_list_with_current
 
# done
echo 
echo "Deployment $DEPLOY_ID has been successfully installed."
 
# this is the END of the KPATCH_API_ONLY if statement
fi

********************End of Script************************

I am getting the following errors:
Code:
/kDeploy.sh: line 45 :syntax error near unexpected token '{

Could anyone let me know what is causing the error and how can it be resolved.

Any kind of help would be much appreciated.

Cheers,
MandyR
Moderator's Comments:
Mod Comment Please use code tags, instead of formatting ~1700 lines of code as Courier New seperately

Last edited by pludi; 05-14-2010 at 05:53 AM..
# 2  
Old 05-14-2010
Change the first line to:

Code:
#!/bin/sh -xv

Run the script and post the entire output.
# 3  
Old 05-14-2010
Quick scan reveals a couple of dubious lines containing {} .


Code:
is_patch_compatible() { DEP_INCOMPAT=

Might be ok, might be not.


Code:
getKintanaLogin(){
    validuser=0

Space missing between () and { .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Syntax error near unexpected token `('

detect_mouse_mvt.sh /home/andy/bin/detect_mouse_mvt.sh: line 4: syntax error near unexpected token `(' /home/andy/bin/detect_mouse_mvt.sh: line 4: `fh = file('/dev/input/mice')' #!/bin/bash # # fh = file('/dev/input/mice') while True: fh.read(3) print 'Mouse... (15 Replies)
Discussion started by: drew77
15 Replies

2. UNIX for Beginners Questions & Answers

Syntax error near unexpected token

Dears, While executing the below script im getting the error at line 30. Please let me know what changes to be done to fix this. test.sh: line 30: syntax error near unexpected token `done' test.sh: line 30: ` done ' #!/bin/sh # Rev. PA1 # author: eillops # date: 26-04-2018 # #... (1 Reply)
Discussion started by: Kamesh G
1 Replies

3. How to Post in the The UNIX and Linux Forums

Syntax error near unexpected token `('

I have 2 files like a.txt and b.txt and the content is as below cat a.txt 810750125 117780 /BSCSQAT4A/bscsqat4a/lib/jar/wclt_common.jar 1803152428 13300 /BSCSQAT4A/bscsqat4a/lib/jar/WFMSSupportTool.jar 2663502779 67049 /BSCSQAT4A/bscsqat4a/lib/jar/wma.jar 687942896 665272... (1 Reply)
Discussion started by: ranabhavish
1 Replies

4. Shell Programming and Scripting

Syntax error near unexpected token

Hi all, I have a simple script that doesn't work somehow. I can't seem to be spotting the cause of the malfunction. count=$((1)) for item in `cat test1.txt` printf %s `sed -n $((count))p test2.txt` > test3.txt count=$((count+1)) do something done I get ; ./why.sh: line 3:... (14 Replies)
Discussion started by: y33t
14 Replies

5. Shell Programming and Scripting

Syntax error near unexpected token '('

I tried to execute the code but I got this error ./Array.c: line 9: syntax error near unexpected token '(' ./Array.c: line 9: ' nvals = get_data(a,MAXARRAY);' and #include<stdio.h> #define MAXARRAY 1000 main() { int a, nvals; nvals =... (7 Replies)
Discussion started by: sgradywhite
7 Replies

6. Shell Programming and Scripting

Syntax error near unexpected token `else'

Hi, I am trying to read the session log through script. But it keeps showing me some error near. I have tried everything. Even tried converting the script using sed command to remove the hidden characters(\r).But nothing seems to be working.Below is the script : #!/bin/bash cd... (6 Replies)
Discussion started by: Aryan12345
6 Replies

7. Shell Programming and Scripting

Syntax error near unexpected token `('

What do I do here? #!/bin/bash payload=-1 AND 1=IF(21,BENCHMARK(5000000,MD5(CHAR(115,113,108,109,97,112))),0)# hash=`echo -n $payload md5sum tr -d 'n' sed 'ss-sg' md5sum tr -d 'n' sed 'ss-sg'` curl --data cs2=chronopay&cs1=$payload&cs3=$hash&transaction_type=rebill... (2 Replies)
Discussion started by: iiiiiiiiiii
2 Replies

8. Shell Programming and Scripting

syntax error near unexpected token `='

Hi all, This is a script which converts hex to bin. However am finding an error while executing syntax error near unexpected token `=' `($hexfile, $binfile) = @ARGV;' I am running using ./fil.pl <hexfile> <binfile> ################################################### # # this script... (3 Replies)
Discussion started by: jaango123
3 Replies

9. Shell Programming and Scripting

Syntax error near unexpected token `('

Guys , This is an output of my script errored out for "Syntax error near unexpected token `(' " Can someone tell me whats wrong with my script. Below is my original script pasted. #!/bin/bash Script Creation Date 01/21/2010 Author baraghun ... (7 Replies)
Discussion started by: raghunsi
7 Replies

10. Shell Programming and Scripting

sh syntax error unexpected token done

I'm getting the following error: line 21: syntax error near unexpected token `done` line 21: `done` and I haven't been able to figure out why. Here is my code #!/bin/sh if ; then echo 'Usage: rename getexp/replStr ' exit 0 fi arg = $1 shift while ; do (5 Replies)
Discussion started by: NullPointer
5 Replies
Login or Register to Ask a Question