aur/tws_check_update

49 lines
1.3 KiB
Bash
Executable file

#!/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