summarylogtreecommitdiffstats
path: root/tws_get_version
blob: 2530ef740c8149191beb5c4a4721c46d5f12988f (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
59
60
61
#!/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

# Clean up installation directories if required and install new version
rm -rf $HOME/Jts $HOME/.install4j $HOME/.i4j_jres $HOME/tws
mkdir -p $HOME/Jts

# Install TWS
ARG1="$(readlink -v -f "$1")" || exit 1
chmod +x ${ARG1}
${ARG1} -q &> /dev/null

# Run TWS in virtual frame buffer
LOG="$HOME/Jts/launcher.log"
/usr/sbin/xvfb-run -n 99 $HOME/tws/tws &

# Wait for TWS JVM to start writing to $LOG
while [ ! -f $LOG ]; do
  inotifywait -q -q -t 10 -e create --format '%f' $HOME/Jts
  if [ $? -eq 2 ] && [ ! -f $LOG ]; then
    echo "Error: $LOG not found"
    exit 1
  fi
done

# Wait for $LOG to contain version ("Build") line
for count in {0..10}; do
  grep -q ' - Build' $LOG
  if [ $? -eq 0 ]; then
    break
  fi
  sleep 1
done

# Kill process now that version line or timeout was reached
pkill -9 -f tws/jars/ &> /dev/null

# Clean up ready for next run
rm -rf $HOME/.install4j $HOME/.i4j_jres $HOME/tws

# Extract version line from log now the JVM has exited
VERSION_LINE=$(grep -m1 ' - Build' $LOG)
if [ $? -eq 0 ]; then
  echo "${VERSION_LINE}" |sed -e 's/.*Build //1' -e 's/,.*//1'
  exit 0
fi

echo "could not grep version string; final log appears below" 1>&2
cat $LOG 1>&2
exit 1