summarylogtreecommitdiffstats
path: root/tws_check_update
diff options
context:
space:
mode:
authorBen Alex2020-12-07 13:12:46 +1100
committerBen Alex2020-12-07 13:12:46 +1100
commit7735cdefccae9e4ad2969b9334f9843ff76eacd9 (patch)
tree56a554abea2cb0f30fe53fefab8da97d39784c79 /tws_check_update
parent966053f102cbb5f076c5f5fc2b20da874876f8cd (diff)
downloadaur-7735cdefccae9e4ad2969b9334f9843ff76eacd9.tar.gz
Refactor tws_ scripts and change to ZST archive format
Diffstat (limited to 'tws_check_update')
-rwxr-xr-xtws_check_update72
1 files changed, 31 insertions, 41 deletions
diff --git a/tws_check_update b/tws_check_update
index bc180b82015..b23decae97d 100755
--- a/tws_check_update
+++ b/tws_check_update
@@ -1,53 +1,43 @@
#!/bin/bash
+# Put latest installer in $HOME/.tws_scripts with a text file showing version
# Exit status codes:
-# 0 = Existing version is latest
-# 1 = New version of TWS available
-# 2 = Error
+# 0 = success (ls -l $HOME/.tws_scripts for accurate latest version)
+# 1 = failure (refer to console output)
DOWNLOAD_DIR="$HOME/.tws_scripts"
FILE_MIRROR="tws-latest-standalone-linux-x64.sh"
URL_MIRROR="https://download2.interactivebrokers.com/installers/tws/latest-standalone"
FILE_CUR="${DOWNLOAD_DIR}/${FILE_MIRROR}"
-get_perm_file_name()
-{
- local ver;
- local dst;
- ver="$(tws_get_version "$1" || echo unknown)"
- dst="$(echo "$1" | sed -e "s/\(.*\)\.\(.*\)/\1-${ver}.\2/g" -e 's/_latest//g')"
- echo "${dst}"
-}
-
-mkdir -p $DOWNLOAD_DIR
-
-TDIR="$(mktemp -d -t twsdl.XXXX)" || exit 2
-trap "rm -rf ${TDIR}" exit
-cd "${TDIR}" || exit 2
-
-# create fake sparse file for wget because wget -K is broken and -O file
-# conflicts with -N
-if test -f "${FILE_CUR}" ; then
- truncate -r "${FILE_CUR}" "${FILE_MIRROR}"
- touch -r "${FILE_CUR}" "${FILE_MIRROR}"
+set -euo pipefail
+
+MD5_OLD='none'
+if test -e "${FILE_CUR}"; then
+ MD5_OLD=$(md5sum ${FILE_CUR} | cut -c 1-32)
+fi
+echo "Latest version before wget has md5sum $MD5_OLD"
+
+wget --verbose -N -P "${DOWNLOAD_DIR}" "${URL_MIRROR}/${FILE_MIRROR}"
+
+MD5_NEW=$(md5sum ${FILE_CUR} | cut -c 1-32)
+echo "Latest version after wget has md5sum $MD5_NEW"
+
+if [ "$MD5_OLD" == "$MD5_NEW" ]; then
+ echo "File has not changed"
+ exit 0
fi
-if wget --no-verbose -U x -N -P "${TDIR}" "${URL_MIRROR}/${FILE_MIRROR}" ;then
- if test "${FILE_MIRROR}" -nt "${FILE_CUR}" ; then
- DST="$(get_perm_file_name "${FILE_MIRROR}")"
- if [[ $DST == *"unknown"* ]]; then
- echo "Error obtaining version from $FILE_MIRROR"
- exit 2
- fi
- mv "${FILE_MIRROR}" "${DOWNLOAD_DIR}/${DST}"
- ln -sf "${DST}" "${FILE_CUR}"
- echo "TWS $(echo "${DST}" |sed 's/.*-\(.*\)\..*/\1/g') fetched" 1>&2
- exit 1
- else
- echo "TWS $(readlink "${DOWNLOAD_DIR}/${FILE_MIRROR}" |sed 's/.*-\(.*\)\..*/\1/g') is latest" 1>&2
- exit 0
- fi
-else
- echo "TWS update failed" 1>&2
- exit 2
+echo "File has been updated; extracting version number by executing Java"
+DST="$(./tws_get_version "${FILE_CUR}" || echo unknown)"
+echo "Version is $DST"
+
+if [[ $DST == *"unknown"* ]]; then
+ echo "Error obtaining version by executing $FILE_MIRROR"
+ exit 2
fi
+
+echo -n $DST > ${DOWNLOAD_DIR}/version.txt
+
+cat ${DOWNLOAD_DIR}/version.txt
+exit 0