Created
December 17, 2012 15:02
-
-
Save rudimeier/4318941 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
TWS_TIMEOUT="30" | |
if ! test -e "$1"; then | |
echo "Usage: $0 <jar file | TWS dir>" 1>&2 | |
exit 1 | |
fi | |
ARG1="$(readlink -v -f "$1")" || exit 1 | |
TDIR="$(mktemp -d -t twsdir.XXXX)" || exit 1 | |
trap "rm -rf ${TDIR}" exit | |
cd "${TDIR}" || exit 1 | |
if test -d "${ARG1}"; then | |
if test -f "${ARG1}/jts.jar" ;then | |
TWS_CP="${ARG1}/jts.jar:${ARG1}/*" | |
else | |
echo "error: directory '"${ARG1}"' is not a TWS installation" 2>&1 | |
exit 1 | |
fi | |
else | |
if jar xf "${ARG1}" &>/dev/null && test -f IBJts/jts.jar; then | |
TWS_CP="IBJts/jts.jar:IBJts/*" | |
else | |
echo "error: invalid jar file '"${ARG1}"'" 2>&1 | |
exit 1 | |
fi | |
fi | |
TWS_HOME="${TDIR}/twshome" | |
mkdir "${TWS_HOME}" || exit 1 | |
LOG_FIFO="${TDIR}/twslogpipe" | |
mkfifo "${LOG_FIFO}" || exit 1 | |
java -cp "${TWS_CP}" jclient.LoginFrame "${TWS_HOME}" &>"${LOG_FIFO}" & | |
TWS_PID="$!" | |
VERSION_LINE="$(timeout "${TWS_TIMEOUT}" grep -m1 --line-buffered "JTS-Main: Build" "${LOG_FIFO}")" | |
grep_rval="$?" | |
kill -9 "${TWS_PID}" &>/dev/null | |
if test "${grep_rval}" = "124"; then | |
echo "timeout waiting for version string" 1>&2 | |
exit 1 | |
elif test "${grep_rval}" != "0"; then | |
echo "could not grep version string" 1>&2 | |
exit 1 | |
fi | |
echo "${VERSION_LINE}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment