#!/bin/sh
################################################################################
# Example script for launching MGC from topaz
# $Id: run6x-mgc.sh,v 1.1 2007-09-14 22:41:16 normg Exp $
#


usage(){
cat <<EOF
Usage: run6x-mgc [stoneName] [SystemUser password] [FDC filename]

where:
            stoneName = name of the database
  SystemUser password = password for SystemUser
         FDC filename = full path to the binary file generated by the FDC
EOF
exit 1
}

if [ "$GEMSTONE" = "" ]; then
  echo "Error: GEMSTONE env var must be set to GemStone 6.x product tree"
  exit 1
fi

if [ "$1" = "" ]; then
usage
fi

if [ "$2" = "" ]; then
usage
fi

if [ "$3" = "" ]; then
usage
fi

osname=`uname`

if [ "$osname" = "HP-UX" ]; then
  suffix="sl"
else
  suffix="so"
fi

library="libofflinegc6x"

libFile="$GEMSTONE/ualib/libofflinegc6x.$suffix"

if [ ! -f "$libFile" ]; then
  echo "Error: cannot find user action library $libFile"
  exit 1
fi

if [ ! -f "mgc.conf" ]; then
  echo "Error: cannot find config file mgc.conf"
  exit 1
fi

# Only GS/64 has geml.  6.x uses gem
if [ -f "$GEMSTONE/sys/geml" ]; then
  echo "Error: GEMSTONE env var references a GemStone/64 product tree instead of 6.x product tree."
  exit 1
fi

stone=$1
pw=$2
fdcFile=$3
logFile="mgc.log"

if [ ! -f "$fdcFile" ]; then
  echo "Error: cannot find FDC file $fdcFile"
  exit 1
fi

if [ ! -r "$fdcFile" ]; then
  echo "Error: cannot read FDC file $fdcFile"
  exit 1
fi

rm -f $logFile >/dev/null 2>&1
echo "Starting MGC operation on database $stone.  log file=$logFile"
echo "fdcFile = $fdcFile"

$GEMSTONE/bin/topaz -il -e mgc.conf -z mgc.conf << EOF  >$logFile 2>&1
dispaly oops
limit oops 100
limit bytes 4000
iferror quit
loadua $library

set gemstone $stone 
set u SystemUser p $pw
login
level 1
time
run
System userAction: #uaLoadOopsAndRunMgc with: '$fdcFile' with: true.
%
time


logout
quit

EOF

