#!/bin/bash
#
# JVMMonitorFFDC
#
# Description:
#    This script calls hmcdebuginfo with the same options passed
#    to this script.
#
# Return Codes
#    2 if no arguments were specified
#    3 if not enough required arguments were specified
#    4 if the first argument is not valid.
#    5 if extraneous arguments were specified.
#    6 if "mv" is specified as the first argument and the file indicated
#      by the second argument exists or "mvacuppd" is specified as the
#      first argument and the file indicated by the third argument exists.
#    The exit code for the hmcdebuginfo script is returned if the first argument
#    is specified as "capture". 
#    The exit code for the mv command is returned if the first argument
#    is specified as "mv" or "mvacuppd". 
#
# Module History
#    00  01/29/2007 P. Callaghan - Initial Release
#    01  02/05/2007 P. Callaghan - Add arguments.

if [ $# -lt 1 ] ; then
   exit 2
fi

if [[ "$1" = "capture" ]] ; then
   if [ $# -ne 1 ] ; then
      exit 5
   fi
   hmcdebuginfo -q -o hmcdebuginfo.JVMMon.tgz
   exit $?
fi

if [[ "$1" = "mv" ]] ; then
   if [ $# -lt 3 ] ; then
      exit 3
   fi
   if [ $# -gt 3 ] ; then
      exit 5
   fi
   if [ -e "$2" ] ; then
      # File exists so do not move.
      exit 6
   else
      mv /tmp/hmcdebuginfo.JVMMon.tgz "$2"
      moveRC="$?"
      chown "$3" "$2"
      exit "$moveRC"
   fi
fi

if [[ "$1" = "mvacuppd" ]] ; then
   if [ $# -lt 4 ] ; then
      exit 3
   fi
   if [ $# -gt 4 ] ; then
      exit 5
   fi
   if [ -e "$3" ] ; then
      # File exists so do not move.
      exit 6
   else
      mv "$2"acuppd.tgz "$3"
      moveRC="$?"
      chown "$4" "$3"
      exit "$moveRC"
   fi
fi

exit 4
