#!/bin/sh # $Header: emll/bin/common /st_emll_10.3.5/3 2011/05/26 00:04:29 ckalivar Exp $ # # common # # Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. # # NAME # common - OCM software configuration # # DESCRIPTION # This script contains a set of common commands that can be included by other # OCM scripts # # NOTES / Conventions # Global variables which are used across functions within the module # should either be prededed by a 'G_' or be entirely in UPPER case. # Variables local to a function should be prefixed with strictly a '_'. # # MODIFIED (MM/DD/YY) # ckalivar 05/20/11 - add checkOracleConfigHomeOwner # fmorshed 04/29/11 - Revert use of stat! This utility is not on all # platforms (e.g. HP - UX). # fmorshed 04/22/11 - Add /usr/bin/stat # jsutton 04/22/11 - allow for root user, e.g. 11.2 grid infra # #-- # set restrictive file creation mask umask 077 # # Reset the locale to ENGLISH for command line operations. LC_ALL=C export LC_ALL # Constant declarations for exit values. SUCCESS=0 ERR_PREREQ_FAILURE=1 ERR_INVALID_ARG=2 ERR_INVALID_USAGE=3 ERR_LOCK_FAILURE=4 ERR_UNEXPECTED_FAILURE=11 ERR_LICENSE_DECLINED=12 # # Fail on command error # set -e # Define the paths for /usr/bin. These are used in subsequent path # specifications for native commands. _binDir=/bin _usrBinDir=/usr/bin _usrLocalBinDir=/usr/local/bin # Set the variables that map to explicit paths to prevent from trojan # horse type attacks and allow for more consistent installation experience # by eliminating the use of aliases. BC=${_usrBinDir}/bc BINMORE=${_binDir}/more CAT=${_binDir}/cat CHMOD=${_binDir}/chmod CP=${_binDir}/cp CRONTAB=${_usrBinDir}/crontab DATE=${_binDir}/date DIFF=${_usrBinDir}/diff DIRNAME=${_usrBinDir}/dirname ECHO=${_binDir}/echo FIND=${_usrBinDir}/find ID=${_usrBinDir}/id LS=${_binDir}/ls MKDIR=${_binDir}/mkdir MKDIRP="${_binDir}/mkdir -p" MV=${_binDir}/mv RM=${_binDir}/rm RMF="$RM -f" RMRF="$RM -rf" SED=${_binDir}/sed PWDD=${_binDir}/pwd STTY=${_binDir}/stty TOUCH=${_binDir}/touch TTY=${_usrBinDir}/tty TR=${_usrBinDir}/tr if [ -f ${_binDir}/cut ] then CUT=${_binDir}/cut elif [ -f ${_usrBinDir}/cut ] then CUT=${_usrBinDir}/cut fi if [ -f ${_binDir}/uname ] then UNAME=${_binDir}/uname elif [ -f ${_usrBinDir}/uname ] then UNAME=${_usrBinDir}/uname fi AWK=${_binDir}/awk PLATFORM=`$UNAME | $CUT -f1` if [ "$PLATFORM" = "SunOS" ] then if [ -f ${_binDir}/nawk ] then AWK=${_binDir}/nawk elif [ -f ${_usrBinDir}/nawk ] then AWK=${_usrBinDir}/nawk fi fi if [ -f ${_binDir}/egrep ] then EGREP=${_binDir}/egrep elif [ -f ${_usrBinDir}/egrep ] then EGREP=${_usrBinDir}/egrep fi LOCKFILE="" if [ -f ${_usrBinDir}/lockfile ] then LOCKFILE=${_usrBinDir}/lockfile elif [ -f ${_usrLocalBinDir}/lockfile ] then LOCKFILE=${_usrLocalBinDir}/lockfile fi if [ -f ${_usrBinDir}/printf ] then PRINTF=${_usrBinDir}/printf elif [ -f ${_binDir}/printf ] then PRINTF=${_binDir}/printf fi if [ -z "${CCR_INSTALL_DEBUG}" ] then VERBOSE= else VERBOSE="${_binDir}/sh -x" fi # Bug 5931631 - getopts issue with /bin/sh on SunOS # If SunOS, run this script with /usr/xpg4/bin/sh (if available) if [ $PLATFORM = "SunOS" ] then if [ -f /usr/xpg4/bin/sh ] then if [ -z "${_xpg4ShAvbl_setupCCR}" ] then _xpg4ShAvbl_setupCCR=1 export _xpg4ShAvbl_setupCCR /usr/xpg4/bin/sh $0 "$@" exit $? fi fi fi if [ $PLATFORM = "OSF1" ] then if [ -z "${BIN_SH}" ] then BIN_SH=xpg4 export BIN_SH $0 "$@" exit $? fi fi # Determine if this is a console device. set +e IS_CONSOLE=0 ${TTY} -s if [ $? -eq 0 ]; then IS_CONSOLE=1 fi set -e # Define of global static variable TRUE=1 FALSE=0 # G_ConfigurationRequest is used to indicate whether a configuration, or removal # of configuration is requested. Valid values are "", "config" or "deconfig". G_ConfigurationRequest="" # G_configurationCompleted is used to denote that a configuration request was # explicitly requested or implicitly made thru a new installation and the # setup of writeable trees was completed. Values are 0 for false and 1 for true. G_ConfigurationCompleted=$FALSE # G_OCMConfigured indicates that the OCM Home/OCM Configuration Home contains # configuration information. The valid values are 'undefined' prior to calls # to isOCMConfigured, and $TRUE or $FALSE otherwise G_OCMConfigured="undefined" # Indicates that this is a new install G_NewInstall=$FALSE # G_ORACLE_CONFIG_HOME_VAR defines a string that is used on CRON operations. # Default value is "". Changes for a pattern match whether the installation # supports a shared home config and ORACLE_CONFIG_HOME is set in the env. G_ORACLE_CONFIG_HOME_VAR="" # G_INIT_DISCONN_STATE defines a string that identifies the initial disconnect # state of the collector when a configuration or reconfiguration is being # performed G_INIT_DISCONN_STATE="false" #G_ADD_CRON is set by configInstance() for storing information that, is crontab #should b added or not. If yes it will be set to ture. G_ADD_CRON="false" #Determines whether the script has to deal with shared homes in the hosts directory G_SharedHomesSupported=1 ROOTCHAR=`$DIRNAME $0 | $CUT -b1` if [ "${ROOTCHAR}" != "/" -a -z "${PWD}" ] then $ECHO "The current shell is not supported for executing commands using relative paths." $ECHO "Either execute the command under the bash or ksh shells, or execute the " $ECHO "command using the absolute path." exit 1 fi # # Determine the absolute path for the CCR location. # CCR_BIN=`$DIRNAME $0 | $TR -s '/'` # First remove './'s in the beginning CCR_BIN=`$ECHO $CCR_BIN | $AWK '{ if (match($0,/^(\.\/)*/)){ sub(/^(\.\/)*/,"",$0) }; print $0; }'` # Next replace all '/./'s in between with '/' CCR_BIN=`$ECHO $CCR_BIN | $AWK '{ if (match($0,/\/(\.\/)+/)){ gsub(/\/(\.\/)+/,"/",$0) }; print $0;}'` # Lastly remove '/.' at the end CCR_BIN=`$ECHO $CCR_BIN | $AWK '{ if (match($0,/\/\.$/)){ sub(/\/\.$/,"",$0) }; print $0; }'` # Now convert to absolute path CCR_BIN=`$ECHO $CCR_BIN | $AWK -f ${CCR_BIN}/strip_path.awk PWD=$PWD` CCR_LIB=`$DIRNAME $CCR_BIN`/lib # Now extract the real variables that are needed. CCR_HOME=`$DIRNAME $CCR_BIN` ORACLE_HOME=`$DIRNAME $CCR_HOME` # # Determine if Shared Oracle Home support is available. This is determined # thru the new directory 'hosts' under the CCR_HOME. # determineSharedHomesSupported() { if [ -d "${CCR_HOME}/hosts" ]; then G_SharedHomesSupported=0 else G_SharedHomesSupported=1 fi } setHostName() { CCR_HOST_NAME=`hostname` export CCR_HOST_NAME } setOCMDirPaths() { if [ ${G_SharedHomesSupported} -eq 0 ] then # Check whether its a shared OCM install if [ -z "${ORACLE_CONFIG_HOME}" ] then CCR_CONFIG_HOME="${CCR_HOME}/hosts/${CCR_HOST_NAME}" elif [ -d "${ORACLE_CONFIG_HOME}" ] then set +e _isRelative=`$ECHO ${ORACLE_CONFIG_HOME} | $EGREP -c '^/'` if [ ${_isRelative} -eq 0 ] ; then $ECHO 'ORACLE_CONFIG_HOME refers to a relative path.' $ECHO 'Redefine ORACLE_CONFIG_HOME to refer to an absolute path, or' $ECHO 'unset it if the configuration state is in the ccr directory tree.' exit $ERR_PREREQ_FAILURE set -e else checkOracleConfigHomeOwnership $ORACLE_CONFIG_HOME ORACLE_CONFIG_HOME # strip any trailing dirsep ORACLE_CONFIG_HOME=`$ECHO ${ORACLE_CONFIG_HOME} | $SED -e 's/\/*$//'` CCR_CONFIG_HOME="${ORACLE_CONFIG_HOME}/ccr" fi else $ECHO 'ORACLE_CONFIG_HOME refers to a non-existent directory.' $ECHO 'Redefine ORACLE_CONFIG_HOME to refer to the correct location or' $ECHO 'unset it if the configuration state is in the ccr directory tree.' exit $ERR_PREREQ_FAILURE fi else CCR_CONFIG_HOME=${CCR_HOME} fi export CCR_CONFIG_HOME # sets the G_ORACLE_CONFIG_HOME_VAR to a value if this is a shared home config # and ORACLE_CONFIG_HOME is specified. if [ ${G_SharedHomesSupported} -eq 0 -a \ ! -z "${ORACLE_CONFIG_HOME}" ]; then G_ORACLE_CONFIG_HOME_VAR="ORACLE_CONFIG_HOME=${ORACLE_CONFIG_HOME} " fi # Default the temporary directory to /tmp for where temporary files are written. if [ -z "${CCR_TEMP}" ] then CCR_TEMP=/tmp export CCR_TEMP fi } checkOracleHomeOwnership() { _DIR=$1 _UID=`$ID | $CUT -d'=' -f2 | $CUT -d'(' -f1` _CCR_OWNER=`$LS -Llnd $_DIR |$AWK '{print $3}'` _HOME=$3 _HOME_OWNER=`$LS -Llnd $_HOME |$AWK '{print $3}'` if [ ${_UID} -ne ${_HOME_OWNER} ]; then # If OH owner is not running, only excuse: user should be ccr_owner and OH owner should be root if [ ${_UID} -ne ${_CCR_OWNER} -o ${_HOME_OWNER} -ne 0 ]; then echo "*****" echo "Only the $2 owner can install or configure the Oracle Configuration Manager in an" echo "$2 structure. The $2 (${_HOME}) is owned by the UID ${_HOME_OWNER}" echo "*****" exit $ERR_PREREQ_FAILURE fi fi } checkOracleConfigHomeOwnership() { _UID=`$ID | $CUT -d'=' -f2 | $CUT -d'(' -f1` _OCH=$1 _OCH_OWNER=`$LS -Llnd $_OCH |$AWK '{print $3}'` if [ ${_UID} -ne ${_OCH_OWNER} ]; then echo "*****" echo "Only the $2 owner can install or configure the Oracle Configuration Manager in an" echo "$2 structure. The $2 (${_OCH}) is owned by the UID ${_OCH_OWNER}" echo "*****" exit $ERR_PREREQ_FAILURE fi } checkIfDisconnected() { getProperty ccr.disconnected collector.properties G_INSTALL_DISCONN_STATE=${_returnData} } checkIfInteractive() { if [ -z "$PS1" ]; then _shellIsInteractive=$FALSE else _shellIsInteractive=$TRUE fi } #++ # # Extracts the Value for the property specified from the base configuration # file. Value returned in the variable _returnData # # The algorithm iterates thru all the files in precidence order, taking the # first one present. Order is: # # (1) $CCR_CONFIG_HOME/config # (2) $CCR_CONFIG_HOME/config/default # (3) $CCR_HOME/config # (4) $CCR_HOME/config/default # # Args: # property-name, i.e. ccr.disconnected # config-basename, i.e. ccr.properties or collector.properties # #-- getProperty() { _propertyName=$1 _propertyFile=$2 _returnData="" if [ -z "${_propertyFile}" -o -z "${_propertyName}" ]; then $ECHO "INTERNAL ERR (getProperty()) - Missing arguments" exit $ERR_UNEXPECTED_FAILURE fi if [ -f ${CCR_CONFIG_HOME}/config/${_propertyFile} ]; then _returnData=`$EGREP "^$_propertyName=" ${CCR_CONFIG_HOME}/config/${_propertyFile} | \ $SED -e "s/$_propertyName=\s*//"` fi # check alternate properties files if we come up empty, just in case if [ -z "${_returnData}" ] ; then if [ -f ${CCR_CONFIG_HOME}/config/default/${_propertyFile} ] ; then _returnData=`$EGREP "^$_propertyName=" ${CCR_CONFIG_HOME}/config/default/${_propertyFile} | \ $SED -e "s/$_propertyName=\s*//"` fi fi if [ -z "${_returnData}" ] ; then if [ -f ${CCR_HOME}/config/${_propertyFile} ] ; then _returnData=`$EGREP "^$_propertyName=" ${CCR_HOME}/config/${_propertyFile} | \ $SED -e "s/$_propertyName=\s*//"` fi fi if [ -z "${_returnData}" ] ; then if [ -f ${CCR_HOME}/config/default/${_propertyFile} ] ; then _returnData=`$EGREP "^$_propertyName=" ${CCR_HOME}/config/default/${_propertyFile} | \ $SED -e "s/$_propertyName=\s*//"` fi fi } isOCMConfigured() { _verbose=$1 if [ -z "$_verbose" ]; then _verbose=$FALSE fi G_OCMConfigured=$FALSE determineConfigHomeSetup if [ ${G_CONFIG_HOME_IS_SETUP} -eq $TRUE ] ; then checkIfDisconnected if [ "$G_INSTALL_DISCONN_STATE" = "true" -o -f ${CCR_CONFIG_HOME}/config/default/uplinkreg.bin ] ; then getProperty ccr.agreement_signer collector.properties _acceptee=${_returnData} if [ ! -z "${_acceptee}" ] ; then G_OCMConfigured=1 elif [ $_verbose -eq $TRUE ]; then $ECHO "The Oracle Configuration Manager license agreement has not been accepted." fi elif [ "$G_INSTALL_DISCONN_STATE" = "false" -a \ ! -f ${CCR_CONFIG_HOME}/config/default/uplinkreg.bin -a \ -z "$G_ConfigurationRequest" -a \ -z "${_responseFile}" -a -z "${_repeaterOption}" ]; then $ECHO "The configuration of Oracle Configuration Manager is unregistered." $ECHO "Please run the $ORACLE_HOME/bin/emCCR register command." fi elif [ $_verbose -eq $TRUE ]; then $ECHO "The Oracle Configuration Manager state/writeable directory structure is incomplete." fi } # Called from checkPrerequisite, this function performs conditional logic # on the type of message to return with corrective action reportInvalidJDKError() { # If this is a prereq check in a complete install, refer to # emSnapshotEnv, otherwise just give the error and terminate. if [ -f ${CCR_HOME}/bin/emCCR ] then $ECHO "Redefine JAVA_HOME to refer to a JDK/JRE 1.2.2 or greater and invoke " $ECHO " $ORACLE_HOME/ccr/bin/emSnapshotEnv." else $ECHO "Redefine JAVA_HOME to refer to a JDK/JRE 1.2.2 or greater." fi } determineJavaHome() { _verbose=$1 set +e # if user has explicitly told us the JAVA_HOME, then use it. if [ ! -z "${JAVA_HOME_CCR}" ]; then _JAVA_HOME=${JAVA_HOME_CCR} _javaLoc="The JAVA_HOME_CCR environment variable" if [ ! -z "${CCR_DEBUG}" ]; then $ECHO "JAVA_HOME_CCR was defined" fi elif [ ! -z "${JAVA_HOME}" ]; then _JAVA_HOME=$JAVA_HOME _javaLoc="JAVA_HOME" if [ ! -z "${CCR_DEBUG}" ]; then $ECHO "JAVA_HOME was defined" fi fi # The check for "! -f ${_JAVA_HOME}/bin/java" below makes this code consistent # with what is in emocmrsp. # Ideally (according to fmorshed and jsutton) if the user sets the JAVA_HOME # variable to something then he should expect that we pick up java from there # and no where else. The code below, and emocmrsp, look elsewhere!! if [ -z "${_JAVA_HOME}" -o ! -f ${_JAVA_HOME}/bin/java ]; then # User did not explicitly told us the JAVA_HOME # Try to find a jdk in the CCR home _CCR_PARENT=`$DIRNAME ${CCR_HOME}` _JAVA_HOME=${_CCR_PARENT}/jdk _javaLoc="The ORACLE_HOME" if [ ! -f ${_JAVA_HOME}/bin/java ]; then # Try to find a jre in the CCR home _JAVA_HOME=${_CCR_PARENT}/jre _javaLoc="The ORACLE_HOME" if [ ! -z "${CCR_DEBUG}" ]; then $ECHO "JAVA_HOME was defined from OH jre as last resort... may not have a java." fi else if [ ! -z "${CCR_DEBUG}" ]; then $ECHO "JAVA_HOME was defined from OH jdk" fi fi fi if [ -z "${_JAVA_HOME}" -o ! -f ${_JAVA_HOME}/bin/java ]; then if [ $_verbose -eq $TRUE ]; then $ECHO "${_javaLoc} does not contain java." $ECHO "${_javaLoc} does not contain a valid JDK/JRE." reportInvalidJDKError fi return $ERR_PREREQ_FAILURE fi # We have found a JAVA_HOME with a bin directory that has a file named java. # Make sure java is valid. _JAVA_BIN=${_JAVA_HOME}/bin if [ ! -z "${CCR_DEBUG}" ]; then $ECHO "Java bin directory is: ${_JAVA_BIN}" fi java_version=`${_JAVA_BIN}/java -version 2>&1` cmd_exit=$? java_version=`$ECHO $java_version | \ $EGREP 'java version' | $CUT -d'"' -f2 | $CUT -d'"' -f1` java_major_version=`$ECHO $java_version | $CUT -d'.' -f1` java_minor_version=`$ECHO $java_version | $CUT -d'.' -f2` if [ $cmd_exit -ne 0 -o \ -z "${java_major_version}" -o \ -z "${java_minor_version}" ]; then if [ $_verbose -eq $TRUE ]; then $ECHO "${_javaLoc} does not contain a valid JDK/JRE." reportInvalidJDKError fi return $ERR_PREREQ_FAILURE fi if [ "$java_major_version" != "1" -o \ "$java_minor_version" = "1" ]; then if [ $_verbose -eq $TRUE ]; then $ECHO "Java Version $java_version is less than minimum required (1.2.2)." $ECHO "${_javaLoc} does not contain a valid JDK/JRE." reportInvalidJDKError fi return $ERR_PREREQ_FAILURE fi JAVA_HOME=${_JAVA_HOME} export JAVA_HOME set -e return $SUCCESS } determineConfigHomeSetup() { if [ -d ${CCR_CONFIG_HOME}/config -a -d ${CCR_CONFIG_HOME}/config/default -a \ -d ${CCR_CONFIG_HOME}/state -a -d ${CCR_CONFIG_HOME}/state/diagnostic -a \ -d ${CCR_CONFIG_HOME}/state/previous -a -d ${CCR_CONFIG_HOME}/state/review -a \ -d ${CCR_CONFIG_HOME}/state/temp -a -d ${CCR_CONFIG_HOME}/state/upload -a \ -d ${CCR_CONFIG_HOME}/log ] then G_CONFIG_HOME_IS_SETUP=$TRUE else G_CONFIG_HOME_IS_SETUP=$FALSE fi } determineBootClassPath() { # determine OS architecture - IBM JVM needs special consideration for SSL # per bug 5894282 G_bootClassPath="" _osArch=`${JAVA_HOME}/bin/java -cp ${OCM_HOME}/lib/emocmcommon.jar OsInfo` if [ "${_osArch}" = "ppc" -o \ "${_osArch}" = "ppc64" -o \ "${_osArch}" = "s390" -o \ "${_osArch}" = "s390x" ]; then G_bootClassPath="-Xbootclasspath/a:${OCM_HOME}/lib/emocmclnt.jar:${OCM_HOME}/lib/emocmcommon.jar:${OCM_HOME}/lib/emocmclnt-14.jar:${OCM_HOME}/lib/osdt_core3.jar:${OCM_HOME}/lib/osdt_jce.jar:${OCM_HOME}/lib/http_client.jar:${OCM_HOME}/lib/regexp.jar:${OCM_HOME}/lib/jcert.jar:${OCM_HOME}/lib/jnet.jar:${OCM_HOME}/lib/jsse.jar:${OCM_HOME}/lib/log4j-core.jar:${OCM_HOME}/lib/xmlparserv2.jar" fi } determineOcmEndPoint() { G_ocmEndpoint="" if [ ! -z "${ORACLE_OCM_SERVICE}" ]; then G_ocmEndpoint="-Docm.endpoint=${ORACLE_OCM_SERVICE}" fi } determineOracleCCRTests() { G_oracleCCRTests="" if [ ! -z "${ORACLE_CCR_TESTS}" ] then G_oracleCCRTests="-DORACLE_CCR_TESTS=${ORACLE_CCR_TESTS}" fi } determineOcmLog() { G_ocmLog="" if [ ! -z "${CCR_DEBUG}" ]; then G_ocmLog="-DOCM_LOG_LEVEL=DEBUG" fi } determineOCMHome() { # Construct the CCR installation directory root based upon the bin # directory being a child. # Extract the binary directory specification where this script resides. # The enclosed code will come up with an absolute path. _OCMBinDir=`$DIRNAME $0 | $TR -s '/'` _savedDir=`$PWDD` cd ${_OCMBinDir} _OCMBinDir=`$PWDD` cd ${_savedDir} OCM_HOME=`$DIRNAME ${_OCMBinDir}` export OCM_HOME } checkOracleHomeOwnership $CCR_HOME ORACLE_HOME $ORACLE_HOME setHostName