summarylogtreecommitdiffstats
path: root/tws_check_update
blob: b23decae97df122324b8cee6080fdae1960db8a1 (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
#!/bin/bash

# Put latest installer in $HOME/.tws_scripts with a text file showing version
# Exit status codes:
#   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}"

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

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