#!/bin/bash

create_archive(){
  echo "echo Creating an archive of support materials for the xMatters Integration Agent..."
  local theDate=`date +%d-%b-%y--%H.%M.%S`
  local zipFileName=xmatters-ia-support-$theDate.zip
  local logFile=/tmp/support-zip.log 

  echo $theDate >> $logFile 2>&1
  pushd .. >> $logFile 2>&1

  if [ -f /tmp ]
  then mktemp -d /tmp
  fi

  # create the zip archive in /tmp to avoid recursivity; don't include previous generations of support-zip archives!
  zip -r /tmp/$zipFileName * -i conf/\* integrationservices/\* log/\*.txt bin/logs/\* lib/integrationservices/javascript/\*.js lib/\integrationagent-utils.jar >> $logFile 2>&1
  mv /tmp/$zipFileName log/. >> $logFile 2>&1
  popd >> $logFile 2>&1
  echo "The archive can be found at <IAHome>/log/$zipFileName"
  return 0
}


if [ -f "../bin/APClient.bin" ] 
then 
   create_archive
else
  echo "ERROR: please execute this command from <IAHome>/tools - exiting..."
  exit 1 
fi


