summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Alex2020-12-07 13:12:46 +1100
committerBen Alex2020-12-07 13:12:46 +1100
commit7735cdefccae9e4ad2969b9334f9843ff76eacd9 (patch)
tree56a554abea2cb0f30fe53fefab8da97d39784c79
parent966053f102cbb5f076c5f5fc2b20da874876f8cd (diff)
downloadaur-7735cdefccae9e4ad2969b9334f9843ff76eacd9.tar.gz
Refactor tws_ scripts and change to ZST archive format
-rw-r--r--.gitignore1
-rwxr-xr-xtws_check_update72
-rwxr-xr-xtws_get_version2
-rwxr-xr-xupdate12
4 files changed, 39 insertions, 48 deletions
diff --git a/.gitignore b/.gitignore
index b13192e5c61..db731c06cb3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
pkg
src
/tws-latest-standalone-linux-x64.sh
+*.zst
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
diff --git a/tws_get_version b/tws_get_version
index 48de622fc91..8bbb694f860 100755
--- a/tws_get_version
+++ b/tws_get_version
@@ -28,7 +28,7 @@ LOG="${TWS_HOME}/launcher.log"
TWS_CP=`find ${HOME}/tws/jars -type f -name \*.jar -printf '%p:'`
-/usr/lib/jvm/java-8-openjdk/bin/java -cp "${TWS_CP}" jclient.LoginFrame "${TWS_HOME}" &
+java -cp "${TWS_CP}" jclient.LoginFrame "${TWS_HOME}" &
disown
TWS_PID="$!"
diff --git a/update b/update
index e9c8ffad10d..9ed1ee0a625 100755
--- a/update
+++ b/update
@@ -5,8 +5,8 @@
# 1 = PKGBUILD has been updated
# 2 = Error
-tws_check_update &> /dev/null
-if [ "$?" -eq 2 ]; then echo "tws_check_update failed"; exit 2; fi
+./tws_check_update
+if [ "$?" -ne 0 ]; then echo "tws_check_update failed"; exit 2; fi
PRG="$0"
@@ -25,25 +25,25 @@ if [ ! -e "$SCRIPT_HOME/PKGBUILD" ] ; then
echo "$SCRIPT_HOME/PKGBUILD missing"
exit 2
fi
-if [ ! -e "$HOME/.tws_scripts/tws-latest-standalone-linux-x64.sh" ] ; then
+if [ ! -e "$HOME/.tws_scripts/version.txt" ] ; then
echo "tws_check_update does not appear to have run"
exit 2
fi
-VER="$(readlink $HOME/.tws_scripts/tws-latest-standalone-linux-x64.sh | sed 's/.*-//g' | sed 's/.sh//g')"
+VER="$(cat $HOME/.tws_scripts/version.txt)"
grep -q "pkgver=${VER}" $SCRIPT_HOME/PKGBUILD
if [ "$?" -eq 0 ]; then
exit 0
else
cd $SCRIPT_HOME
- rm -rf *.jar *.xz *.gz tws-latest-standalone-*.sh pkg src
+ rm -rf *.jar *.zst *.gz tws-latest-standalone-*.sh pkg src
sed -i "s/pkgver=.*/pkgver=${VER}/" PKGBUILD
sed -i "s/pkgrel=.*/pkgrel=1/" PKGBUILD
# Next line from https://bugs.archlinux.org/task/15051
{ rm PKGBUILD; awk '$0 ~ /^md5sums/ {i = 1; system("makepkg -g 2>/dev/null")}; !i {print}; $0 ~ /\)/ {i = 0}' > PKGBUILD; } < PKGBUILD
makepkg
- if ! ls *.xz &> /dev/null ; then
+ if ! ls *.zst &> /dev/null ; then
echo "Package creation failure"
exit 2
fi