#!/bin/sh # #ident "@(#)smreg 1.65 05/02/11 SMI" # Copyright (c) 2002-2004 Sun Microsystems, Inc. # All Rights Reserved. ################################################################################ ## ## This script registers objects with the Sun ## Java(TM) Web Console. ## ################################################################################ umask 022 ################################################################################ # # Globals Variables # ################################################################################ ## Return codes EXIT_SUCCESS=0 EXIT_USAGE=1 # missing/malformed arguments EXIT_FAILURE=2 # error in files or directories EXIT_UNKNOWNOS=3 # can't determine OS we're running on EXIT_BADOS=4 # detected OS not supported EXIT_BADVERSION=4 # can't determine console version we're running # Must be able to determine target OS so can set up appropriate # command environment. OS=`uname -s` if [ ! -n "${OS}" ]; then echo "Unable to determine operating system." 1>&2 exit $EXIT_UNKNOWNOS fi # Setup command environment for target OS. if [ "${OS}" = "SunOS" ]; then PATH=/bin:/sbin:/usr/sbin NAWK=nawk # XPG4-compliant implementation of awk ECHO=echo WHICH="/bin/ksh whence" # `which` is csh and can create problems under # under certain conditions # Default locations for java runtime DEFAULT_JAVA_HOME="" if [ -d /usr/jdk ]; then DEFAULT_JAVA_HOME="/usr/jdk/`ls -A /usr/jdk | fgrep jdk1.5 | sort | tail -1`" fi if [ -d /usr/j2se ]; then DEFAULT_JAVA_HOME="$DEFAULT_JAVA_HOME /usr/j2se" fi MANSECTION=1M DEFAULT_FILE=/etc/default/webconsole DEFAULT_TOMCAT_DIR=/usr/apache/tomcat elif [ "${OS}" = "Linux" ]; then PATH=/bin:/sbin:/usr/bin:/usr/sbin NAWK=awk # is already XPG4-compliant ECHO="/bin/echo -e" WHICH="which --skip-alias" # Default locations for java runtime if [ -d /usr/java ]; then DEFAULT_JAVA_HOME=/usr/java/`ls -A /usr/java | fgrep jdk1.5 | sort | tail -1` DEFAULT_JAVA_HOME="$DEFAULT_JAVA_HOME /usr/java/`ls -A /usr/java | fgrep j2sdk1.4 | sort | tail -1`" fi MANSECTION=1 DEFAULT_FILE=/etc/opt/default/webconsole DEFAULT_TOMCAT_DIR=/usr/apache/tomcat elif [ "${OS}" = "HP-UX" ]; then PATH=/bin:/sbin:/usr/bin:/usr/sbin NAWK=awk # is already XPG4-compliant ECHO="/bin/echo" MANSECTION=1 DEFAULT_FILE=/etc/default/webconsole DEFAULT_TOMCAT_DIR=/usr/bin/tomcat elif [ "${OS}" = "AIX" ]; then PATH=/bin:/sbin:/usr/bin:/usr/sbin NAWK=nawk # is already XPG4-compliant ECHO="/bin/echo" WHICH="/bin/ksh whence" DEFAULT_JAVA_HOME=/usr/java MANSECTION=1 DEFAULT_FILE=/etc/default/webconsole DEFAULT_TOMCAT_DIR=/usr/apache/jakarta-tomcat-5.0.16 else echo "Not supported on detected OS \"${OS}\"." 1>&2 exit $EXIT_BADOS fi # The model employed in the script is to delegate argument # parsing to subcommand functions. Some arguments can take the # form of 'name=value', where value can be enclosed in quotes # in the case of multiple words seperated by white space. # getopts(1) correctly parses this argument syntax in main script # code, but cannot parse it from within a function - the behavior is # that the quotes are not recognized, and so only the initial quote # character and the following word are recognized as an argument. # # So in order to preserve the argument delegation model, we replace # white space in every 'value' of a 'name=value' type of argument with a # unique pattern. Functions that process arguments which are expected # to be in 'name=value' format MUST reverse this substitution before # attempting to extract the 'name' and 'value'. The unique pattern # employed is available in the global variable WHITESPACE_KEY_PATTERN. # # After this pattern substitution, the main script code must NEVER # use "$*" to reference the list of all arguments, but instead must # use "$PROGARGS". Additionally, it must NEVER reference specific # arguments via "$1", "$2", etc. To use these macros, best to do so # in a function, where the args are passed in via $PROGARGS. # TIMESTAMP=`date -u +"%Y"%m"%d"%H"%M"%S""` WHITESPACE_KEY_PATTERN="_${TIMESTAMP}_" PROGARGS="" while [ -n "$1" ]; do a=$1 # Look for '=' character. If found, replace all whitespace with # unique pattern. $ECHO $1 | grep "=" >/dev/null 2>&1 if [ $? -eq 0 ]; then a=`$ECHO $1 | sed -e "s@ @$WHITESPACE_KEY_PATTERN@g"` fi # Rebuild program arguments PROGARGS="$PROGARGS $a" shift done ## This script's directory path and name PROGDIR=`dirname "$0"` PROGNAME=`basename "$0"` # Path to the .runtimerc - for performance sake, we determine it once # and cache it here RUNTIMERC="" ## The file name of the registered plugin list REG_PLUGIN_LIST=registered_plugins ## The file name of the smloginmodule command list in CATALINA_BASE JAAS_CONFIG_FILE=consolelogin.conf ## The file name of the pre-registered login modules JAAS_PRECONFIG_FILE=.consolelogin ## The official product name that this program is a part of PRODUCT_NAME="Sun Java(TM) Web Console" ## The file name of the registered jar list REG_JAR_LIST=registered_jars ## The file name of the registered login module list REG_MODULE_LIST=registered_modules ## The file name of the registered product names list REG_PRODNAME_LIST=ProductNames ## Temporary placeholder for properties that are needed by this program, ## but which cannot be made available as an environment variable or ## as a configuration property in $CONSOLE_CONFIG_DIR/webconsole. ## This is ONLY used when ALL the following conditions are true: ## - installation is being performed via unbundled setup only. ## - use of environment variables is precluded. ## - this program is invoked from a pkg script ## - $CONSOLE_CONFIG_DIR/webconsole does not exist ## ## The reasons for these conditions are: ## - $CONSOLE_CONFIG_DIR/webconsole might not exist because this smreg ## script may not have been installed yet by the time the setup program ## wants to set a property for smreg to use. During OS install, ## smreg processing takes place during stage 2 of the 2-stage ## registration/deployment, at which time the proper runtime environment ## and properties file does exist. ## - During pkgadd on Solaris, we cannot simply export environment ## variables to pkg scripts. pkgadd completely sets the runtime ## environment for pkg scripts based on the pkginfo. ## If you change this file, you MUST also change it in the setup scripts ## for each platform! PREREG=/var/tmp/_prereg.properties ## The first line of the registered plugin list AUTOGENERATEDSTRING="### DO NOT EDIT - AUTOMATICALLY GENERATED ###" ## The version of the Java Servlet Specification the filter and filter-mapping ## tags adhere to SERVLET_SPEC_VERSION=2.3 ## The pluginName tags in the app.xml file PLUGIN_NAME_START_TAG="" PLUGIN_NAME_END_TAG="<\/pluginName>" ## The managementApp start tag in the app.xml file MANAGEMENTAPP_START_TAG="/dev/null` if [ $? -eq 0 ]; then if [ "$PKG" = "SUNWmcon" ]; then dir="${BASEDIR}${dir}" else pkginst=`echo $pkginfo | awk '{print $2}'` basedir=`env LANG=C LC_ALL=C \ pkgparam ${Rarg} $pkginst BASEDIR 2>/dev/null` dir="${PKG_INSTALL_ROOT}${basedir}${dir}" fi else basedir=`env LANG=C LC_ALL=C \ pkgparam SUNWmcon BASEDIR 2>/dev/null` dir="${basedir}${dir}" fi elif [ "${OS}" = "Linux" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "HP-UX" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "AIX" ]; then basedir="/" dir="${basedir}${dir}" fi RUNTIMERC=`$ECHO ${dir} | sed -e 's@/*$@@' -e 's@//*@/@g'` if [ ! -f "$RUNTIMERC" ]; then $ECHO "Cannot find configuration \".runtimerc\" file." 1>&2 exit $EXIT_FAILURE fi # Execute it. . ${RUNTIMERC} } ## getRuntimeConfig ################################################################################ # # regUsage # # Prints usage of this script to the screen. # # $1 = Exit code # ################################################################################ regUsage() { cat - << EOF Usage: ${PROGNAME} SUBCOMMAND ARGUMENTS or: ${PROGNAME} $HELP_FLAG_SHORT Manages the registration database for the ${PRODUCT_NAME}. The accepted values for SUBCOMMAND are: add Registers objects remove Unregisters objects list Prints a list of registered objects check Validate a application's web.xml $VERSION_FLAG_SHORT, $VERSION_FLAG_LONG Display console version information. $HELP_FLAG_SHORT, $HELP_FLAG_SHORT2, $HELP_FLAG_LONG Display this help list. For more information, see smreg($MANSECTION). EOF exit $1 } ## end regUsage() ######################################################## # # Function to resolve a link to it's target. # ######################################################## resolve_link() { prg=$1 if [ -h "${prg}" ]; then # Must cd to where the symbolic link is located as a starting point # to follow the link. cd `dirname ${prg}` # Resolve link to conclusion while [ -h "${prg}" ] do prg=`ls -al ${prg} | awk '{print $NF}'` cd `dirname ${prg}` done # Resolve to full path, in case it's relative. prg=`pwd`/`basename ${prg}` fi $ECHO $prg } # resolve_link ######################################################## # # Version to convert a version string in X.Y.Z or # X.Y.X_NN format to XYZNN format so can be treated as a # number. # # $1 = version string # Returns numerical version # ######################################################## versionString2Num () { # Minor and micro default to 0 if not specified. major=`$ECHO $1 | awk -F. '{print $1}'` minor=`$ECHO $1 | awk -F. '{print $2}'` if [ ! -n "$minor" ]; then minor="0" fi dash=`$ECHO $minor | grep "-"` if [ $? -eq 0 ]; then # Must be internal build, so drop the trailing variant. minor=`$ECHO $minor | awk -F- '{print $1}'` $ECHO $minor | grep -v '[^0-9]' >/dev/null if [ $? -ne 0 ]; then minor="0" fi fi micro=`$ECHO $1 | awk -F. '{print $3}'` if [ ! -n "$micro" ]; then micro="0" fi # The micro version may further be extended to include a patch number. # This is typically of the form _NN, where NN is the 2-digit # patch number. However it can also be of the form -XX, where # XX is some arbitrary non-digit sequence (eg., "rc"). This latter # form is typically used for internal-only release candidates or # development builds. # # For these internal builds, we drop the -XX and assume a patch number # of "00". Otherwise, we extract that patch number. # patch="00" dash=`$ECHO $micro | grep "-"` if [ $? -eq 0 ]; then # Must be internal build, so drop the trailing variant. micro=`$ECHO $micro | awk -F- '{print $1}'` $ECHO $micro | grep -v '[^0-9]' >/dev/null if [ $? -ne 0 ]; then micro="0" fi fi underscore=`$ECHO $micro | grep "_"` if [ $? -eq 0 ]; then # Extract the seperate micro and patch numbers, ignoring anything # after the 2-digit patch. patch=`$ECHO $micro | awk -F_ '{print substr($2, 1, 2)}'` micro=`$ECHO $micro | awk -F_ '{print $1}'` fi # Strip off any alphabetic characters, in case anyone inserts things # like "beta". We don't support such variants, but the test group # admits to needing this fixed for selfish reasons. ;-) major=`echo $major | sed -e "s/[a-z]//g" -e "s/[A-Z]//g"` minor=`echo $minor | sed -e "s/[a-z]//g" -e "s/[A-Z]//g"` micro=`echo $micro | sed -e "s/[a-z]//g" -e "s/[A-Z]//g"` $ECHO "${major}${minor}${micro}${patch}" } # versionString2Num ######################################################## # # Function to try to find a suitable Java2 runtime # ######################################################## findJava() { # JAVA_HOME environment variable overrides everything JAVA_LOC="${JAVA_HOME:+${JAVA_HOME}/bin/java}" # java.home property is where we think it should be. javahome_prop=`/usr/sbin/smreg list -p | grep "java.home="` if [ $? -eq 0 ]; then JAVA_LOC="$JAVA_LOC `echo $javahome_prop | cut -d"=" -f2`/bin/java" fi # Followed by along PATH and the standard location. defaultJavas="" for i in $DEFAULT_JAVA_HOME; do defaultJavas="$defaultJavas $i/bin/java" done javaOnPath=`${WHICH} java 2>&1` if [ $? -eq 0 ]; then JAVA_LOC="$JAVA_LOC ${javaOnPath} ${defaultJavas}" else JAVA_LOC="$JAVA_LOC ${defaultJavas}" fi # Followed by the special temporary placeholder for properties that are # needed by this program, but which cannot be made available as an # environment variable or as a configuration property. # See the definition of PREREG for a full explanation. if [ -f $PREREG ]; then javahome_prop=`cat $PREREG | grep "java.home="` if [ $? -eq 0 ]; then JAVA_LOC="$JAVA_LOC `echo $javahome_prop | cut -d"=" -f2`/bin/java" fi fi JAVA_HOME="" for i in ${JAVA_LOC} do prog=`resolve_link ${i}` if [ -x ${prog} ]; then JAVA_HOME=`dirname \`dirname ${prog}\`` break fi done if [ ! -n "${JAVA_HOME}" ]; then $ECHO "No suitable Java runtime found in any of the following directories:" 1>&2 $ECHO " \c" 1>&2 for i in $JAVA_LOC; do $ECHO "${i} \c"; done; $ECHO 1>&2 $ECHO "Please set the JAVA_HOME environment variable to point to a Java" 1>&2 $ECHO "installation and run ${PROGDIR}/${PROGNAME} again." 1>&2 exit 1 fi } # findJava ################################################################################ # # getConsoleVersionNum # # get the console version and convert it to a "number" for version checking # ################################################################################ getConsoleVersionNum() { # If CONSOLE_VERSION is empty extract it from version.txt if [ ! -n "${CONSOLE_VERSION}" ]; then # Extract console version and set the CONSOLE_VERSION # and CONSOLE_VERSION_NUM vars. If we get back the string "???" # exit with an error code CONSOLE_VERSION=`regVersion | head -1 | awk '{print $NF}'` if [ "${CONSOLE_VERSION}" != "???" ]; then CONSOLE_VERSION="`echo ${CONSOLE_VERSION} | \ sed -e 's@ @@g' -e 's@[a-zA-Z\-]@@g'`" CONSOLE_VERSION_NUM="`versionString2Num ${CONSOLE_VERSION}`" else printOut "Error! Unable to determine console version." 1>&2 printOut "Does ${CONSOLE_INSTALL_DIR}/version.txt exist?" 1>&2 exit ${EXIT_BADVERSION} fi fi } ## end getConsoleVersionNum ################################################################################ # # regVersion # # Display version information. # ################################################################################ regVersion() { # Extract console version. # getConsoleInstallDir versionFile=${CONSOLE_INSTALL_DIR}/version.txt if [ -f ${versionFile} ]; then version="`cat ${versionFile}`" else version="???" fi cat - << EOF ${PROGNAME} (${PRODUCT_NAME}) $version Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms. EOF } ## end regVersion ################################################################################ # # isRoot # # Check the user ID to see if it matches root's (0). # Return 0 if the user is root. Exit with status 1 otherwise. # ################################################################################ isRoot() { USERID=`id | sed -e 's/uid=\([0-9]*\).*/\1/'` if [ $USERID -ne 0 ]; then printOut "Error! You must be \"root\" to run this command." 1>&2 exit $EXIT_USAGE fi return 0 } ## end isRoot ################################################################################ # # perms2mode # # Converts file permissions in format output from `ls -l' to absolute # mode into form used by `chmod'. Only does "simple" conversions so basic # permissions on files we modified can be restored - no support for # sticky bits and such. # # $1 = permissions for owner, group, world in standard 3-character # sequence for each (eg., "-rw-r--r--") # # Returns the absolute mode # ################################################################################ perms2mode() { perms=$1 owner=`$ECHO $perms | awk '{print substr($1, 2, 3)}'` group=`$ECHO $perms | awk '{print substr($1, 5, 3)}'` world=`$ECHO $perms | awk '{print substr($1, 8, 3)}'` perms="" for user in $owner $group $world do n=0 r=`$ECHO $user | awk '{print substr($1, 1, 1)}'` w=`$ECHO $user | awk '{print substr($1, 2, 1)}'` x=`$ECHO $user | awk '{print substr($1, 3, 1)}'` if [ "$r" = "r" ]; then n=4 fi if [ "$w" = "w" ]; then n=`(expr $n + 2)` fi if [ "$x" = "x" ]; then n=`(expr $n + 1)` fi perms="${perms}${n}" done $ECHO ${perms} } ## end perms2mode ################################################################################ # # inMiniRoot # # Return "1" if this program is running from a relocatable root, "0" if not. # ################################################################################ inMiniRoot() { # Check if the application's install pkg is relocateable if [ -n "${PKG_INSTALL_ROOT}" ]; then # Check if the console was also relocated to this location. if [ "${OS}" = "SunOS" ]; then Aarg="" if [ -n "$ARCH" ]; then Aarg="-a $ARCH" fi pkginfo ${Aarg} -R ${PKG_INSTALL_ROOT} "SUNWmcon*" >/dev/null 2>&1 if [ $? -eq 0 ]; then $ECHO "1" return fi fi fi $ECHO "0" } ## end inMiniRoot ################################################################################ # # isNormalizeable # # Determine if a given path can be normalized to its absolute runtime # location. This is needed to account for the fact that when running # running during install, paths are very likely to be mount points on # some install server, so we need to be able to determine if we can strip # off any leading BASEDIR. However, we can NOT normalize if we find a BASEDIR # of /, /usr, or one starting with /opt, which are *real* BASEDIRs, and not # mount points. We also can NOT normalize if the application pkg is relocatable # but not to the same location as the console itself. # # $1 = the path to check # # Return "0" if the path should NOT be normalized, "1" if it can. # ################################################################################ isNormalizeable() { # Check if the application's install pkg is relocateable if [ -n "${PKG_INSTALL_ROOT}" ]; then # Check if the console was also relocated to this location. # If not, then the path should not be normalized. if [ "${OS}" = "SunOS" ]; then Aarg="" if [ -n "$ARCH" ]; then Aarg="-a $ARCH" fi pkginfo ${Aarg} -R ${PKG_INSTALL_ROOT} "SUNWmcon*" >/dev/null 2>&1 if [ $? -ne 0 ]; then $ECHO "0" return fi fi fi # Paths starting with /opt should not be normalized. opt=`$ECHO $1 | grep "^/opt/"` if [ -n "${opt}" ]; then $ECHO "0" # / and /usr should not be normalized, everything else can elif [ -n "${1}" -a "${1}" != "/" -a "${1}" != "/usr" ]; then $ECHO "1" else $ECHO "0" fi } ## isNormalizeable ################################################################################ # # getConsoleInstallDir # # Get the install directory of the console and set it in CONSOLE_INSTALL_DIR. # This is the directory containing shared data stores. # The default is /usr/share/webconsole. # CONSOLE_INSTALL_DIR is relative to the machine on which the script is being # run; that is, the directory MUST be accessible from within the script during # system install. # ################################################################################ getConsoleInstallDir() { if [ -n "${CONSOLE_INSTALL_DIR}" ]; then return fi getRuntimeConfig dir=/usr/share/webconsole if [ -n "${COM_SUN_WEB_CONSOLE_HOME}" ]; then dir=${COM_SUN_WEB_CONSOLE_HOME} fi # Adjust default directory based on console pkg relocation and basedir. if [ "${OS}" = "SunOS" ]; then Rarg="" if [ -n "${PKG_INSTALL_ROOT}" ]; then Rarg="-R ${PKG_INSTALL_ROOT}" fi Aarg="" if [ -n "${ARCH}" ]; then Aarg="-a ${ARCH}" fi pkginfo=`pkginfo ${Aarg} ${Rarg} "SUNWmcon*" 2>/dev/null` if [ $? -eq 0 ]; then if [ "$PKG" = "SUNWmcon" ]; then dir="${BASEDIR}${dir}" else pkginst=`echo $pkginfo | awk '{print $2}'` basedir=`env LANG=C LC_ALL=C \ pkgparam ${Rarg} $pkginst BASEDIR 2>/dev/null` dir="${PKG_INSTALL_ROOT}${basedir}${dir}" fi else basedir=`env LANG=C LC_ALL=C \ pkgparam SUNWmcon BASEDIR 2>/dev/null` dir="${basedir}${dir}" fi elif [ "${OS}" = "Linux" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "HP-UX" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "AIX" ]; then basedir="/" dir="${basedir}${dir}" fi CONSOLE_INSTALL_DIR=`$ECHO ${dir} | sed -e 's@/*$@@' -e 's@//*@/@g'` if [ ! -d "$CONSOLE_INSTALL_DIR" ]; then printOut "Error! Installation directory \"$CONSOLE_INSTALL_DIR\" does not exist." 1>&2 exit $EXIT_FAILURE fi } ## end getConsoleInstallDir ################################################################################ # # getConsoleAppbaseDir # # Get the deployed web application base directory and set it in CONSOLE_APPBASE_DIR. # This is the directory web applications are deployed into by registration. # The default is /var/opt/webconsole/webapps. # CONSOLE_APPBASE_DIR is relative to the machine on which the script is being # run; that is, the directory MUST be accessible from within the script during # system install. # ################################################################################ getConsoleAppbaseDir() { if [ -n "${CONSOLE_APPBASE_DIR}" ]; then return fi getRuntimeConfig dir=/var/opt/webconsole/webapps if [ -n "${COM_SUN_WEB_CONSOLE_APPBASE}" ]; then dir=${COM_SUN_WEB_CONSOLE_APPBASE} fi # Adjust default directory based on console pkg relocation and basedir. if [ "${OS}" = "SunOS" ]; then Rarg="" if [ -n "${PKG_INSTALL_ROOT}" ]; then Rarg="-R ${PKG_INSTALL_ROOT}" fi Aarg="" if [ -n "$ARCH" ]; then Aarg="-a $ARCH" fi pkginfo=`pkginfo ${Aarg} ${Rarg} "SUNWmconr*" 2>/dev/null` if [ $? -eq 0 ]; then if [ "$PKG" = "SUNWmconr" ]; then dir="${BASEDIR}${dir}" else pkginst=`echo $pkginfo | awk '{print $2}'` basedir=`env LANG=C LC_ALL=C \ pkgparam ${Rarg} $pkginst BASEDIR 2>/dev/null` dir="${PKG_INSTALL_ROOT}${basedir}${dir}" fi else basedir=`env LANG=C LC_ALL=C \ pkgparam SUNWmconr BASEDIR 2>/dev/null` dir="${basedir}${dir}" fi elif [ "${OS}" = "Linux" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "HP-UX" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "AIX" ]; then basedir="/" dir="${basedir}${dir}" fi CONSOLE_APPBASE_DIR=`$ECHO ${dir} | sed -e 's@/*$@@' -e 's@//*@/@g'` if [ ! -d "$CONSOLE_APPBASE_DIR" ]; then printOut "Error! Deployment directory \"$CONSOLE_APPBASE_DIR\" does not exist." 1>&2 exit $EXIT_FAILURE fi } ## end getConsoleAppbaseDir ################################################################################ # # getConsoleBaseDir # # Get the console base directory and set it in CONSOLE_BASE_DIR. # This is the directory where we maintain our configuration and registrations. # The default is /var/opt/webconsole. # CONSOLE_BASE_DIR is relative to the machine on which the script is being # run; that is, the directory MUST be accessible from within the script during # system install. # ################################################################################ getConsoleBaseDir() { if [ -n "${CONSOLE_BASE_DIR}" ]; then return fi getRuntimeConfig dir=/var/opt/webconsole if [ -n "${COM_SUN_WEB_CONSOLE_BASE}" ]; then dir=${COM_SUN_WEB_CONSOLE_BASE} fi # Adjust default directory based on console pkg relocation and basedir. if [ "${OS}" = "SunOS" ]; then Rarg="" if [ -n "${PKG_INSTALL_ROOT}" ]; then Rarg="-R ${PKG_INSTALL_ROOT}" fi Aarg="" if [ -n "$ARCH" ]; then Aarg="-a $ARCH" fi pkginfo=`pkginfo ${Aarg} ${Rarg} "SUNWmconr*" 2>/dev/null` if [ $? -eq 0 ]; then if [ "$PKG" = "SUNWmconr" ]; then dir="${BASEDIR}${dir}" else pkginst=`echo $pkginfo | awk '{print $2}'` basedir=`env LANG=C LC_ALL=C \ pkgparam ${Rarg} $pkginst BASEDIR 2>/dev/null` dir="${PKG_INSTALL_ROOT}${basedir}${dir}" fi else basedir=`env LANG=C LC_ALL=C \ pkgparam SUNWmconr BASEDIR 2>/dev/null` dir="${basedir}${dir}" fi elif [ "${OS}" = "Linux" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "HP-UX" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "AIX" ]; then basedir="/" dir="${basedir}${dir}" fi CONSOLE_BASE_DIR=`$ECHO ${dir} | sed -e 's@/*$@@' -e 's@//*@/@g'` if [ ! -d "$CONSOLE_BASE_DIR" ]; then printOut "Error! directory \"$CONSOLE_BASE_DIR\" does not exist." 1>&2 exit $EXIT_FAILURE fi } ## end getConsoleBaseDir ################################################################################ # # getConsoleConfigDir # # Get the configuration directory of the console and set it in CONSOLE_CONFIG_DIR. # The default is /etc/opt/webconsole. # CONSOLE_CONFIG_DIR is relative to the machine on which the script is being # run; that is, the directory MUST be accessible from within the script during # system install. # ################################################################################ getConsoleConfigDir() { if [ -n "${CONSOLE_CONFIG_DIR}" ]; then return fi dir=/etc/opt/webconsole # Adjust default directory based on console pkg relocation and basedir. if [ "${OS}" = "SunOS" ]; then Rarg="" if [ -n "${PKG_INSTALL_ROOT}" ]; then Rarg="-R ${PKG_INSTALL_ROOT}" fi Aarg="" if [ -n "$ARCH" ]; then Aarg="-a $ARCH" fi pkginfo=`pkginfo ${Aarg} ${Rarg} "SUNWmconr*" 2>/dev/null` if [ $? -eq 0 ]; then if [ "$PKG" = "SUNWmconr" ]; then dir="${BASEDIR}${dir}" else pkginst=`echo $pkginfo | awk '{print $2}'` basedir=`env LANG=C LC_ALL=C \ pkgparam ${Rarg} $pkginst BASEDIR 2>/dev/null` dir="${PKG_INSTALL_ROOT}${basedir}${dir}" fi else basedir=`env LANG=C LC_ALL=C \ pkgparam SUNWmconr BASEDIR 2>/dev/null` dir="${basedir}${dir}" fi elif [ "${OS}" = "Linux" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "HP-UX" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "AIX" ]; then basedir="/" dir="${basedir}${dir}" fi CONSOLE_CONFIG_DIR=`$ECHO ${dir} | sed -e 's@/*$@@' -e 's@//*@/@g'` if [ ! -d "$CONSOLE_CONFIG_DIR" ]; then printOut "Error! Configuration directory \"$CONSOLE_CONFIG_DIR\" does not exist." 1>&2 exit $EXIT_FAILURE fi } ## end getConsoleConfigDir ################################################################################ # # getJatoInstallDir # # Get the install directory of JATO and set it in JATO_INSTALL_DIR. # The default is /usr/share/lib/jato. # JATO_INSTALL_DIR is relative to the machine on which the script is being; # run; that is, the directory MUST be accessible from within the script during # system install. # ################################################################################ getJatoInstallDir() { if [ -n "${JATO_INSTALL_DIR}" ]; then return fi getRuntimeConfig dir=/usr/share/lib/jato if [ -n "${JATO_HOME}" ]; then dir=${JATO_HOME} fi # Adjust default directory based on jato pkg relocation and basedir. if [ "${OS}" = "SunOS" ]; then Rarg="" if [ -n "${PKG_INSTALL_ROOT}" ]; then Rarg="-R ${PKG_INSTALL_ROOT}" fi Aarg="" if [ -n "${ARCH}" ]; then Aarg="-a ${ARCH}" fi # Check for a package for the specific architecture. pkginfo=`pkginfo ${Aarg} ${Rarg} "SUNWjato*" 2>/dev/null` if [ $? -ne 0 ]; then # In this case, Jato was not installed with a specific architecture # type. Instead, the ARCH type 'all' was used'. if [ -n "${ARCH}" ]; then Aarg="-a all" fi pkginfo=`pkginfo ${Aarg} ${Rarg} "SUNWjato*" 2>/dev/null` fi if [ $? -eq 0 ]; then if [ "$PKG" = "SUNWjato" ]; then dir="${BASEDIR}${dir}" else pkginst=`echo $pkginfo | awk '{print $2}'` basedir=`env LANG=C LC_ALL=C \ pkgparam ${Rarg} $pkginst BASEDIR 2>/dev/null` dir="${PKG_INSTALL_ROOT}${basedir}${dir}" fi else basedir=`env LANG=C LC_ALL=C \ pkgparam SUNWjato BASEDIR 2>/dev/null` dir="${basedir}${dir}" fi elif [ "${OS}" = "Linux" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "HP-UX" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "AIX" ]; then basedir="/" dir="${basedir}${dir}" fi JATO_INSTALL_DIR=`$ECHO ${dir} | sed -e 's@/*$@@' -e 's@//*@/@g'` if [ ! -d "$JATO_INSTALL_DIR" ]; then printOut "Error! SunOne Presentation Framework installation directory \"$JATO_INSTALL_DIR\" does not exist." 1>&2 exit $EXIT_FAILURE fi } ## end getJatoInstallDir ################################################################################ # # getTomcatInstallDir # # Get the install directory of Tomcat and set it in TOMCAT_INSTALL_DIR. # The default is /usr/apache/tomcat. # TOMCAT_INSTALL_DIR is relative to the machine on which the script is being # run; that is, the directory MUST be accessible from within the script during # system install. # ################################################################################ getTomcatInstallDir() { if [ -n "${TOMCAT_INSTALL_DIR}" ]; then return fi getRuntimeConfig dir=$DEFAULT_TOMCAT_DIR if [ -n "${CATALINA_HOME}" ]; then dir=${CATALINA_HOME} fi # Adjust default directory based on tomcat pkg relocation and basedir. # But Tomcat could have been installed in /opt, in which case we don't # need to account for pkg relocation. This determination is based on # whether it's BASEDIR is normalizeable. # if [ "${OS}" = "SunOS" ]; then Rarg="" if [ -n "${PKG_INSTALL_ROOT}" ]; then Rarg="-R ${PKG_INSTALL_ROOT}" fi Aarg="" if [ -n "${ARCH}" ]; then Aarg="-a ${ARCH}" fi pkginfo=`pkginfo ${Aarg} ${Rarg} "SUNWtcatu*" 2>/dev/null` if [ $? -eq 0 ]; then if [ "$PKG" = "SUNWtcatu" ]; then dir="${BASEDIR}${dir}" else pkginst=`echo $pkginfo | awk '{print $2}'` basedir=`env LANG=C LC_ALL=C \ pkgparam ${Rarg} $pkginst BASEDIR 2>/dev/null` if [ `isNormalizeable ${PKG_INSTALL_ROOT}${basedir}` = "1" ]; then dir="${PKG_INSTALL_ROOT}${basedir}${dir}" fi fi else basedir=`env LANG=C LC_ALL=C \ pkgparam SUNWtcatu BASEDIR 2>/dev/null` if [ `isNormalizeable ${basedir}` = "1" ]; then dir="${basedir}${dir}" fi fi elif [ "${OS}" = "Linux" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "HP-UX" ]; then basedir="/" dir="${basedir}${dir}" elif [ "${OS}" = "AIX" ]; then basedir="/" dir="${basedir}${dir}" fi TOMCAT_INSTALL_DIR=`$ECHO ${dir} | sed -e 's@/*$@@' -e 's@//*@/@g'` if [ ! -d "$TOMCAT_INSTALL_DIR" ]; then printOut "Error! Tomcat installation directory \"$TOMCAT_INSTALL_DIR\" does not exist." 1>&2 exit $EXIT_FAILURE fi } ## end getTomcatInstallDir ################################################################################ # # absPath # # Convert a path argument to an absolute path. # ################################################################################ absPath() { # Record our CWD savecwd=`pwd` if [ -d $1 ]; then # It's a directory that exists, so we can cd to it and resolve # its full path. cd $1 wd=`pwd` cd $savecwd echo $wd elif [ -f $1 ]; then # It's a file that exists, so we can cd to it's parent and resolve # its full path. cd `dirname $1` wd=`pwd` cd $savecwd echo $wd/`basename $1` else # Otherwise just return the original path echo $1 fi } ## absPath ################################################################################ # # registerApp # # Registers an application plugin. # # $1 = directory in which the plugin application was installed, or # path to war file # $2 = optional deployment context path # ################################################################################ registerApp() { fullPath=`absPath $1` if [ `inMiniRoot` = "1" ]; then getConsoleInstallDir # Normalize the path so that the command gets written out so that it # resolves relative to the client's runtime. command=${PROGDIR}/${PROGNAME} if [ `isNormalizeable ${BASEDIR}` = "1" ]; then command=`$ECHO $command | sed -e "s@^${BASEDIR}/@/@"` fi # Re-create the original command that got us here in the 1st place. # p=$1 if [ `isNormalizeable ${BASEDIR}` = "1" ]; then p=`$ECHO $p | sed -e "s@^${BASEDIR}/@/@"` fi if [ -n "$2" ]; then cmd="$command add -a -x $2 $p" else cmd="$command add -a $p" fi deferRegistration "$cmd" return fi # Make sure we have the console version num getConsoleVersionNum ## Create the new plugin list if it doesn't exist or if its size is 0 getConsoleInstallDir getConsoleBaseDir if [ ! -s $CONSOLE_BASE_DIR/$REG_PLUGIN_LIST ]; then doBanner $CONSOLE_BASE_DIR/$REG_PLUGIN_LIST fi # Check for packed (war file) or unpacked application. suffix=`$ECHO $fullPath | \ awk '{i=index($1, ".war")}{print substr($1, i, length($1)-i+1)}'` if [ $suffix = ".war" ]; then # 2.1 does not officially support war file deployment # we'll leave the code and just exit printOut "Error! Deployment of applications in web archive (.war) format is not supported." exit $EXIT_FAILURE # WAR file if [ ! -s $fullPath ]; then printOut "Error! \"$fullPath\" does not exist." 1>&2 exit $EXIT_FAILURE fi # If not specified, context derived from war filename. warFilename=`basename $fullPath` context=$2 if [ ! -n "$context" ]; then context=`$ECHO $warFilename | sed -e "s/.war//"` fi # Extract app.xml from war file so we can get the pluginName # and SDK version this app was built with. findJava tmpdir=/tmp/.smreg.$$ mkdir -p $tmpdir savecwd=`pwd` cd $tmpdir $JAVA_HOME/bin/jar xf $fullPath WEB-INF/app.xml cd $savecwd if [ -s $tmpdir/WEB-INF/app.xml ]; then extractPluginName $tmpdir/WEB-INF/app.xml extractSDKversion $tmpdir/WEB-INF/app.xml rm -rf $tmpdir appVersion=`versionString2Num $SDK_VERSION` if [ "(" ${appVersion} -lt 21000 ")" -o "(" ${appVersion} -gt ${CONSOLE_VERSION_NUM} ")" ]; then printOut "Error! The registrationInfo \"$VERSION_ATTR\" attribute in $fullPath/WEB-INF/app.xml must be at least 2.1 and no more than ${CONSOLE_VERSION}" 1>&2 exit $EXIT_FAILURE fi $ECHO " Registering $fullPath\n as context $context\n" else rm -rf $tmpdir SDK_VERSION="2.1" # Must be 2.1 or greater PLUGIN_NAME="unknown" $ECHO " Registering $fullPath\n as context $context\n" fi # Remove any existing entry for this app from the database removeRegAppBy context $context params="unused" ## Remove trailing slashes (/) and double slashes (//) from the war name war=`$ECHO $fullPath | sed -e 's@/*$@@' -e 's@//*@/@g'` $ECHO "$context|$PLUGIN_NAME|$war|$SDK_VERSION|$params" \ >> $CONSOLE_BASE_DIR/$REG_PLUGIN_LIST return fi # Unpacked application in a directory PLUGIN_DIR=$fullPath if [ ! -d $PLUGIN_DIR ]; then printOut "Error! \"$PLUGIN_DIR\" does not exist." 1>&2 exit $EXIT_FAILURE fi # Extract information from application descriptor. if [ -s $PLUGIN_DIR/WEB-INF/app.xml ]; then # Apps based on 2.1 or later should have descriptor in app's WEB-INF # directory, and the registrationInfo version should be set to the SDK # the app was built against, 2.1 or later. extractSDKversion $PLUGIN_DIR/WEB-INF/app.xml appVersion=`versionString2Num $SDK_VERSION` if [ "(" ${appVersion} -lt 21000 ")" -o "(" ${appVersion} -gt ${CONSOLE_VERSION_NUM} ")" ]; then printOut "Error! The registrationInfo \"$VERSION_ATTR\" attribute in $PLUGIN_DIR/WEB-INF/app.xml must be at least 2.1 and no more than ${CONSOLE_VERSION}" 1>&2 exit $EXIT_FAILURE fi extractPluginName $PLUGIN_DIR/WEB-INF/app.xml elif [ -s $PLUGIN_DIR/app.xml ]; then # Pre-2.1 based apps have descriptor in top-level app directory. extractSDKversion $PLUGIN_DIR/app.xml if [ `versionString2Num $SDK_VERSION` -gt 20000 ]; then printOut "Error! The registrationInfo \"$VERSION_ATTR\" attribute in $PLUGIN_DIR/app.xml must be less than 2.1" 1>&2 exit $EXIT_FAILURE fi extractPluginName $PLUGIN_DIR/app.xml else printOut "Error! No registration descriptor file (app.xml) found in $PLUGIN_DIR or $PLUGIN_DIR/WEB-INF." 1>&2 exit $EXIT_FAILURE fi printOut "Registering $PLUGIN_NAME." ## If the plugin_name is registered, remove the original from the file isAppRegistered $PLUGIN_NAME if [ $? -eq 0 ]; then # get the app name we need for removal regAppInfo=`getRegAppBy pluginID $PLUGIN_NAME` app=`getRegAppValue $regAppInfo context` # remove the plugin removeRegAppBy pluginID $PLUGIN_NAME # remove the app's files in $CONSOLE_APPBASE_DIR getConsoleAppbaseDir /bin/rm -rf $CONSOLE_APPBASE_DIR/$app fi # Pre-2.1 based apps must have filter tags in web.xml. if [ `versionString2Num $SDK_VERSION` -lt 21000 ]; then checkForFilterTags $1 if [ $? -ne 0 ]; then printOut "Error! The web deployment descriptor in $PLUGIN_DIR/WEB-INF/web.xml does not contain the required and tags. This application is not registered." 1>&2 printOut "Run this script with the \"check\" subcommand to view the descriptor with these tags inserted." 1>&2 exit $EXIT_FAILURE fi fi # Apps must have tags-related files copied into their deployment area. installTags # Auto generate product name images generateProdnames # normalize the path so that the client PLUGIN_DIR gets written out if [ `isNormalizeable ${BASEDIR}` = "1" ]; then PLUGIN_DIR=`$ECHO $PLUGIN_DIR | sed -e "s@^${BASEDIR}/@/@"` fi ## Remove trailing slashes (/) and double slashes (//) from the directory PLUGIN_DIR=`$ECHO $PLUGIN_DIR | sed -e 's@/*$@@' -e 's@//*@/@g'` # Context derived from app's directory name, but app's built with the # SDK version 2.1 or later can override if [ `versionString2Num $SDK_VERSION` -lt 21000 ]; then context=`basename $PLUGIN_DIR` else context=$2 if [ ! -n "$context" ]; then context=`basename $PLUGIN_DIR` fi fi params="unused" ## Append the unique plugin name to the registered plugin list $ECHO "$context|$PLUGIN_NAME|$PLUGIN_DIR|$SDK_VERSION|$params" \ >> $CONSOLE_BASE_DIR/$REG_PLUGIN_LIST } ## end registerApp ################################################################################ # # registerJar # # Registers a jar file, with the specified scope # # $1 = path to jar file # $2 = scope under which the jar was registered . This can be the # token "ALL", in which case the scope is global and the jar # is shared by all apps. Alternatively, this can be an # application's registered name, which is _, # where and are as specified in the app's web.xml # $3 = 1=register the jar via a symbolic link # 0=register the jar via a file copy # $4 = name by which to register the jar. If not specified, the # default is `basename $1` # # Entries in the registration database are of the form: # scope@name path # ################################################################################ registerJar() { path=`absPath $1` path=`$ECHO $path | sed -e 's@/*$@@' -e 's@//*@/@g'` scope=$2 linkFlag=$3 name=$4 if [ `inMiniRoot` = "1" ]; then getConsoleInstallDir # Normalize the path so that the command gets written out so that it # resolves relative to the client's runtime. command=${PROGDIR}/${PROGNAME} if [ `isNormalizeable ${BASEDIR}` = "1" ]; then command=`$ECHO $command | sed -e "s@^${BASEDIR}/@/@"` fi # Re-create the original command that got us here in the 1st place. # p=$path if [ `isNormalizeable ${BASEDIR}` = "1" ]; then p=`$ECHO $path | sed -e "s@^${BASEDIR}/@/@"` fi if [ $linkFlag -eq 0 ]; then cmd="$command add -l -s $scope -n $name $p" else cmd="$command add -l -L -s $scope -n $name $p" fi deferRegistration "$cmd" # Tomcat 4.x requires the shared lib area to be with the software - that is, # in /usr. Unfortunately if we defer the command to initial server startup, # the client could be diskless, in which case /usr is read-only. To workaround # this, we install the jar now. The original command will still be deferred and # the copy will be attempted again at server startup - this will simply overwrite # the original copy on a standalone machine, and be bypassed in a diskless or # local zone environment when /usr is read-only (See below). # if [ "${scope}" = "ALL" ]; then # Must have ".jar" suffix. suffix=`$ECHO $path | \ awk '{i=index($1, ".jar")}{print substr($1, i, length($1)-i+1)}'` if [ $suffix = ".jar" ]; then # Install jar to Tomcat's lib directory getTomcatInstallDir rm -f ${TOMCAT_INSTALL_DIR}/lib/$name >/dev/null 2>&1 if [ $linkFlag -eq 0 ]; then cp $path ${TOMCAT_INSTALL_DIR}/lib/$name chmod 644 ${TOMCAT_INSTALL_DIR}/lib/$name else ln -s $path ${TOMCAT_INSTALL_DIR}/lib/$name fi fi fi return fi getConsoleAppbaseDir getConsoleBaseDir # Must have ".jar" suffix. suffix=`$ECHO $path | \ awk '{i=index($1, ".jar")}{print substr($1, i, length($1)-i+1)}'` if [ $suffix != ".jar" ]; then printOut "Not a jar file!" 1>&2 exit $EXIT_FAILURE fi # Default name to register the jar is basename of the path. if [ ! -n "$name" ]; then name=`basename $path` fi # Name must include .jar suffix, so add it if not provided. suffix=`$ECHO $name | \ awk '{i=index($1, ".jar")}{print substr($1, i, length($1)-i+1)}'` if [ $suffix != ".jar" ]; then name=${name}.jar fi $ECHO " Registering $path\n as $name for scope $scope\n" if [ "${scope}" = "ALL" ]; then getTomcatInstallDir # It is possible Tomcat could be located on a shared read-only # filesystem. On Solaris this could be within a zone. So # only copy the jar if we have write access to the Tomcat area. # tiptoe=$TOMCAT_INSTALL_DIR/_.$$ touch $tiptoe >/dev/null 2>&1 if [ $? -eq 0 ]; then rm -f $tiptoe # AIX is different - primarily because we are # using tomcat 5.x - the shared libs need to # go in CATALINA_HOME/shared/lib # NOTE: On Solaris, if we migrate to Tomcat 5.x, # these libs *should* go into CATALINA_BASE/shared/lib # but this does not seem to work for AIX. # if [ "${OS}" = "AIX" ]; then # Install jar to Tomcat's lib directory rm -f ${TOMCAT_INSTALL_DIR}/shared/lib/$name >/dev/null 2>&1 if [ $linkFlag -eq 0 ]; then cp $path ${TOMCAT_INSTALL_DIR}/shared/lib/$name chmod 644 ${TOMCAT_INSTALL_DIR}/shared/lib/$name else ln -s $path ${TOMCAT_INSTALL_DIR}/shared/lib/$name fi else # Install jar to Tomcat's lib directory rm -f ${TOMCAT_INSTALL_DIR}/lib/$name >/dev/null 2>&1 if [ $linkFlag -eq 0 ]; then cp $path ${TOMCAT_INSTALL_DIR}/lib/$name chmod 644 ${TOMCAT_INSTALL_DIR}/lib/$name else ln -s $path ${TOMCAT_INSTALL_DIR}/lib/$name fi fi fi else # Scope is reference to registered app. It must already be registered. isAppRegistered $scope if [ $? -eq 1 ]; then printOut "Error! \"$scope\" has not been registered." 1>&2 exit $EXIT_FAILURE fi # Extract the basename of the app's install directory. This # basename is also used to deploy the app in the console's # repository, where we install the jar to the app's WEB-INF/lib. # getConsoleAppbaseDir getConsoleBaseDir regAppInfo=`getRegAppBy pluginID $scope` dir=`getRegAppValue $regAppInfo path` libdir=${CONSOLE_APPBASE_DIR}/`basename $dir`/WEB-INF/lib if [ ! -d "${libdir}" ]; then printOut "Error! \"${libdir}\" for scope \"$scope\" does not exist." 1>&2 exit $EXIT_FAILURE fi rm -f $libdir/$name >/dev/null 2>&1 if [ $linkFlag -eq 0 ]; then cp $path $libdir/$name chmod 644 $libdir/$name else ln -s $path $libdir/$name fi fi # Create the jar list file if it doesn't exist or if its size is 0 if [ ! -s $CONSOLE_BASE_DIR/$REG_JAR_LIST ]; then doBanner $CONSOLE_BASE_DIR/$REG_JAR_LIST fi # normalize the path so that it gets written out relative to the client. if [ `isNormalizeable ${BASEDIR}` = "1" ]; then path=`$ECHO $path | sed -e "s@^${BASEDIR}/@/@"` fi ## Remove trailing slashes (/) and double slashes (//) from the path path=`$ECHO $path | sed -e 's@/*$@@' -e 's@//*@/@g'` # Append the jar name to the registered jar list, but only if # it does not already exists as registered ujnder the specified # scope. This is to support registration overlays, without having # duplicate entries in the database. # regJarInfo=`getRegJarBy "$scope" "$name"` if [ ! -n "$regJarInfo" ]; then $ECHO "$scope|$name|$path" >> $CONSOLE_BASE_DIR/$REG_JAR_LIST fi } ## end registerJar ################################################################################ # # registerModule # # Registers a login module. The specified login module is added to # the specified login service. Only the intermediate registered_modules # file is changed, not the final JAAS config file - that gets re-written # when the server is restarted based on the content of registered_modules. # # $1 = service type # $2 = LoginModule class name # $3 = behavior # $4, $5, ... = zero or more "name=value" pairs # ################################################################################ registerModule() { service=$1 moduleName=$2 behavior=$3 if [ `inMiniRoot` = "1" ]; then getConsoleInstallDir # Normalize the path so that the command gets written out so that it # resolves relative to the client's runtime. command=${PROGDIR}/${PROGNAME} if [ `isNormalizeable ${BASEDIR}` = "1" ]; then command=`$ECHO $command | sed -e "s@^${BASEDIR}/@/@"` fi # Re-create the original command that got us here in the 1st place. # IMPORTANT: Replace the pattern that signifies where a whitespace # should be, and replace it with a whitespace. Also, enclose the # value part in quotes, being careful not to leave it with pairs of # double quotes in case the value already was enclosed in quotes. # cmd="$command add -m -s $service" while [ -n "$4" ]; do p=`$ECHO ${4} | sed -e "s@$WHITESPACE_KEY_PATTERN@ @" \ -e 's/=/=\"/' -e 's/$/\"/' | sed -e "s/\"\"/\"/g"` cmd="${cmd} -o ${p}" shift done cmd="${cmd} -b ${behavior} ${moduleName}" deferRegistration "$cmd" return fi printOut "Registering login module $moduleName" # Move all options into a single variable. # IMPORTANT: For argument in 'name=value' format, replace the pattern # that signifies that signifies where a whitespace should be, and # replace it with a whitespace. Also, enclose the value part in quotes, # being careful not to leave it with pairs of double quotes in case # the value already was enclosed in quotes. options="" while [ -n "$4" ]; do p=`$ECHO ${4} | sed -e "s@$WHITESPACE_KEY_PATTERN@ @" \ -e 's/=/=\"/' -e 's/$/\"/' | sed -e "s/\"\"/\"/g"` if [ -n "${options}" ]; then options="${options} ${p}" else options=${p} fi shift done getConsoleBaseDir # Read the registered modules file, one line at a time, searching for # a line which matches the specified service and module. If a match is # found, the line is replaced with specified behavior and options. # If no match is found, the module is appended to the registered modules # file. Note that we use a zero-length file as the "flag" to indicate # that a match is found - can't use variables inside the 'while' loop # which is a seperate process. # FILE=$CONSOLE_BASE_DIR/$REG_MODULE_LIST if [ ! -s $FILE ]; then doBanner $FILE fi tmp=${FILE}.$$ found=/tmp/found.$$ rm -f $tmp $found >/dev/null cat $FILE | \ while read line do # Ignore empty lines or lines starting with a comment character. firstChar=`$ECHO $line | awk '{print substr($1, 1, 1)}'` if [ ! -n "${firstChar}" -o "${firstChar}" = "#" ]; then $ECHO $line >> $tmp continue fi # Extract the service and module s=`$ECHO $line | awk -F'|' '{print $1}'` m=`$ECHO $line | awk -F'|' '{print $2}'` # Found it, so replace with new entry. if [ "${s}" = "${service}" -a "${m}" = "${moduleName}" ]; then $ECHO "${service}|${moduleName}|${behavior}|${options}" >> $tmp touch $found continue fi # Keep this one. $ECHO $line >> $tmp done # If not found, append it. if [ ! -f $found ]; then $ECHO "${service}|${moduleName}|${behavior}|${options}" >> $tmp fi # New registered modules file mv $tmp $FILE rm -f $found >/dev/null # Now, there is a requirement at this time that PamLoginModule be the # 1st login module and RbacRoleLoginModule be 2nd. It is possible that # the database might not reflect this, such as after an upgrade, or in # the case where the webconsole was removed but a 3rd-party module was # not unregistered. So we have to re-construct the file such that the # aforementioned ordering is honored. # order=/tmp/order.$$ notorder=/tmp/notorder.$$ rm -f $order $notorder > /dev/null grep PamLoginModule $FILE > $order grep RbacRoleLoginModule $FILE >> $order grep -v PamLoginModule $FILE | grep -v RbacRoleLoginModule | grep -v "^#" > $notorder rm -f $FILE doBanner $FILE cat $order $notorder >> $FILE rm -f $order $notorder > /dev/null } ## registerModule ################################################################################ # # deferRegistration # # Handles management of registrations by deferring actual # registration until the next server restart. We do this by # creating a command script which can be executed on the running client. # But we must implement a scheme to ensure that the script will only run once. # We can do this by timestamping the script, and having the script save it's # timestamp to a file on the client. We have to save the timestamp in this # way because the command script will be created on the /usr partition which # may be read-only at client runtime (eg. diskless clients) and in which case # we may not be able to delete the script after it is run. # # $1 = the registration command to defer # ################################################################################ deferRegistration() { cmd=$1 getConsoleInstallDir # The name of the command script file to which the registration command # is echoed. The script must be unique, so we base it on a date/time # stamp, taking into consideration that consecutive registration commands # could have been requested within a 1-second interval yielding the # same date/time. We solve this by appending a numeric suffix. # DATESTAMP=`date -u +"%Y"%m"%d"%H"%M"%S""` REG_DIR=$CONSOLE_INSTALL_DIR/lib/.reg mkdir -p $REG_DIR NNN=1 script=${REG_DIR}/${DATESTAMP}-${NNN} while [ -s "$script" ]; do NNN=`(expr $NNN + 1)` script="${REG_DIR}/${DATESTAMP}-$NNN" done # Create self-timestamped script cat << \DRPEOF | sed -e "s/_datestamp_/${DATESTAMP}/" \ -e "s/NNN/${NNN}/" > ${script} #!/bin/sh # THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT. DATESTAMP=_datestamp_ REG_DATE=0 REG_DIR=/var/opt/webconsole/.reg REG_DATE_FILE=${REG_DIR}/_datestamp_-NNN if [ -f ${REG_DATE_FILE} ]; then . ${REG_DATE_FILE} fi if [ `expr ${DATESTAMP} \> ${REG_DATE}` = "1" ]; then DRPEOF # Insert the new registration command for this property. $ECHO " $cmd" >> $script # Have command script output its timestamp to a file on the client. $ECHO " mkdir -p \${REG_DIR}" >> $script $ECHO " echo \"REG_DATE=\${DATESTAMP}\" > \${REG_DATE_FILE}" >> ${script} # Finish off 'if' clause that was started above. $ECHO "fi" >> ${script} $ECHO "exit 0" >> ${script} chmod 744 $script } ## deferRegistration ################################################################################ # # registerProperties # # Registers the specified properties. # # $1 = 0 means the properties are server configuration properties that must # be written to the configuration file /etc/opt/webconsole/webconsole. # 1 means the properties are environment properties that must # be written to the environment file /etc/opt/webconsole/.webconsole. # If the property already exists, it will be overwritten. # # $2 = series of name=value pairs. # ################################################################################ registerProperties() { typeFlag=$1 shift 1 if [ `inMiniRoot` = "1" ]; then getConsoleInstallDir # Normalize the path so that the command gets written out so that it # resolves relative to the client's runtime. command=${PROGDIR}/${PROGNAME} if [ `isNormalizeable ${BASEDIR}` = "1" ]; then command=`$ECHO $command | sed -e "s@^${BASEDIR}/@/@"` fi # Re-create the original command that got us here in the 1st place. # IMPORTANT: Replace the pattern that signifies where a whitespace # should be, and replace it with a whitespace. Also, enclose the # value part in quotes, being careful not to leave it with pairs of # double quotes in case the value already was enclosed in quotes. # if [ $typeFlag -eq 0 ]; then cmd="$command add -p -c" else cmd="$command add -p -e" fi while [ -n "$1" ]; do p=`$ECHO ${1} | sed -e "s@$WHITESPACE_KEY_PATTERN@ @g" \ -e 's/=/=\"/' -e 's/$/\"/' | sed -e "s/\"\"/\"/g"` cmd="${cmd} ${p}" shift done deferRegistration "$cmd" else getConsoleConfigDir # The name of the config file in which to add the property if [ $typeFlag -eq 0 ]; then FILE=$CONSOLE_CONFIG_DIR/webconsole title="Server configuration properties" perms=644 else FILE=$CONSOLE_CONFIG_DIR/.webconsole title="Server environment properties" perms=400 fi TMPFILE=${FILE}.$$ rm -f $TMPFILE >/dev/null 2>&1 # Create the config file if it does not exist. if [ ! -s "$FILE" ]; then # Prepend appropriate comment characters to the auto-generated # header, and include optional 2nd line of header. AUTOGENERATEDSTRING="${AUTOGENERATEDSTRING}" doBanner $FILE "### $title ###\n\n" fi propErr=0 numFailure=0; # Process each argument as a name=value pair. while [ -n "$1" ]; do # IMPORTANT: Replace the pattern that signifies where a # whitespace should be, and replace it with a whitespace. p=`$ECHO ${1} | sed -e "s@$WHITESPACE_KEY_PATTERN@ @g"` # Must be in "name=value" format $ECHO ${p} | grep "=" >/dev/null 2>&1 if [ $? -ne 0 ]; then $ECHO "Invalid property format: $p" $ECHO "Properties must be in name=value format" numFailure=`(expr $numFailure + 1)` shift continue fi # Extract name and value name=`$ECHO ${p} | cut -d"=" -f1` value=`$ECHO ${p} | cut -d"=" -f2-` # Environment names cannot have embedded periods (.) if [ $typeFlag -eq 1 ]; then env_check=`$ECHO $name | cut -d"." -f1` if [ "$name" != "$env_check" ]; then $ECHO "Invalid environment property name: $name. \c" $ECHO "No dots (.) allowed." numFailure=`(expr $numFailure + 1)` shift continue fi fi # Property name cannot have embedded spaces if [ `$ECHO $name | wc -w` -gt 1 ]; then $ECHO "Invalid environment property name: $name. No spaces allowed" $ECHO "" numFailure=`(expr $numFailure + 1)` shift continue fi # Make sure name and value are valid if [ ! -n "$name" -o ! -n "$value" ]; then # Show this once, even if multiple props are invalid # because we can't really determine users actual intent. if [ $propErr -eq 0 ]; then $ECHO "Properties must be of the form name=value." $ECHO "Property names cannot contain spaces." $ECHO "If you wish to include spaces in the properties" $ECHO "value, place quotes around the name value pair :" $ECHO " \" name = value data \"" propErr=1 numFailure=`(expr $numFailure + 1)` fi shift continue fi # If the property exists, delete it. sed -e "/^${name}=/d" $FILE > $TMPFILE # Insert property to file $ECHO "${name}=${value}" >> $TMPFILE mv $TMPFILE $FILE chmod $perms $FILE shift done rm -f $TMPFILE >/dev/null 2>&1 if [ $numFailure -ne 0 ]; then exit $EXIT_USAGE 1>&2 fi fi } # registerProperties ################################################################################ # # unregisterJar # # Unregisters the specified jar file from the specified scope. # # $1 = scope under which to register the jar. This can be the # token "ALL", in which case the scope is global and the jar # is shared by all apps. Alternatively, this can be an # application's registered name, which is _, # where and are as specified in the app's web.xml # $2 = the registered name of the library # ################################################################################ unregisterJar() { scope=$1 name=$2 if [ `inMiniRoot` = "1" ]; then getConsoleInstallDir # Normalize the path so that the command gets written out so that it # resolves relative to the client's runtime. command=${PROGDIR}/${PROGNAME} if [ `isNormalizeable ${BASEDIR}` = "1" ]; then command=`$ECHO $command | sed -e "s@^${BASEDIR}/@/@"` fi # Re-create the original command that got us here in the 1st place. # p=$1 if [ `isNormalizeable ${BASEDIR}` = "1" ]; then p=`$ECHO $p | sed -e "s@^${BASEDIR}/@/@"` fi cmd="$command remove -l -s $scope $name" # Defer unregistration, and make it silent in the face of errors, # as there are scenarios during OS upgrades in which outputting an # an error when unregistration fails in 2-stage deployment does not # make sense. Note: this is NOT a public API!. # deferRegistration "env SILENT_REMOVE=true $cmd" # Tomcat 4.x requires the shared lib area to be with the software - that is, # in /usr. Unfortunately if we defer the command to initial server startup, # the client could be diskless, in which case /usr is read-only. To workaround # this, we uninstall the jar now. The original command will still be deferred and # the delete will be attempted again at server startup, and this will silently # fail (See below). # if [ "${scope}" = "ALL" ]; then # Name must include .jar suffix, so add it if not provided. suffix=`$ECHO $name | awk '{i=index($1, ".jar")}{print substr($1, i, length($1)-i+1)}'` if [ $suffix != ".jar" ]; then name=${name}.jar fi # Delete jar from Tomcat's lib directory getTomcatInstallDir rm -f ${TOMCAT_INSTALL_DIR}/lib/$name >/dev/null 2>&1 fi return fi getConsoleAppbaseDir getConsoleBaseDir # if registered jars list doesn't exist, we know it's not registered if [ ! -s $CONSOLE_BASE_DIR/$REG_JAR_LIST ]; then if [ "$SILENT_REMOVE" != "true" ]; then printOut "$1 is not registered!" fi return 1 fi # Name must include .jar suffix, so add it if not provided. suffix=`$ECHO $name | awk '{i=index($1, ".jar")}{print substr($1, i, length($1)-i+1)}'` if [ $suffix != ".jar" ]; then name=${name}.jar fi # Test if jar is actually registered under the specified scope regJarInfo=`getRegJarBy "$scope" "$name"` if [ ! -n "$regJarInfo" ]; then if [ "$SILENT_REMOVE" != "true" ]; then printOut "$name not registered for scope $scope!" 1>&2 fi exit $EXIT_FAILURE fi printOut "Unregistering $name from scope $scope" if [ "${scope}" = "ALL" ]; then getTomcatInstallDir # It is possible Tomcat could be located on a shared read-only # filesystem. On Solaris this could be within a zone. So # only remove the jar if we have write access to the Tomcat area. # tiptoe=$TOMCAT_INSTALL_DIR/_.$$ touch $tiptoe >/dev/null 2>&1 if [ $? -eq 0 ]; then rm -f $tiptoe # Delete jar from Tomcat's lib directory if [ "${OS}" = "AIX" ]; then rm -f ${TOMCAT_INSTALL_DIR}/shared/lib/$name >/dev/null 2>&1 else rm -f ${TOMCAT_INSTALL_DIR}/lib/$name >/dev/null 2>&1 fi fi else # Scope is reference to registered app. It must already be registered. isAppRegistered $scope if [ $? -eq 1 ]; then if [ "$SILENT_REMOVE" != "true" ]; then printOut "Error! \"$scope\" has not been registered." 1>&2 fi exit $EXIT_FAILURE fi # Extract the basename of the app's install directory. This # basename is also used to deploy the app in the console's # repository, where we delete the jar from the app's WEB-INF/lib. # getConsoleAppbaseDir getConsoleBaseDir regAppInfo=`getRegAppBy pluginID $scope` dir=`getRegAppValue $regAppInfo path` dir=${CONSOLE_APPBASE_DIR}/`basename $dir` rm -f $dir/WEB-INF/lib/$name >/dev/null 2>&1 fi # Now update the list of registered jars removeRegJarBy $scope $name } ## end unregisterJar ################################################################################ # # unregisterApp # # Unregister the specified application. # # $1 = the registered name of the application # ################################################################################ unregisterApp() { name=$1 if [ `inMiniRoot` = "1" ]; then getConsoleInstallDir # Normalize the path so that the command gets written out so that it # resolves relative to the client's runtime. command=${PROGDIR}/${PROGNAME} if [ `isNormalizeable ${BASEDIR}` = "1" ]; then command=`$ECHO $command | sed -e "s@^${BASEDIR}/@/@"` fi # Re-create the original command that got us here in the 1st place. # p=$1 if [ `isNormalizeable ${BASEDIR}` = "1" ]; then p=`$ECHO $p | sed -e "s@^${BASEDIR}/@/@"` fi cmd="$command remove -a $p" # Defer unregistration, and make it silent in the face of errors, # as there are scenarios during OS upgrades in which outputting an # an error when unregistration fails in 2-stage deployment does not # make sense. Note: this is NOT a public API!. # deferRegistration "env SILENT_REMOVE=true $cmd" return fi printOut "Unregistering $name." getConsoleBaseDir getConsoleAppbaseDir # Check for remove by context and remove the app # from the appbase directory. regAppInfo=`getRegAppBy context $name` if [ -n "$regAppInfo" ]; then dir=`getRegAppValue $regAppInfo path` dir=${CONSOLE_APPBASE_DIR}/`basename $dir` rm -rf $dir >/dev/null 2>&1 removeRegAppBy context $name return fi # Check for remove by pluginID and remove the app # from the appbase directory. regAppInfo=`getRegAppBy pluginID $name` if [ -n "$regAppInfo" ]; then dir=`getRegAppValue $regAppInfo path` dir=${CONSOLE_APPBASE_DIR}/`basename $dir` rm -rf $dir >/dev/null 2>&1 removeRegAppBy pluginID $name return fi # Shouldn't get here unless app was not already registered. if [ "$SILENT_REMOVE" != "true" ]; then printOut "Error! \"$name\" has not been registered." 1>&2 exit $EXIT_FAILURE fi } ## end unregisterApp ################################################################################ # # unregisterModule # # Unregisters a login module. The specified login module is removed from # the specified login service. Only the intermediate registered_modules # file is changed, not the final JAAS config file - that gets re-written # when the server is restarted based on the content of registered_modules. # # $1 = service type # $2 = LoginModule class name # ################################################################################ unregisterModule() { service=$1 moduleName=$2 if [ `inMiniRoot` = "1" ]; then getConsoleInstallDir # Normalize the path so that the command gets written out so that it # resolves relative to the client's runtime. command=${PROGDIR}/${PROGNAME} if [ `isNormalizeable ${BASEDIR}` = "1" ]; then command=`$ECHO $command | sed -e "s@^${BASEDIR}/@/@"` fi # Re-create the original command that got us here in the 1st place. # cmd="$command remove -m -s $service $moduleName" deferRegistration "$cmd" return fi printOut "Unregistering login module $moduleName." getConsoleBaseDir # Read the registered modules file, one line at a time, tossing out # all lines which match the specified service and module and writing # everything else to a tmp file, which then becomes the new # registered modules. # FILE=$CONSOLE_BASE_DIR/$REG_MODULE_LIST tmp=${FILE}.$$ rm -f $tmp >/dev/null cat $FILE | \ while read line do # Ignore empty lines or lines starting with a comment character. firstChar=`$ECHO $line | awk '{print substr($1, 1, 1)}'` if [ ! -n "${firstChar}" -o "${firstChar}" = "#" ]; then $ECHO $line >> $tmp continue fi # Extract the service and module s=`$ECHO $line | awk -F'|' '{print $1}'` m=`$ECHO $line | awk -F'|' '{print $2}'` # Found it, so ignore it if [ "${s}" = "${service}" -a "${m}" = "${moduleName}" ]; then continue fi # Keep this one. $ECHO $line >> $tmp done # New registered modules file mv $tmp $FILE } ## unregisterModule ################################################################################ # # unregisterProperties # # Unregisters the specified properties. # # $1 = 0 means the properties are server configuration properties that must # be deleted from the configuration file /etc/opt/webconsole/webconsole. # 1 means the properties are environment properties that must # be deleted from the environment file /etc/opt/webconsole/.webconsole. # If the property does not exist, who cares! # # $2 = series of named properties # ################################################################################ unregisterProperties() { typeFlag=$1 shift 1 if [ `inMiniRoot` = "1" ]; then getConsoleInstallDir # Normalize the path so that the command gets written out so that it # resolves relative to the client's runtime. command=${PROGDIR}/${PROGNAME} if [ `isNormalizeable ${BASEDIR}` = "1" ]; then command=`$ECHO $command | sed -e "s@^${BASEDIR}/@/@"` fi # Re-create the original command that got us here in the 1st place. # if [ $typeFlag -eq 0 ]; then cmd="$command remove -p -c $*" else cmd="$command remove -p -e $*" fi deferRegistration "$cmd" else getConsoleConfigDir # The name of the config file from which to remove the property if [ $typeFlag -eq 0 ]; then FILE=$CONSOLE_CONFIG_DIR/webconsole title="Server configuration properties" perms=644 else FILE=$CONSOLE_CONFIG_DIR/.webconsole title="Server environment properties" perms=400 fi # If the file does not exist, no property to delete. if [ ! -s "$FILE" ]; then return fi TMPFILE=${FILE}.$$ rm -f $TMPFILE >/dev/null 2>&1 numFailure=0; # Process each argument as a property name. while [ -n "$1" ]; do name=$1 # Property names cannot have equals (=) $ECHO $1 | grep "[=]" >/dev/null 2>&1 if [ $? -eq 0 ]; then $ECHO "Invalid property name: $name. \c" $ECHO "No equals (=) allowed." numFailure=`(expr $numFailure + 1)` shift continue fi # Environment names cannot have embedded periods (.) if [ $typeFlag -eq 1 ]; then env_check=`$ECHO $name | cut -d"." -f1` if [ "$name" != "$env_check" ]; then $ECHO "Invalid environment property name: $name. \c" $ECHO "No dots (.) allowed." numFailure=`(expr $numFailure + 1)` shift continue fi fi # If the property exists, delete it. sed -e "/^${name}=/d" $FILE > $TMPFILE mv $TMPFILE $FILE chmod $perms $FILE shift done rm -f $TMPFILE >/dev/null 2>&1 if [ $numFailure -ne 0 ]; then exit $EXIT_USAGE 1>&2 fi fi } # unregisterProperties ################################################################################ # # checkForServletTags # # Check to make sure the app has the correct servlet tags for the # specified servlet. # # $1 = the full path (including filename) of the web.xml file # $2 = servlet name # $3 = servlet class # $4 = servlet URL # # Returns a pair of boolean string values (either "true" or "false"), to # to indicate whether the and tags for specified # servlet should be added to the web.xml. # ################################################################################ checkForServletTags() { ## ## Check for an existing web.xml file. ## WEB_XML=$1 if [ ! -s $WEB_XML ]; then printOut "Error! \"$WEB_XML\" does not exist." 1>&2 exit $EXIT_FAILURE fi SERVLET_NAME=$2 SERVLET_CLASS=$3 SERVLET_URL=$4 # Flags that indicate whether or not servlet tags should be added to # the web.xml file. We assume true both and prove otherwise. add_servlet=true add_servlet_mapping=true ## ## Enforce that the starting char sequence of a comment is preceeded with ## white space, and the ending char sequence is followed by white space. ## Also, enforcing that this will ensure that each comment beginning and ## ending will be treated as a word separate from the tags in the file. ## WEB_XML_CONTENT=`cat $WEB_XML \ | sed -e 's@@--> @g' -e 's@><@> <@g'` for word in $WEB_XML_CONTENT; do case $word in "" ) IN_COMMENT="false" ;; $SERVLET_START_TAG* ) IN_SERVLET_TAG="true" ;; $SERVLET_END_TAG* ) IN_SERVLET_TAG="false" ## Check the contents of the servlet-name and servlet-class ## tags here. if [ "$SERVLET_NAME_CONTENT" = "$SERVLET_NAME" \ -a "$SERVLET_CLASS_CONTENT" = "$SERVLET_CLASS" ]; then add_servlet=false fi ;; $SERVLET_MAPPING_START_TAG* ) IN_SERVLET_MAPPING_TAG="true" ;; $SERVLET_MAPPING_END_TAG* ) IN_SERVLET_MAPPING_TAG="false" ## Check the contents of the servlet-name and url-pattern \ ## tags here. if [ "$SERVLET_NAME_CONTENT" = "$SERVLET_NAME" \ -a "$URL_PATTERN_CONTENT" = "$SERVLET_URL" ]; then add_servlet_mapping=false fi ;; $URL_PATTERN_START_TAG* ) [ "$IN_COMMENT" = "true" ] && continue [ "$IN_SERVLET_MAPPING_TAG" != "true" ] && continue ## Attempt to extract the url-pattern content from the line. URL_PATTERN_CONTENT=`$ECHO $word \ | sed -e 's@.*'$URL_PATTERN_START_TAG'@@' \ | sed -e 's@'$URL_PATTERN_END_TAG'.*@@' \ | sed -e 's@\"@@g' -e "s@^\'@@"` ## ## If URL_PATTERN_CONTENT is not empty, we have our data. Otherwise, ## the start/end tags and tag content span multiple "words". Set ## a flag to indicate the tag content will be the next word read. ## if [ "$URL_PATTERN_CONTENT" = "" ]; then URL_PATTERN_START_TAG_FOUND="true" fi ## ;; $SERVLET_NAME_START_TAG* ) [ "$IN_COMMENT" = "true" ] && continue [ "$IN_SERVLET_TAG" != "true" \ -a "$IN_SERVLET_MAPPING_TAG" != "true" ] && continue ## Attempt to extract the servlet-name content from the line. SERVLET_NAME_CONTENT=`$ECHO $word \ | sed -e 's@.*'$SERVLET_NAME_START_TAG'@@' \ | sed -e 's@'$SERVLET_NAME_END_TAG'.*@@' \ | sed -e 's@\"@@g' -e "s@^\'@@"` ## ## If SERVLET_NAME_CONTENT is not empty, we have our data. Otherwise, ## the start/end tags and tag content span multiple "words". Set ## a flag to indicate the tag content will be the next word read. ## if [ "$SERVLET_NAME_CONTENT" = "" ]; then SERVLET_NAME_START_TAG_FOUND="true" fi ## ;; $SERVLET_CLASS_START_TAG* ) [ "$IN_COMMENT" = "true" ] && continue [ "$IN_SERVLET_TAG" != "true" ] && continue ## Attempt to extract the servlet-class content from the line. SERVLET_CLASS_CONTENT=`$ECHO $word \ | sed -e 's@.*'$SERVLET_CLASS_START_TAG'@@' \ | sed -e 's@'$SERVLET_CLASS_END_TAG'.*@@' \ | sed -e 's@\"@@g' -e "s@^\'@@"` ## ## If SERVLET_CLASS_CONTENT is not empty, we have our data. Otherwise, ## the start/end tags and tag content span multiple "words". Set ## a flag to indicate the tag content will be the next word read. ## if [ "$SERVLET_CLASS_CONTENT" = "" ]; then SERVLET_CLASS_START_TAG_FOUND="true" fi ;; * ) [ "$IN_COMMENT" = "true" ] && continue ## ## We're in the middle of reading in the servlet-name content. The ## next word will be the content. ## if [ "$SERVLET_NAME_START_TAG_FOUND" = "true" ]; then SERVLET_NAME_CONTENT=`$ECHO $word \ | sed -e 's@'$SERVLET_NAME_END_TAG'.*@@' \ | sed -e 's@\"@@g' -e "s@^\'@@"` SERVLET_NAME_START_TAG_FOUND="false" fi ## ## We're in the middle of reading in the servlet-class content. The ## next word will be the content. ## if [ "$SERVLET_CLASS_START_TAG_FOUND" = "true" ]; then SERVLET_CLASS_CONTENT=`$ECHO $word \ | sed -e 's@'$SERVLET_CLASS_END_TAG'.*@@' \ | sed -e 's@\"@@g' -e "s@^\'@@"` SERVLET_CLASS_START_TAG_FOUND="false" fi ## ## We're in the middle of reading in the url-pattern content. The ## next word will be the content. ## if [ "$URL_PATTERN_START_TAG_FOUND" = "true" ]; then URL_PATTERN_CONTENT=`$ECHO $word \ | sed -e 's@'$URL_PATTERN_END_TAG'.*@@' \ | sed -e 's@\"@@g' -e "s@^\'@@"` URL_PATTERN_START_TAG_FOUND="false" fi ;; esac done echo "$add_servlet $add_servlet_mapping" } ## end checkForServletTags ################################################################################ # # addServletTags # # Add the servlet and servlet-mapping tags required by the console to the app's # web.xml file. The final web.xml will be printed to stdout, and can be # redirected to another file to save the output. # # NOTE: the checkForServletTags function should be called before this one to be # sure that we actually need to add the tags. # # $1 = the full path (including filename) of the web.xml file # $2 = true or false, indicates whether the tag for the # specified servlet should be added to the web.xml file. # $3 = true or false, indicates whether the tag for the # specified servlet should be added to the web.xml file. # $4 = servlet name # $5 = servlet class # $6 = servlet URL # ################################################################################ addServletTags() { # If both tags already exist, then nothing to do. if [ "${2}" = "false" -a "${3}" = "false" ]; then return fi SERVLET_NAME=$4 SERVLET_CLASS=$5 SERVLET_URL=$6 ## ## Write out the new web.xml file with the servlet and servlet-mapping tags ## for servlet inserted in the designated place. NOTE: The 'sed' ## statement below performs the following task: if a end tag/comment ## char ">" and a start tag/comment char "<" occur on the same line, force ## them onto two separate lines. This helps ensure that the servlet and ## servlet-mapping tags don't get inserted in a weird place. ## WEB_XML_FILE=$1 TMP_WEBXML=${WEB_XML_FILE}.$$ rm ${TMP_WEBXML} >/dev/null 2>&1 touch ${TMP_WEBXML} sed -e 's/> */>/g' -e 's/>\ / { IN_COMMENT="false" } // { } // { } // { } // { } // { } // { } // { } // { } // { } // { ADD_SERVLET_TAG="'${2}'"; } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } // { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } /<\/web-app>/ { ADD_SERVLET_TAG="'${2}'"; ADD_SERVLET_MAPPING_TAG="'${3}'" } ############################################################################ # # This function adds the servlet components tag required by the # console to the web.xml file in the required location. # ############################################################################ function addServletTag() { print " " print " '$SERVLET_NAME'" print " " print " '$SERVLET_CLASS'" print " " print " " } ## end addServletTag ############################################################################ # # This function adds the application tag required by the # console to the web.xml file in the required location. # ############################################################################ function addServletMappingTag() { print " " print " '$SERVLET_NAME'" print " '$SERVLET_URL'" print " " } ## end addServletMappingTag ############################################################################ # # main function # ############################################################################ { ## Add in our servlet tag if they have not been added already if (ADD_SERVLET_TAG == "true") { if (SERVLET_ADDED != "true") { if (IN_COMMENT == "true") { print print "-->" } addServletTag() SERVLET_ADDED="true" if (IN_COMMENT == "true") { print "" } addServletMappingTag() SERVLET_MAPPING_ADDED="true" if (IN_COMMENT == "true") { print "/--> /g' -e 's/> /\" >/'` for word in $APP_XML_CONTENT; do case $word in "" ) IN_COMMENT="false" ;; $REGINFO_START_TAG* ) [ "$IN_COMMENT" = "true" ] && continue IN_REGINFO_TAG="true" ;; $VERSION_ATTR | $VERSION_ATTR=* ) [ "$IN_COMMENT" = "true" ] && continue [ "$IN_REGINFO_TAG" != "true" ] && continue reginfoVersionFound=1 ## The version attribute value may contain the string "version" if [ "$APP_VERSION" != "" -o "$IN_VERSION" = "true" ]; then getVersion $word continue fi ## ## Remove the "version" attribute name and the equal sign. If there ## is still info to parse, call getVersion. Otherwise, set a flag to ## indicate we're in the middle of parsing. ## TMP_APP_VERSION=`$ECHO $word \ | sed -e "s/^$VERSION_ATTR//" \ | sed -e 's/^=//'` if [ "$TMP_APP_VERSION" != "" ]; then getVersion $TMP_APP_VERSION if [ "$IN_VERSION" != "true" ]; then break fi else IN_VERSION="true" fi ;; * ) [ "$IN_COMMENT" = "true" ] && continue if [ "$IN_REGINFO_TAG" = "true" ]; then if [ $reginfoVersionFound -eq 0 ]; then break fi fi ## ## We're in the middle of reading in the version word(s). Continue ## to read words until a closing quote is read. ## if [ "$IN_VERSION" = "true" ]; then getVersion $word if [ "$IN_VERSION" != "true" ]; then break fi break fi ;; esac done # Make sure the tag includes a version attribute specification. if [ $reginfoVersionFound -eq 0 ]; then printOut "Error! The registrationInfo \"$VERSION_ATTR\" attribute element not found in $appxml." 1>&2 exit $EXIT_FAILURE fi SDK_VERSION=$APP_VERSION if [ ! -n "$SDK_VERSION" ]; then printOut "Error! The registrationInfo \"$VERSION_ATTR\" attribute value has not been specified in $appxml." 1>&2 exit $EXIT_FAILURE fi if [ `versionString2Num $SDK_VERSION` -lt 21000 ]; then SDK_VERSION="2.0" fi # Since these are global, used by getVersion() when invoked for other # version tags, reset them to initial states. APP_VERSION="" IN_VERSION="" } ## extractSDKversion ################################################################################ # # extractPluginName # # Extract the pluginName from the registration descriptor file and save the # name into PLUGIN_NAME. # # $1 = path to application descriptor file # ################################################################################ extractPluginName() { appxml=$1 ## ## Enforce that the starting char sequence of a comment is preceeded with white ## space, and the ending char sequence is followed by white space. This will ## ensure that each comment beginning and ending will be treated as a word ## separate from the tags in the file. ## APP_XML_CONTENT=`cat $appxml | sed -e 's//--> /g' -e 's/> " ) IN_COMMENT="false" ;; $MANAGEMENTAPP_START_TAG* ) [ "$IN_COMMENT" = "true" ] && continue IN_MANAGEMENT_APP_TAG="true" ;; $VERSION_ATTR | $VERSION_ATTR=* ) [ "$IN_COMMENT" = "true" ] && continue [ "$IN_MANAGEMENT_APP_TAG" != "true" ] && continue ## The version attribute value may contain the string "version" if [ "$APP_VERSION" != "" -o "$IN_VERSION" = "true" ]; then getVersion $word continue fi ## ## Remove the "version" attribute name and the equal sign. If there ## is still info to parse, call getVersion. Otherwise, set a flag to ## indicate we're in the middle of parsing. ## TMP_APP_VERSION=`$ECHO $word \ | sed -e "s/^$VERSION_ATTR//" \ | sed -e 's/^=//'` if [ "$TMP_APP_VERSION" != "" ]; then getVersion $TMP_APP_VERSION else IN_VERSION="true" fi ;; $PLUGIN_NAME_START_TAG* ) [ "$IN_COMMENT" = "true" ] && continue [ "$IN_MANAGEMENT_APP_TAG" != "true" ] && continue ## Attempt to extract the plugin name from the line. PLUGIN_NAME=`$ECHO $word \ | sed -e 's/.*'$PLUGIN_NAME_START_TAG'//' \ | sed -e 's/'$PLUGIN_NAME_END_TAG'.*//' \ | sed -e 's/\"//g' -e "s/^\'//"` ## ## If PLUGIN_NAME is not empty, we have our data. Otherwise, the ## start/end tags and tag content span multiple "words". Set a flag ## to indicate the tag content will be the next word read. ## if [ "$PLUGIN_NAME" != "" ]; then TMP_PLUGIN_NAME=${PLUGIN_NAME}_${APP_VERSION} PLUGIN_NAME=$TMP_PLUGIN_NAME else PLUGIN_START_TAG_FOUND="true" fi ;; * ) [ "$IN_COMMENT" = "true" ] && continue ## ## We're in the middle of reading in the version word(s). Continue ## to read words until a closing quote is read. ## if [ "$IN_VERSION" = "true" ]; then getVersion $word continue fi ## ## We're in the middle of reading in the pluginName content. The ## next word will be the content. ## if [ "$PLUGIN_START_TAG_FOUND" = "true" ]; then PLUGIN_NAME=`$ECHO $word \ | sed -e 's/'$PLUGIN_NAME_END_TAG'.*//' \ | sed -e 's/\"//g' -e "s/^\'//"` TMP_PLUGIN_NAME=${PLUGIN_NAME}_${APP_VERSION} PLUGIN_NAME=$TMP_PLUGIN_NAME PLUGIN_START_TAG_FOUND="false" fi ;; esac done ## Check the plugin name for validity. Format: _ if [ "$PLUGIN_NAME" = "" ]; then printOut "Error! The managementApp \"$VERSION_ATTR\" attribute and \"pluginName\" element values could not be determined." 1>&2 exit $EXIT_FAILURE fi $ECHO $PLUGIN_NAME | grep "_" >/dev/null if [ $? -ne 0 ]; then printOut "Error! The managementApp \"$VERSION_ATTR\" attribute and \"pluginName\" element values could not be determined." 1>&2 exit $EXIT_FAILURE fi tmp=`$ECHO $PLUGIN_NAME | sed -e 's/_.*//'` if [ "$tmp" = "" ]; then printOut "Error! The \"pluginName\" element value has not been specified in the application descriptor file." 1>&2 exit $EXIT_FAILURE fi tmp=`$ECHO $PLUGIN_NAME | sed -e 's/.*_//'` if [ "$tmp" = "" ]; then printOut "Error! The managementApp \"$VERSION_ATTR\" attribute value has not been specified in the application descriptor file." 1>&2 exit $EXIT_FAILURE fi # Since these are global, used by getVersion() when invoked for other # version tags, reset them to initial states. APP_VERSION="" IN_VERSION="" } ## end extractPluginName ################################################################################ # # getVersion # # This function extracts the managementApp tag's version attribute value. The # version may be formatted in several ways: # version="1.0beta" # version="1.0 beta" # version = "1.0beta" # version=" 1.0 beta " # # This function handles all types of input by removing the equal sign, and # reading (perhaps over several calls to this function) the value(s) contained # within the quotes. The final version is concatenated into a single word if # necessary, and stored in the VERSION variable. # # $1 = the version value to extract, or the portion of the value # # Outputs 2 global variables: # IN_VERSION = tells whether we are still in the middle of extracting # the version value. # APP_VERSION = the (possibly not fully extracted) version value. # # It is VERY important that users of this function reset these variable # to empty strings when they are done extracting the value of their # version tag!!! # ################################################################################ # A "static" variable, private to this function. STRIPPED_FIRST_QUOTE="" getVersion() { versionArg=$1 ## ## Strip off the equal sign, if it exists. Also globally replace ## all instances of single-quote with double-quote, as some OS ## sed implementations have trouble with end-of-line edit patterns ## involving the single-quote. ## versionArg=`$ECHO $versionArg | sed -e 's/^=//' -e "s/'/\"/g"` ## ## Strip off the opening quote (make sure this is only done once) ## if [ "$STRIPPED_FIRST_QUOTE" != "true" ]; then firstChar=`$ECHO $versionArg | awk '{print substr($1, 1, 1)}'` if [ "${firstChar}" = "\"" -o "${firstChar}" = "\'" ]; then versionArg=`$ECHO $versionArg | sed -e 's/^\"//' -e "s/^\'//"` STRIPPED_FIRST_QUOTE="true" fi fi ## ## If the remaining word is a quote only (that is, the closing quote if we ## have made it this far), end the search for APP_VERSION ## if [ "$versionArg" = "\"" -o "$versionArg" = "'" ]; then IN_VERSION="false" STRIPPED_FIRST_QUOTE="" return fi ## ## Ignore the versionArg if it only contains: = ## if [ "$versionArg" = "" ]; then IN_VERSION="true" STRIPPED_FIRST_QUOTE="" return fi ## ## If the version continues over more than 1 word (ie "1.0 beta"), save what ## we have and continue until we find the closing quote. NOTE: This format ## will result in the words being concatenated to "1.0beta". ## lastChar=`$ECHO $versionArg | awk '{print substr($1, length($1), 1)}'` if [ "${lastChar}" != "\"" -a "${lastChar}" != "\'" ]; then APP_VERSION=${APP_VERSION}${versionArg} IN_VERSION="true" return fi APP_VERSION=${APP_VERSION}`$ECHO $versionArg | sed -e 's/\".*//'` IN_VERSION="false" STRIPPED_FIRST_QUOTE="" } ## end getVersion ################################################################################ # # checkForFilterTags # # Check to make sure the app has the correct filter tags. # # $1 = the full path to (including filename) web.xml, or app directory # # Return 0 if it has the correct tags, 1 otherwise # ################################################################################ checkForFilterTags() { path=$1 ## Remove trailing slashes (/) and double slashes (//) from the directory path=`$ECHO $path | sed 's/\/*$//' | sed 's/\/\/*/\//g'` ## Append WEB-INF/web.xml if just given path to app if [ -d "${path}" ]; then WEB_XML=${path}/WEB-INF/web.xml else WEB_XML=${path} fi ## ## Check for an existing web.xml file ## if [ ! -s $WEB_XML ]; then printOut "Error! \"$WEB_XML\" does not exist." 1>&2 exit $EXIT_FAILURE fi ## ## Enforce that the starting char sequence of a comment is preceeded with white ## space, and the ending char sequence is followed by white space. Also, enforcing ## that This will ## ensure that each comment beginning and ending will be treated as a word ## separate from the tags in the file. ## WEB_XML_CONTENT=`cat $WEB_XML | sed -e 's//--> /g' -e 's/> " ) IN_COMMENT="false" ;; $FILTER_START_TAG* ) IN_FILTER_TAG="true" ;; $FILTER_END_TAG* ) IN_FILTER_TAG="false" ## Check the contents of the filter-name and filter-class tags here if [ "$FILTER_NAME_CONTENT" = "$APP_FILTER_NAME" -a "$FILTER_CLASS_CONTENT" = "$APP_FILTER_CLASS" ]; then return 0 fi if [ "$FILTER_NAME_CONTENT" = "$CONSOLE_FILTER_NAME" -a "$FILTER_CLASS_CONTENT" = "$CONSOLE_FILTER_CLASS" ]; then return 0 fi ;; $FILTER_NAME_START_TAG* ) [ "$IN_COMMENT" = "true" ] && continue [ "$IN_FILTER_TAG" != "true" ] && continue ## Attempt to extract the filter-name content from the line. FILTER_NAME_CONTENT=`$ECHO $word \ | sed -e 's/.*'$FILTER_NAME_START_TAG'//' \ | sed -e 's/'$FILTER_NAME_END_TAG'.*//' \ | sed -e 's/\"//g' -e "s/^\'//"` ## ## If FILTER_NAME_CONTENT is not empty, we have our data. Otherwise, the ## start/end tags and tag content span multiple "words". Set a flag ## to indicate the tag content will be the next word read. ## if [ "$FILTER_NAME_CONTENT" = "" ]; then FILTER_NAME_START_TAG_FOUND="true" fi ;; $FILTER_CLASS_START_TAG* ) [ "$IN_COMMENT" = "true" ] && continue [ "$IN_FILTER_TAG" != "true" ] && continue ## Attempt to extract the filter-class content from the line. FILTER_CLASS_CONTENT=`$ECHO $word \ | sed -e 's/.*'$FILTER_CLASS_START_TAG'//' \ | sed -e 's/'$FILTER_CLASS_END_TAG'.*//' \ | sed -e 's/\"//g' -e "s/^\'//"` ## ## If FILTER_CLASS_CONTENT is not empty, we have our data. Otherwise, the ## start/end tags and tag content span multiple "words". Set a flag ## to indicate the tag content will be the next word read. ## if [ "$FILTER_CLASS_CONTENT" = "" ]; then FILTER_CLASS_START_TAG_FOUND="true" fi ;; * ) [ "$IN_COMMENT" = "true" ] && continue ## ## We're in the middle of reading in the filter-name content. The ## next word will be the content. ## if [ "$FILTER_NAME_START_TAG_FOUND" = "true" ]; then FILTER_NAME_CONTENT=`$ECHO $word \ | sed -e 's/'$FILTER_NAME_END_TAG'.*//' \ | sed -e 's/\"//g' -e "s/^\'//"` FILTER_NAME_START_TAG_FOUND="false" fi ## ## We're in the middle of reading in the filter-class content. The ## next word will be the content. ## if [ "$FILTER_CLASS_START_TAG_FOUND" = "true" ]; then FILTER_CLASS_CONTENT=`$ECHO $word \ | sed -e 's/'$FILTER_CLASS_END_TAG'.*//' \ | sed -e 's/\"//g' -e "s/^\'//"` FILTER_CLASS_START_TAG_FOUND="false" fi ;; esac done return 1 } ## end checkForFilterTags ################################################################################ # # addFilterTags # # Add the filter and filter-mapping tags required by the console to the app's # web.xml file. The final web.xml will be printed to stdout, and can be # redirected to another file to save the output. # # NOTE: the checkForFilterTags function should be called before this one to be # sure that we actually need to add the tags. # # $1 = the full path to (including filename) web.xml, or app directory # ################################################################################ addFilterTags() { WEB_XML_FILE=$1 ## Remove trailing slashes (/) and double slashes (//) from the directory WEB_XML_FILE=`$ECHO $WEB_XML_FILE | sed 's/\/*$//' | sed 's/\/\/*/\//g'` ## Append WEB-INF/web.xml if just given path to app if [ -d "${WEB_XML_FILE}" ]; then WEB_XML_FILE=${WEB_XML_FILE}/WEB-INF/web.xml fi ## ## Check for an existing web.xml file ## if [ ! -s $WEB_XML_FILE ]; then printOut "Error! \"$WEB_XML_FILE\" does not exist." 1>&2 exit $EXIT_FAILURE fi ## ## ## Write out the new web.xml file with the filter and filter-mapping tags ## inserted in the designated place. NOTE: The 'sed' statement below ## performs the following task: if a end tag/comment char ">" and a start ## tag/comment char "<" occur on the same line, force them onto two separate ## lines. This helps ensure that the filter and filter-mapping tags don't ## get inserted in a weird place. ## sed -e 's/> */>/g' -e 's/>\ / { IN_COMMENT="false" } // { } // { } // { } // { } // { } // { } // { ADD_FILTER_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } // { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } /<\/web-app>/ { ADD_FILTER_TAG="true"; ADD_FILTER_MAPPING_TAG="true" } ################################################################################ # # This function adds the application tag required by the console to the # web.xml file in the required location. # ################################################################################ function addFilterTag() { print " " print " '$APP_FILTER_NAME'" print " " print " '$APP_FILTER_CLASS'" print " " print " " print " ignore-paths" print " " print " /images/*" print " " print " " print " " } ## end addFilterTag ################################################################################ # # This function adds the application tag required by the # console to the web.xml file in the required location. # ################################################################################ function addFilterMappingTag() { print " " print " '$APP_FILTER_NAME'" print " /*" print " " } ## end addFilterMappingTag ################################################################################ # # main function # ################################################################################ { ## Add in our filter tag if they have not been added already if (ADD_FILTER_TAG == "true") { if (FILTER_ADDED != "true") { if (IN_COMMENT == "true") { print print "-->" } addFilterTag() FILTER_ADDED="true" if (IN_COMMENT == "true") { print "" } addFilterMappingTag() FILTER_MAPPING_ADDED="true" if (IN_COMMENT == "true") { print "