aboutsummarylogtreecommitdiffstats
path: root/tws_check_update
blob: 6ee5a8ad8ad04b22925db888e0db9ed1e740f4f9 (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
#!/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"
  if [ -e "${DOWNLOAD_DIR}/version.txt" ] ; then
    echo "version.txt found so no further work required"
    exit 0
  fi
fi

echo "Extracting version number"
DST="$(./tws_get_version "${FILE_CUR}" || echo unknown)"
echo "Version is $DST"

if [[ $DST == *"unknown"* ]]; then
  echo "Error obtaining version from $FILE_MIRROR"
  echo "Removing ${DOWNLOAD_DIR}/version.txt"
  rm -f ${DOWNLOAD_DIR}/version.txt
  exit 2
fi

echo -n $DST > ${DOWNLOAD_DIR}/version.txt

cat ${DOWNLOAD_DIR}/version.txt
exit 0