#!/usr/bin/ksh
#
# Shell skript to unpack an MQSeries Workflow hotfix package into a temporary
# directory and copy the updated files into the appropriate places.
#
# Valid for: MQSeries Workflow AIX v3.2.0 Hotfix 2
#            Filename of Hotfix: wf320aau.tar.gz
#
# Run this skript as 'root'
# Needs to be installed on top of MQWF 3.2.0 (= version 3.2.0.0)
#
# To check, use the command    lslpp -L "fmc*"
# A more detailed check can be done using the tool 'fmczchk', or
# by checking specific time stamps, like:
#   % what fmczutil
#   fmczutil:
#     MQSeries Workflow 3.2.0 Configuration Utility, Driver v32_663, Hotfix 1, Jul  8 1999, 10:50:24
#   (This is the correct base level version)
#
# All running MQSeries Workflow processes should have been stopped.
# Needs temporarily about 250 MB in the current file system.
# Needs "gzip" installed.
#
# Parameter: 1) Input file to be unpacked (must be .tar.gz)
#            2) (optional parameter) Existing backup directory,
#               where the original files can be copied into
# Note:      You need additional 250 MB free space in the backup directory
#
# Example:   fmchotfix wf320aau.tar.gz /tmp/WF320backup
#
if [[ ! -d "/usr/lpp/fmc" ]]; then
  echo "Installation directory for MQSeries Workflow does not exist!"
  exit 1
fi
VERS=`LC_ALL=C lslpp -Lq fmc.base | grep base | awk '{print $2}'`
if [[ $VERS != "3.2.0.0" ]]; then
  echo "MQSeries Workflow 3.2.0 is not installed."
  if [[ "$VERS" = "" ]]; then VERS="< none >"; fi
  echo "Installed level seems to be:" $VERS
  echo "It should be: 3.2.0.0"
  exit 2
fi
# This is the name of the directory to unpack the distribution file.
# It will be created relative to the current directory.
TMPDIRNAME=\$\$tmp\$\$
if [ $# -eq 0 ]; then
  echo "Please specify an input file!"
  exit 3
fi
if [[ ! -f $1 ]]; then
  echo "Input file <"$1"> does not exist!"
  exit 4
fi
if [ "$2" != "" ]; then
  if [[ ! -d $2 ]]; then
    echo "Backup directory <"$2"> does not exist!"
    exit 5
  fi
  echo "Will save original files into" $2
else
  echo "Backup directory has not been specified..."
fi
echo "Continue? [y]"
read ASK
if [ "$ASK" = "" ]; then
  ASK=y
fi
if [ $ASK != "y" ] && [ $ASK != "Y" ] && [ $ASK != "yes" ] && [ $ASK != "YES" ] && [ $ASK != "Yes" ]; then
  exit 0
fi
slibclean
mkdir $TMPDIRNAME
if [[ $? > 0 ]]; then
  echo "Problem occurred during creation of the temporary directory <" $PWD/$TMPDIRNAME ">"
  exit 6
fi
echo "Unpacking" $1 "into" $PWD/$TMPDIRNAME
gzip -dc $1 | (cd $TMPDIRNAME; tar -vxf -)
cd $TMPDIRNAME
if [ "$2" != "" ]; then
  echo "Saving original files into" $2
  for i in fmc*.bnd
  do
    (cd ..; cp -p /usr/lpp/fmc/bnd/$i $2)
    if [[ $? > 0 ]]; then
      echo "Problem occurred during copy of" $i "into" $2
      echo "Please ensure that you have installed the correct level of"
      echo "  MQSeries Workflow and that the file system is not full."
      exit 7
    fi
  done
  for i in fmc*.jar
  do
    (cd ..; cp -p /usr/lpp/fmc/bin/java320/$i $2)
    if [[ $? > 0 ]]; then
      echo "Problem occurred during copy of" $i "into" $2
      echo "Please ensure that you have installed the correct level of"
      echo "  MQSeries Workflow and that the file system is not full."
      exit 8
    fi
  done
  for i in *.class
  do
    (cd ..; cp -p /usr/lpp/fmc/smp/$i $2)
    if [[ $? > 0 ]]; then
      echo "Problem occurred during copy of" $i "into" $2
      echo "Please ensure that you have installed the correct level of"
      echo "  MQSeries Workflow and that the file system is not full."
      exit 9
    fi
  done
  for i in *.html
  do
    (cd ..; cp -p /usr/lpp/fmc/doc/javaapi/$i $2)
    if [[ $? > 0 ]]; then
      echo "Problem occurred during copy of" $i "into" $2
      echo "Please ensure that you have installed the correct level of"
      echo "  MQSeries Workflow and that the file system is not full."
      exit 10
    fi
  done
  for i in fmc*
  do
    (cd ..; cp -p /usr/lpp/fmc/bin/$i $2) 2>/dev/null
    # No error checking here, because we ship different files fmc*
    # (not all of them are located in .../bin - see above)
  done
  for i in libfmc*
  do
    (cd ..; cp -p /usr/lpp/fmc/lib/$i $2)
    if [[ $? > 0 ]]; then
      echo "Problem occurred during copy of" $i "into" $2
      echo "Please ensure that you have installed the correct level of"
      echo "  MQSeries Workflow and that the file system is not full."
      exit 11
    fi
  done
fi
echo "Now copying update files into the installation directory..."
cp -p wf*.txt /usr/lpp/fmc 2> /dev/null
cp -p fmc*.bnd /usr/lpp/fmc/bnd
rm fmc*.bnd
cp -p fmc*.jar /usr/lpp/fmc/bin/java320
rm fmc*.jar
cp -p *.class /usr/lpp/fmc/smp
rm *.class
cp -p *.html /usr/lpp/fmc/doc/javaapi
rm *.html
cp -p fmc* /usr/lpp/fmc/bin
cp -p libfmc* /usr/lpp/fmc/lib
echo "Removing again temporary directory..."
cd ..
rm -R $TMPDIRNAME
echo "Done."

echo "Don't forget to issue the 'bind' command as documented in the README"
echo "(by using the fmczrdb tool)."
echo
