SoapUI install directory detection / mockservice execution script

For some 'homework' i needed a (bash) script to start the soapUI mockservicerunner on Oracle Linux which could start the mock service regardless of the soapUI installation directory. I could not find a single reference to the installation directory, and therefore wrote some code to find the installation location, To speed up the detection the script first searches the directories where you might expect to find soapUI, secondly in less logical locations. When found, the soapUI installation directory is stored in the script itself to speed up future executions of the script. Here it is, have fun !

#!/bin/bash

# Objective: Start mockservicerunner
#
# 11282011 petervannes.nl Initial version
# 11302011 petervannes.nl Improved soapUI detection
# 04132011 petervannes.nl Improved soapUI detection for soapui 4.5.0

# Do not change this line
export soapuipath="/home/soaadmin/soapui-4.5.0/bin/soapui-4.5.0.jar"
fqscript=$0

if [[ "${1}" == "respawn" ]] 
  then respawned="true"
  else respawned="false"
fi

# function  replaceconfig
# objective replace assigned path to soapuipath variable in
#           this script
#
function replaceconfig {
  path=`echo ${1} | sed 's/\//\\\\\//g'`
  sed -r "s/^(export\ssoapuipath)=.*$/\1=\"${path}\"/" $fqscript > \
  ${fqscript}.tmp \
  && cp ${fqscript}.tmp ${fqscript} \
  && rm -f ${fqscript}.tmp
  echo Respawning process ... 
  ./$0 respawn
  kill $$
}

# Check if current path to soapUI is a valid path
if [[ ((! -x $soapuipath) || (! -n $soapuipath)) && ($respawned != "true")]]
then

  echo Please be patient for first time initialization
  echo Detection of soapUI in progress ...

  # try to find soapUI in well known places
  sourcepath=( '/opt' ~ '/usr' '/' )

  for index in "${sourcepath[@]}"
  do
    echo Searching in ${index} ...
    soapuipath=`find ${index} -name "soapUI-?.?.?" -type f -perm /u=x,g=x 2>/dev/null`

    if [[ ! -x $soapuipath ]]
    then
      soapuipath=`find ${index} -name "soap[Uu][Ii]-?.?.?.jar" -type f  2>/dev/null`
    fi

    if [[ -x $soapuipath ]]
    then
      replaceconfig ${soapuipath}
    fi

  done
fi

# Stop if process is respawned without valid path to soapUI
if [[ ($respawned == "true") && ((! -x $soapuipath) || (! -n $soapuipath))]]
then
  echo Could not find installation of soapUI!
  exit
fi

# Get 'soapUI_HOME' 
soapuibasedir=`dirname ${soapuipath} 2>/dev/null`
if [ $? -ne  '0' ]
then 
  echo "Unable to determine soapUI installation directory" 
  exit 
fi

# Start mockservice
$soapuibasedir/mockservicerunner.sh -m"CustomerServiceSOAP MockService" \
CustomerServiceCRM-soapui-project.xml



20120619 Update; Improved soapUI detection for soapui 4.5.0

blog comments powered by Disqus