dinsdag 17 november 2015

eBS R11/R12 Installation Host Script Library



Library

On installation of eBS customizations you usually create a driver to install the software. The following library makes the installation easier by using a library for installation.


#!/bin/ksh
##########################################################################
# (c) 2015 Your company
##########################################################################
#
# FILENAME     : XXX_INSTALL.LIB
# DESCRIPTION  : Libraries for shell functions for install scripts
# USAGE        : This file must be sourced into the installation driver
#                script; all functions are SHARED and hence can be
#                maintained in a single location: this library.
# NOTE         : This shellscript contains a SMALL executable section
#                for initialization purposes.
#                place this file in: $XXX_TOP/install/driver/
#
# PARAMETERS
# ==========
# $1 - Mandatory base dir for logging --> ${1}/log
# $2 - Mandatory filename-prefix for logging
# $3 - Mandatory minimum library revision number
#
##########################################################################
# Define GLOBAL variables
_INSTALL_DATE=`date +%Y%m%d_%H%M%S`
_REVISION=$(echo '$Revision: 115 $' | sed '/^/s/[^0-9]//g')
LIBRARY_REVISION=${_REVISION:-0}
LIBRARY_NAME=$(basename $0)
LIBRARY_ERROR_COUNT=0

# GLOBALS TO BE INHERITED
# APPS_USER/APPS_PASS/XXX_USER/XXX_PASS
#

# Define configuration variables
FNDLOAD_CONFIG1=$FND_TOP/patch/115/import
FNDLOAD_CONFIG2=$FND_TOP/admin/import
XDOLOAD_CONFIG=$XDO_TOP/patch/115/import
##################################################################
# START-LIBRARY-FUNCTIONS
##################################################################
# -----------------------------------------------------------------
# Function   : verify_invocation
# Purpose    : Check script is invoked with correct parameters
#              and the library meets the minimum revision requirements
# Parameters : All invocation parameters to this script are passed
# -----------------------------------------------------------------
verify_invocation()
{
  if [ $# -ne 3 ]; then
    echo
    echo "Usage ${0} CUSTOM_TOP logfilename-include min-library-revision"
    exit 1
  fi
  if [ $LIBRARY_REVISION -lt $3 ]; then
    echo "Version of LIBRARY ($LIBRARY_REVISION) must be >= $3"
    exit 2
  fi
}
# -----------------------------------------------------------------
# Function   : init_logging
# Purpose    : Initialize logging, create logfilename
# Parameters : $1 = BASEDIR for installation
#              $2 = name to include in logfilename
# -----------------------------------------------------------------
init_logging()
{
  if [ -n $1 ]; then
    LOGDIR=${1}/log
    if [ ! -d ${LOGDIR} ]; then
      mkdir ${LOGDIR}
    fi
    LOGFILE=${LOGDIR}/${2}_${_INSTALL_DATE}.log
  fi
}

# -----------------------------------------------------------------
# Function   : out
# Purpose    : Write to stdout and tee to logfile; should be used
#              for almost all output
# Parameters : $* = messages to output
# -----------------------------------------------------------------
out()
{
  echo "$*" | tee -a ${LOGFILE}
}

# -----------------------------------------------------------------
# Function   : do_sql_file
# Purpose    : Execute sql script using sqlplus
# Parameters :
# ${1}: The un/pw@connect_string to use when connecting (default "/ as sysdba")
# ${2}: The SQL script to execute.
# ${3}: database (optioneel)
# Results    :
#              0 ok
#              >0 error
# -----------------------------------------------------------------
do_sql_file()
{
#
  do_banner "Starting sqlplus script ${2}"

  out "Starting sqlplus script ${2} at `date +%d%m%Y_%H%M%S`"

  p_un_pw_connect=${1}
  p_SQL=${2}
  OUT_FILE=/tmp/$$.do_SQL.lst

  # temporary file CREATION, FILENAME en parameters isoleren, nieuwe p_sql
  # maken en exit toevoegen
  TMP_IN_FILE=/tmp/$$.sql
  #
  echo $p_SQL > /tmp/$$.argumenten
  #
  while read sqlfile parameters
  do
     SQL_FILE=$sqlfile
     PARAMETERS=$parameters
  done < /tmp/$$.argumenten
  #
  rm /tmp/$$.argumenten
  #
  echo "set serveroutput on size 300000"       > ${TMP_IN_FILE}
  echo "       "                              >> ${TMP_IN_FILE}
  cat  ${SQL_FILE}                            >> ${TMP_IN_FILE}
  echo "       "                              >> ${TMP_IN_FILE}
  echo "exit"                                 >> ${TMP_IN_FILE}
  echo ""                                     >> ${TMP_IN_FILE}
  #
  # temporary file opstarten
  ${ORACLE_HOME}/bin/sqlplus  -s $p_un_pw_connect @$TMP_IN_FILE ${PARAMETERS} | tee -a $LOGFILE
  l_rc=${?}
  [[ ${l_rc} -ne 0 ]] && echo "SQL statement \"${p_SQL}\" returned error code ${l_rc} instead of 0."
  return ${l_rc}

  # temporary file
  rm ${TMP_IN_FILE}

  ENDTIME=$(date +%s)
   let TIMEDIFF=$ENDTIME-$STARTTIME
   out "Finished sqlplus script ${2} at `date +%d%m%Y_%H%M%S`"
   out "Executed in $TIMEDIFF seconds"

}

# -----------------------------------------------------------------
# Function   : do_banner
# Purpose    : Generate banner to stdout & logfile
# Parameters : $@ = banner text
# -----------------------------------------------------------------
do_banner()
{
 out ""
 out " ==================================================="
 out " " "$@"
 out " ==================================================="
}
do_error()
{
  let LIBRARY_ERROR_COUNT=LIBRARY_ERROR_COUNT+1
  do_banner " **** ERROR COUNT = ${LIBRARY_ERROR_COUNT} ****"
}

# -----------------------------------------------------------------
# Function   : determine_db_params
# Purpose    : Determine database parameters based on current
#              TWO_TASK variable; useful for Java loaders
# -----------------------------------------------------------------
determine_db_params()
{
 DB_PORT=$(tnsping ${TWO_TASK} | grep PORT \
   | sed 's/^.*PORT=//g' | sed 's/).*//g')
 DB_HOST=$(tnsping ${TWO_TASK} | grep HOST \
   | sed 's/^.*HOST=//g' | sed 's/).*//g')
 _SID=$(tnsping ${TWO_TASK} | grep SID \
   | sed 's/^.*SID=//g' | sed 's/).*//g')
 DB_SID=${_SID:=$TWO_TASK}
}

# -----------------------------------------------------------------
# Function   : wfload
# Purpose    : Upload workflow process definitions to target DB
# Parameters : $1 - workflow file to be uploaded
#              $2 - mode (should be specified as UPLOAD OR UPGRADE)
#              $3 - wf access level [default: 100]
# -----------------------------------------------------------------
wfload()
{
  do_banner "Uploading Workflow"
  # bail out if incorrect number of parameters supplied on command line
  if [[ $# -lt 1 || $# -gt 3 ]]; then
    do_error "Incorrect number of parameters in invocation of wfload()"
    out "wfload $*"
    return
  fi

  save_wf_access_level=$WF_ACCESS_LEVEL
  case $# in
    3) export WF_ACCESS_LEVEL=$3 # need to fall thru !
       WFLOAD_OPTION=$2
       ;;
    2) WFLOAD_OPTION=$2
       export WF_ACCESS_LEVEL=100
       ;;
    1) export WF_ACCESS_LEVEL=100
       WFLOAD_OPTION=DOWNLOAD
       ;;
  esac
  out "WFLOAD mode: $WFLOAD_OPTION (Access Level=$WF_ACCESS_LEVEL) File=$1"

  ( WFLOAD $APPS_USER/$APPS_PASS 0 Y $WFLOAD_OPTION $1 2>&1) \
    1> wfload.$$
  WFLOAD_LOGFILE=`grep -i log wfload.$$ | awk -F: '{print $2}' | sed 's/ *//'`
  out Command output of upload workflow $1
  cat wfload.$$ | tee -a $LOGFILE
  out Logfile of upload workflow $1
  cat $WFLOAD_LOGFILE >> $LOGFILE

  # cleanup after each use
  rm $WFLOAD_LOGFILE 2>&1 1>/dev/null
  rm wfload.$$
  export WF_ACCESS_LEVEL=$save_wf_access_level
}

##################################################################
# Upload AOL entity to the database
# Usage: fndload loader_config_file.lct loader_data_file.ldt
# Note: loader config is a relative filename, loader data is an absolute name
##################################################################
fndload()
{
  do_banner "FNDLOAD: Uploading AOL/application entity definitions"

  if [ -r $FNDLOAD_CONFIG1/$1 ]
  then LOADER_CONFIG=$FNDLOAD_CONFIG1/$1
  elif [ -r $FNDLOAD_CONFIG2/$1 ]
  then
    LOADER_CONFIG=$FNDLOAD_CONFIG2/$1
  elif [ -r $XDOLOAD_CONFIG/$1 ]
  then
    LOADER_CONFIG=$XDOLOAD_CONFIG/$1
  fi

  echo Configuratie file: $LOADER_CONFIG | tee -a $LOGFILE
  echo Loader file      : $2             | tee -a $LOGFILE

  ( FNDLOAD $APPS_USER/$APPS_PASS 0 Y UPLOAD $LOADER_CONFIG $2 \
      - UPLOAD_MODE=REPLACE CUSTOM_MODE=FORCE 2>&1) 1> fndload.$$
  FNDLOAD_LOGFILE=`grep -i log fndload.$$ | awk -F: '{print $2}' | sed 's/ *//'`
  cat fndload.$$ | tee -a $LOGFILE

  # cleanup after each usage
  cat $FNDLOAD_LOGFILE >> $LOGFILE
  rm $FNDLOAD_LOGFILE 2>&1 1>/dev/null
  rm fndload.$$
}

# -----------------------------------------------------------------
# Function   : complib
# Purpose    : Compile forms library (PLL) into runtime file (PLX)
# Parameters : $1 = name of form module (excluding extension)
# Results    : .plx file will be in same directory as .pll file
# -----------------------------------------------------------------
complib()
{
  do_banner "Compiling library ${1}"

  # initialize environment
  SAVE_FORMS_PATH=$FORMS_PATH
  FORMS_PATH=${SAVE_FORMS_PATH}:${AU_TOP}/resource
  out "Compiling library ${1}"
  STARTTIME=$(date +%s)

  ( frmcmp_batch Module=${1} Userid=$APPS_USER/$APPS_PASS \
    Module_Type=LIBRARY Compile_All=Yes 2>&1) | tee -a $LOGFILE

  # finalize: report and reset environment
  ENDTIME=$(date +%s)
  let TIMEDIFF=$ENDTIME-$STARTTIME
  out "Finished library ${1} at `date +%d%m%Y_%H%M%S`"
  out "Compiled in $TIMEDIFF seconds"
  FORMS_PATH=$SAVE_FORMS_PATH
}
# -----------------------------------------------------------------
# Function   : compfrm
# Purpose    : Compile form definition into runtime file
# Parameters : $1 = name of form module (excluding extension, including $XXX_TOP/forms/NL or US)
#              $2 = language of form module
# Results    : .fmx file will be in same directory as .fmb file
# -----------------------------------------------------------------
compfrm()
{
  do_banner "Compiling form ${2}/${1}"

  # save current forms path and append correct language directory
  SAVE_FORMS_PATH=$FORMS_PATH
  FORMS_PATH=${SAVE_FORMS_PATH}:${AU_TOP}/${2}

  out "Compiling form ${1} language $2 at `date +%d%m%Y_%H%M%S`"

  # cd added for compilation from correct directorie
  cd $AU_TOP/forms/$2

  STARTTIME=$(date +%s)
  ( frmcmp_batch Module=${1} Userid=$APPS_USER/$APPS_PASS \
    Module_Type=FORM Compile_All=Yes 2>&1) | tee -a $LOGFILE

  # finalize: report and reset environment
  ENDTIME=$(date +%s)
  let TIMEDIFF=$ENDTIME-$STARTTIME
  out "Finished form ${1} language ${2} at `date +%d%m%Y_%H%M%S`"
  out "Compiled in $TIMEDIFF seconds"
  FORMS_PATH=$SAVE_FORMS_PATH
 
  # back to initial directorie
  cd -
}

# -----------------------------------------------------------------
# Function   : xdoload
# Purpose    : Loader for XML Publisher (Data) Templates
# Parameters : $1 = Template filename
#              $2 = Lob Type  (TEMPLATE/DATA_TEMPLATE/BURSTING_FILE/XML_SAMPLE)
#              $3 = Template Application Short Name (Owning application)
#              $4 = Template language
#              $5 = Template territory
#              $6 = Template file type (PDF, RTF, XSL-FO, ...)
#              $7 = Lob code equal to data definition name
# Results    : XML Publisher template is uploaded in DB
#              ** NOTE: XMLP also requires UPLOADING LDT files
#                       for the complete definition !
# -----------------------------------------------------------------
xdoload()
{
  do_banner "Uploading XML Publisher Template"
  # determine_db_params
  out "Filename           : ${1}"
  out "Lob-type           : ${2}"
  out "Template owner     : ${3}"
  out "Language           : ${4}"
  out "Territory          : ${5}"
  out "Template file type : ${6}"
  out "Lob-Code           : ${7}"
  out "Destination-host   : ${DB_HOST}"
  out "Destination-port   : ${DB_PORT}"
  out "Destination-SID    : ${DB_SID}"
  XDO_LOGFILE=XDO_${1}_${3}_${4}.log
  STARTTIME=$(date +%s)

  java oracle.apps.xdo.oa.util.XDOLoader UPLOAD \
  -DB_USERNAME ${APPS_USER} \
  -DB_PASSWORD ${APPS_PASS} \
  -JDBC_CONNECTION ${DB_HOST}:${DB_PORT}:${DB_SID} \
  -LOB_CODE ${7} \
  -LOB_TYPE ${2} \
  -APPS_SHORT_NAME ${3} \
  -LANGUAGE ${4} \
  -TERRITORY ${5} \
  -XDO_FILE_TYPE ${6} \
  -NLS_LANG ${NLS_LANG} \
  -FILE_NAME ${1} \
  -CUSTOM_MODE FORCE \
  -LOGFILE ${XDO_LOGFILE} | tee -a ${LOGFILE}

  ENDTIME=$(date +%s)
  let TIMEDIFF=$ENDTIME-$STARTTIME
  ( cat ${XDO_LOGFILE} | tee -a ${LOGFILE} ) 2>/dev/null
  out "Uploaded template ${1} in ${TIMEDIFF} seconds"
  rm ${XDO_LOGFILE} 2>/dev/null
}

# -----------------------------------------------------------------
# Function   : xdodownload
# Purpose    : DOWNLoader for XML Publisher (Data) Templates
# Parameters : $1 = Lob Type  (TEMPLATE/DATA_TEMPLATE/BURSTING_FILE/XML_SAMPLE)
#              $2 = Template Application Short Name (Owning application)
#              $3 = Template language
#              $4 = Template territory
# Results    : XML Publisher template is downloaded from DB
# -----------------------------------------------------------------
xdodownload()
{
  do_banner "Downloading XML Publisher Templates"
  # determine_db_params
  out "Lob-type           : ${1}"
  out "Template owner     : ${2}"
  out "Language           : ${3}"
  out "Territory          : ${4}"
  out "Destination-host   : ${DB_HOST}"
  out "Destination-port   : ${DB_PORT}"
  out "Destination-SID    : ${DB_SID}"
  XDO_LOGFILE=XDO_${1}_${2}.log
  STARTTIME=$(date +%s)

  java oracle.apps.xdo.oa.util.XDOLoader DOWNLOAD \
  -DB_USERNAME ${APPS_USER} \
  -DB_PASSWORD ${APPS_PASS} \
  -JDBC_CONNECTION ${DB_HOST}:${DB_PORT}:${DB_SID} \
  -LOB_TYPE ${1} \
  -APPS_SHORT_NAME ${2} \
  -LANGUAGE ${3} \
  -TERRITORY ${4} \
  -CUSTOM_MODE FORCE \
  -LOGFILE ${XDO_LOGFILE} | tee -a ${LOGFILE}

  ENDTIME=$(date +%s)
  let TIMEDIFF=$ENDTIME-$STARTTIME
  ( cat ${XDO_LOGFILE} | tee -a ${LOGFILE} ) 2>/dev/null
  out "Downloaded template ${1} in ${TIMEDIFF} seconds"
  rm ${XDO_LOGFILE} 2>/dev/null
}

# -----------------------------------------------------------------
# Function   : generate_msg
# Purpose    : Generate message runtime file for application
# Parameters : $1 = Application Short name
#              $2 = Language
# -----------------------------------------------------------------
generate_msg()
{
  do_banner "Generating message file for ${1}"
  ( FNDMDGEN ${APPS_USER}/${APPS_PASS} 0 Y \
    ${2} ${1} DB_TO_RUNTIME 2>&1) 1> fndmdgen.$$
  # extract name of logfile from loader's output
  FNDMDGEN_LOGFILE=`grep -i log fndmdgen.$$ | awk -F: '{print $2}' | sed 's/ *//'`
  cat fndmdgen.$$ | tee -a ${LOGFILE}

  # cleanup after each usage
  cat ${FNDMDGEN_LOGFILE} >> ${LOGFILE}
  rm ${FNDMDGEN_LOGFILE} 2>&1 1>/dev/null
  rm fndmdgen.$$ 2>/dev/null
}

# -----------------------------------------------------------------
# Function   : oaf_substitutions
# Purpose    : Loader for OAF BC4J substitutions
# Parameters : $1 = JPX-filename (full path)
# -----------------------------------------------------------------
oaf_vo_substitutions()
{
  do_banner "Uploading OAF BC4J substitutions"
  determine_db_params
  out "Filename           : ${1}"
  out "Destination-host   : ${DB_HOST}"
  out "Destination-port   : ${DB_PORT}"
  out "Destination-SID    : ${DB_SID}"
  STARTTIME=$(date +%s)

  ( java oracle.jrad.tools.xml.importer.JPXImporter ${1} \
      -username ${APPS_USER} -password ${APPS_PASS} \
      -dbconnection ${DB_HOST}:${DB_PORT}:${DB_SID}  2>&1 ) | tee -a ${LOGFILE}

  ENDTIME=$(date +%s)
  let TIMEDIFF=$ENDTIME-$STARTTIME
  ( cat ${XDO_LOGFILE} | tee -a ${LOGFILE} ) 2>/dev/null
  out "Uploaded template ${1} in ${TIMEDIFF} seconds"
  rm ${XDO_LOGFILE} 2>/dev/null
}

# -----------------------------------------------------------------
# Function   : check_login
# Purpose    : Check that login credentials are valid
# Parameters : $1 = USERNAME
#              $2 = PASSWORD
# Returns 0 upon successful login, <>0 otherwise
# -----------------------------------------------------------------
check_login()
{
if (( $# != 3 ))
then
    DATABASE=$TWO_TASK
else
    DATABASE=${3}
fi
sqlplus -s /nolog <<EOFSQLPLUS >/dev/null 2>&1
  WHENEVER SQLERROR EXIT 1;
  CONNECT ${1}/${2}@${DATABASE};
  SELECT * FROM DUAL;
  EXIT;
EOFSQLPLUS
if [ $? -eq 0 ]; then
  out "Login credentials for ${1} are valid"
#  echo "Login credentials for ${1} are valid"
  return 0
else
  out "Login credentials for ${1} are *INVALID*"
#  echo "Login credentials for ${1} are *INVALID*"
  return 1
fi
}

# -----------------------------------------------------------------
# Function   : prompt_parameter
# Purpose    : Prompt user for parameter
# Parameters : $1 = Prompt
#              $2 = Return-variable name
#              $3 = (Optional) HIDE/NOHIDE (NOHIDE is default)
#              $4 = (Optional) Default value for return variable
# Prompt user for parameter, returning the value in the indicated
# variable. Optionally, the parameter value is HIDDEN during
# entry (e.g. for passwords)
# -----------------------------------------------------------------
prompt_parameter()
{
  print -n ${1}
  if [ ! -z "$4" ]; then
    print -n " [$4]: "
  else
    print -n ": "
  fi

  # Turn off echoing if required
  if [ "$3" == "HIDE" ]; then
    stty -echo
  else
    stty echo
  fi

  read PARAMETER_VALUE

  stty echo
  print ""
  eval export ${2}=${PARAMETER_VALUE:-$4}
}
##################################################################
# END-OF-LIBRARY
##################################################################

##################################################################
# START-OF-EXECUTABLE-SECTION
##################################################################
# Verify calling this LIBRARY: are the correct parameters passed ?
verify_invocation "$@"
# Initialize logging
init_logging ${1} ${2}

clear
out "Installation logged in ${LOGFILE}"


Installation driver

The installation driver itself will then be something like this including the library so you can use routines from the library itself.




#!/bin/ksh
##########################################################################
# (c) 2015 Your company
##########################################################################
#
# FILENAME         : xxx_{module}.sh
# AUTHOR           : {Author}
# DESCRIPTION       : Installation driver for {module}
#               
#                *NOTE* This version assumes an e-Business Suite 12.1.3
#                       or later
# DATE             : dd-mm-yyyy
# MODULE(S)        : XXPV
# USAGE            : Run the shellscript from the shell prompt after the
#                 environment setting have been sourced into the session
#
# PARAMETERS    : Are all prompted for
#
# CHANGE HISTORY
# ==============
#
# Date             Authors              Change reference/Description
# ------------------ -------------------- ---------------------------------------
# dd-mm-yyyy         {Author}             Initial Creation 
#                            
##########################################################################
# Define variables
INSTALL_DATE=`date +%Y%m%d_%H%M%S`
FNDLOAD_CONFIG1=$FND_TOP/patch/115/import
FNDLOAD_CONFIG2=$FND_TOP/install/import

# Edit variables below
ZIP_FILE=xxpv_{module}.zip
INSTALLATION_DIR=$XXX_TOP
CURRENTDIR=`pwd`
LOGFILE=$CURRENTDIR/XXX_{module}_${INSTALL_DATE}.log
CUSTOMIZATION_NAME={module name}
export CUSTOMIZATION_NAME

# LOAD LIBRARY INSTALLATION ROUTINES
. ${ INSTALLATION_DIR}/install/driver/XXX_INSTALL.LIB ${INSTALLATION_DIR} ${CUSTOMIZATION_NAME} 1


##################################################################
# Start of program
##################################################################
clear
echo "" > $LOGFILE                                    # empty logfile
do_banner "Start installation at `date`"
# prompt for all parameters

test -z "$APPS_USER"  && prompt_parameter "APPS Username" APPS_USER NOHIDE APPS
test -z "$APPS_PASS"  && prompt_parameter "APPS Password" APPS_PASS HIDE
test -z "$XXX_USER"  && prompt_parameter "Custom Username" XXX_USER NOHIDE
test -z "$XXX_PASS"  && prompt_parameter "Custom Password" XXX_PASS HIDE
check_login ${APPS_USER} ${APPS_PASS}
if [ $? -ne 0 ]; then
  out "Incorrect APPS credentials .. exiting"
  exit 1
fi
check_login ${XXX_USER} ${XXX_PASS}
if [ $? -ne 0 ]; then
  out "Incorrect Custom credentials .. exiting"
  exit 1
fi

if [ -f ${ZIP_FILE} ]
then
  echo 'Expanding' ${ZIP_FILE}
else
  echo 'No zip file '${ZIP_FILE}' present. Aborting installation.'
  exit 1
fi


unzip -oa ${ZIP_FILE} >> $LOGFILE

echo  >> $LOGFILE

echo "Installation" >> $LOGFILE


And finally start the actual installation from here.



Geen opmerkingen:

Een reactie posten

Opmerking: Alleen leden van deze blog kunnen een reactie posten.