summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Alex2020-12-24 13:53:39 +1100
committerBen Alex2020-12-24 13:59:01 +1100
commite3ce17a60511c696ded3f86a870e525e70a59bd0 (patch)
tree4b1da6ecc6b25f3495216086878bd3cf278d3bd8
parent8ff9558ff8729551b451c3cc4d4845031c6c4c8c (diff)
downloadaur-e3ce17a60511c696ded3f86a870e525e70a59bd0.tar.gz
Better handle line buffering in tws_get_version
-rwxr-xr-xtws_check_update11
-rwxr-xr-xtws_get_version42
2 files changed, 37 insertions, 16 deletions
diff --git a/tws_check_update b/tws_check_update
index b23decae97d..6ee5a8ad8ad 100755
--- a/tws_check_update
+++ b/tws_check_update
@@ -25,15 +25,20 @@ echo "Latest version after wget has md5sum $MD5_NEW"
if [ "$MD5_OLD" == "$MD5_NEW" ]; then
echo "File has not changed"
- exit 0
+ if [ -e "${DOWNLOAD_DIR}/version.txt" ] ; then
+ echo "version.txt found so no further work required"
+ exit 0
+ fi
fi
-echo "File has been updated; extracting version number by executing Java"
+echo "Extracting version number"
DST="$(./tws_get_version "${FILE_CUR}" || echo unknown)"
echo "Version is $DST"
if [[ $DST == *"unknown"* ]]; then
- echo "Error obtaining version by executing $FILE_MIRROR"
+ echo "Error obtaining version from $FILE_MIRROR"
+ echo "Removing ${DOWNLOAD_DIR}/version.txt"
+ rm -f ${DOWNLOAD_DIR}/version.txt
exit 2
fi
diff --git a/tws_get_version b/tws_get_version
index 8bbb694f860..fc094fd7796 100755
--- a/tws_get_version
+++ b/tws_get_version
@@ -18,6 +18,7 @@ TDIR="$(mktemp -d -t twsdir.XXXX)" || exit 1
trap "rm -rf ${TDIR}" exit
cd "${TDIR}" || exit 1
+# Clean up installation directories if required and install new version
rm -rf $HOME/.install4j $HOME/.i4j_jres $HOME/tws
chmod +x ${ARG1}
${ARG1} -q &> /dev/null
@@ -27,26 +28,41 @@ mkdir "${TWS_HOME}" || exit 1
LOG="${TWS_HOME}/launcher.log"
TWS_CP=`find ${HOME}/tws/jars -type f -name \*.jar -printf '%p:'`
-
-java -cp "${TWS_CP}" jclient.LoginFrame "${TWS_HOME}" &
+/usr/sbin/xvfb-run -n 99 /usr/lib/jvm/java-8-openjdk/jre/bin/java -cp "${TWS_CP}" jclient.LoginFrame "${TWS_HOME}" &
disown
TWS_PID="$!"
-# give TWS JVM chance to start writing to $LOG
-x=0
-while [ "$x" -lt 50 -a ! -e /path/to/the/file_name ]; do
- x=$((x+1))
- sleep .1
+# Wait for TWS JVM to start writing to $LOG
+while [ ! -f $LOG ]; do
+ inotifywait -q -q -t 10 -e create --format '%f' $TWS_HOME
+ 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
-VERSION_LINE="$(timeout --preserve-status "${TWS_TIMEOUT}" grep -m1 --line-buffered " - Build" "${LOG}")"
-kill -9 "${TWS_PID}" &>/dev/null
+# Kill process now that version line or timeout was reached
+/usr/bin/kill --verbose --timeout 1000 TERM --timeout 1000 KILL --signal INT $TWS_PID &>/dev/null
+# Clean up ready for next run
rm -rf $HOME/.install4j $HOME/.i4j_jres $HOME/tws
-if test "${VERSION_LINE}" == ""; then
- echo "could not grep version string" 1>&2
- exit 1
+# 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 "${VERSION_LINE}" |sed -e 's/.*Build //1' -e 's/,.*//1'
+echo "could not grep version string; final log appears below" 1>&2
+cat $LOG 1>&2
+exit 1