summarylogtreecommitdiffstats
path: root/tws_get_version
blob: 307db786297ffa7b105ca4d75295f33e56a2916a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh

# Exit status codes:
#   0 =  Version reported correctly
#   1 =  Error

TWS_TIMEOUT="15"

if ! test -e "$1"; then
	echo "Usage:   $0 <sh>" 1>&2
	echo "Example: $0 $HOME/.tws_scripts/tws-latest-standalone-linux-x64.sh" 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

rm -rf $HOME/.install4j $HOME/.i4j_jres $HOME/Jts
chmod +x ${ARG1}

# as of 954.2o the installer runs TWS, even after unattended install!
# so we need to install, wait to kill off the nuisance process, and continue
${ARG1} -q &> /dev/null
while true
do
    pkill -f $HOME/Jts
    if [ $? -eq 0 ]; then
        break
    fi
done


MAJORVER=`find $HOME/Jts -maxdepth 1 -type d -regex '.*/[0-9]*' -printf '%f'`

TWS_HOME="${TDIR}/twshome"
mkdir "${TWS_HOME}" || exit 1
LOG_FIFO="${TDIR}/twslogpipe"
mkfifo "${LOG_FIFO}" || exit 1

TWS_CP=`find ${HOME}/Jts/${MAJORVER}/jars -type f -name \*.jar -printf '%p:'`
java -cp "${TWS_CP}" jclient.LoginFrame "${TWS_HOME}" &>"${LOG_FIFO}" &
disown
TWS_PID="$!"

VERSION_LINE="$(timeout --preserve-status "${TWS_TIMEOUT}" grep -m1 --line-buffered ": Build" "${LOG_FIFO}")"
kill -9 "${TWS_PID}" &>/dev/null

rm -rf $HOME/.install4j $HOME/.i4j_jres $HOME/Jts

if test "${VERSION_LINE}" == ""; then
	echo "could not grep version string" 1>&2
	exit 1
fi

echo "${VERSION_LINE}" |sed -e 's/.*Build //1' -e 's/,.*//1'