2.22.2007

Work { Java DST upgrade script

The change in Daylight Savings Time caused by the Energy Policy Act of 2005 has resulted in nightmare conditions for some in Information Technology as almost every operating system required a patch of some kind in order to correctly adjust for the new DST rules. Many apps (most noteably Exchange) also require patching. Those that cannot be patched have to be upgraded or work around have to be put into place. Java is one of those Apps. More information regarding Java can be found at http://www.sun.com/dst. To make my life a little easier I wrote the script below to aid my efforts to patch/upgrade the system JRE and the Symantec/Veritas JREs on Solaris systems. Its not as clean as I would like and there are many improvements I would do as well as streamline some of the logic.

#!/bin/ksh

# java_dst.ksh ###
# author: Me
#version: 1.1
#purpose: to automatically find/update JAVA JREs on Solaris hosts
# and catalog completed and unsupported JRE instances.
###

###
# changelog:
# 20070215 me: streamlined script/debugged
# added find/update for /usr/openv/java
# 20070214 me: script debugging
# 20070211 me: script creation
#
###
# peer review:
# 20070214 co-worker1
# 20070215 co-worker2
#
###


###
# PATHS
###
PATH=/usr/bin:/usr/sbin
export PATH

###
# global variables
###
# base directory where script runs
case $0 in
"./java_dst.ksh") BASE=$(pwd) ;;
*) echo "WARNING! This script needs to be executed from the directory in which it resides, otherwise the script will not work."
exit 1 ;;
esac
export BASE

TZUPDATE=${BASE}/tzupdater2006p/tzupdater.jar
JRE15SRC=${BASE}/jre1.5.0_11
JRE15=jre1.5.0_11
SYSJRE=/usr/java

if [ -x ${SYSJRE}/bin/java ]; then
PATH=${SYSJRE}/bin:${PATH}
export PATH
else
echo "WARNING! No system JRE defined as ${SYSJRE}! Please investigate."
ls -ltard ${SYSJRE}
exit 1
fi
MASTERDIR=${BASE}/log
ISSUEHOSTSLOG=${MASTERDIR}/issue_hosts.log
UPDATEDHOSTLOG=${MASTERDIR}/updated_host_list.log
export BASE TZUPDATE JRE15SRC SYSJRE JRE15 MASTERCATALOG ISSUEHOSTSLOG UPDATEDHOSTLOG

###
# intro
###
echo "This script will scan the target host for installed JREs in /usr and /opt."
echo "This script will also update any JREs found with the '-u' option."
echo " "



###
# functions() {}
###

find_jre() {
# find installed JREs on system and catalog them

JRECATALOG=/var/tmp/$(uname -n)-jre_catalog.out
JREVEROUT=/var/tmp/$(uname -n)-jre_versions.out

OPTS=$1
# better search string, will not cross mount points or non-local file systems,
# will not also exec the version option on the java installs found, will
# elmininate sparcv9 (64-bit) entries as they are duplicitous
echo "Searching for installed JREs in /usr and /opt..."

find /usr /opt -local -xdev -type f -perm -o+x -name java -print -o -name sparcv9 -prune >${JRECATALOG}


# catalog the version of the JREs found, for documentation purposes
echo "Cataloging installed JRE locations and version..."
echo "Versions will be saved in: ${JREVEROUT}"
echo "Installed JREs found will be saved in: ${JRECATALOG}"

# initialize version output log
echo "">${JREVEROUT}

for x in $(cat ${JRECATALOG})
do
(
echo "${x}"
${x} -version 2>&1
) >>${JREVEROUT}
done
echo "done."

# update the master catalog with JREs installed on system for future
# reference
if [ "${OPTS}" = "B" ]; then
echo "Copying ${JREVEROUT} to ${MASTERDIR}..."
cp ${JREVEROUT} ${MASTERDIR}/
echo "done."

else
echo "Note: ${JREVEROUT} will not be copied to ${MASTERDIR} unless the '-u' option is specified."
fi
}

install_jre() {
# install JRE 1.5.0_11 on target host, re-link /usr/java to new JRE.
# JRE installed will be /usr/jre1.5.0_11

tar cf - ${JRE15} | (cd /usr ; tar xvf - )
mv ${SYSJRE} ${SYSJRE}.old
ln -s /usr/${JRE15} ${SYSJRE}
${SYSJRE}/bin/java -version
echo " "
echo "If version (Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)) appears, then JRE 1.5.0_11 was successfully installed as the system JRE."

updated_hosts_log A

}

updated_hosts_log() {
# update the ${MASTERDIR} logs
case $1 in
A) # updated
(
echo "###"
echo "# $(uname -n) system JRE updated"
echo "# $(date)"
echo "###"
${SYSJRE}/bin/java -version
)>>$UPDATEDHOSTLOG
;;
B) # issue
(
echo "###"
echo "# $(uname -n) Symantec JRE non-updatable $2"
echo "###"
)>>${ISSUEHOSTSLOG}
esac
}


update_system_jre() {
# update the JRE using tzupdater or unbundle the new JRE if needed

echo "Checking installed system JRE (${SYSJRE})..."
SYSJREVER=$(${SYSJRE}/bin/java -version 2>&1 | grep "^java" | cut -d\" -f2)

case ${SYSJREVER} in
1.4*|1.5*) echo "updateable JRE version found ${SYSJREVER}, updating..." ;${SYSJRE}/bin/java -jar ${TZUPDATE} -u ;echo "done."; updated_hosts_log A;;
*) echo "non-updateable JRE version found ${SYSJREVER}, installing ${JRE15}...";install_jre ; echo "done.";;
esac
}


update_symantec_jre() {
# update Veritas/Symantec Product JREs, will only work with JRE1.4 or greater
# only Veritas/Symantec Products v4.0 or greater are supported
# any version less than 4.0 found will not be able to be updated
echo "Checking for and updating the following packages: VRTSjre, VRTSjre15, VRTSob..."

VRTSJRE14="/opt/VRTSjre/jre1.4/bin/java"
VRTSJRE15="/opt/VRTSjre/jre1.5/bin/java"
VRTSJREOB="/opt/VRTSob/jre/bin/java"
NBUJRE="/usr/openv/java/jre/bin/java"
for x in $(echo "${NBUJRE} ${VRTSJRE14} ${VRTSJRE15} ${VRTSJREOB}")
do
SYMJREVER=$( ${x} -version 2>&1 | grep "^java" | cut -d\" -f2 )
echo ${x}
case ${SYMJREVER} in
1.4*|1.5*) ${x} -jar ${TZUPDATE} -u ; echo "Updated ${x}."
;;
"") echo "\c: not installed. ";;
*) echo "Non-updateable JRE found: ${x}"
echo "See http://seer.entsupport.symantec.com/docs/286461.htm for instructions and impact to this host."
echo "Per Symantec, JRE updates are cosmetic and only affect the GUI."
updated_hosts_log B ${x}
;;
esac
done
}

usage() {
echo " "
echo "ILLEGAL OPTION"
echo "usage: ./java_dst.ksh [-u]"
echo " -u: find/update JREs"
echo "no opts: find JREs and save output to /var/tmp"
}

###
# main()
###

if [ "$*" = "" ]; then
find_jre
else
while [ "$*" != "" ]; do
case $1 in
-u) find_jre B;update_system_jre;update_symantec_jre; shift;;
*) usage; exit 1;;
esac
done
fi

1 comment:

Anonymous said...

Thanks for pointing this out. IT professionals worldwide need to be cognizant of the DST2007 problem, especially if your organization, your organizations customers, or your partners have a physical or electronic presence in the United States or Canada. There is a small but growing body of information available online to help address the DST2007 problem. For example, there is a tool available at sharpebusinesssolutions.com/dst2007.htm to help with one of the toughest parts of the problem - unsupported versions of Microsoft Windows.