diff options
author | Ben Alex | 2015-06-10 14:11:50 +1000 |
---|---|---|
committer | Ben Alex | 2015-06-10 14:15:06 +1000 |
commit | 5d13392e5834c7a0e726ec3cb18ef8979ad687f6 (patch) | |
tree | 23b717192afbd8668025305c2b1268e597ecd0e0 | |
parent | 8da1339d174ca9919f8137760e2bdf098aed30a4 (diff) | |
download | aur-5d13392e5834c7a0e726ec3cb18ef8979ad687f6.tar.gz |
Additional AUR maintenance files formerly stored at GitHub
-rw-r--r-- | README.md | 70 | ||||
-rwxr-xr-x | tws | 181 | ||||
-rwxr-xr-x | tws_check_update | 50 | ||||
-rwxr-xr-x | tws_get_version | 56 | ||||
-rwxr-xr-x | update | 62 | ||||
-rwxr-xr-x | upload | 24 |
6 files changed, 443 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 000000000000..a4333ccfa45a --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +ib-tws Package Helpers +====================== + +Source and helpers for the [Interactive Brokers] +(http://interactivebrokers.com/) Traders Workstation [ib-tws] +(https://aur.archlinux.org/packages/ib-tws/) AUR package. + +This project assists maintain ib-tws. It is necessary because TWS is +downloaded from a generic, non-versioned URL. The downloaded file does +not provide a version number, instead requiring execution of the software +to determine the version. These conditions complicate maintenance of the +Arch package, as the package must report the correct TWS version number +plus reflect the md5sum of the currently-available TWS URL. + +Setup +----- + +Install software: + + sudo pacman -S wget java-environment bash base-devel namcap pkgbuild-introspection + +If you are the current AUR maintainer, setup burp: + + sudo pacman -S burp + mkdir -p $XDG_CONFIG_HOME/burp + echo 'User=something' > $XDG_CONFIG_HOME/burp/burp.conf + echo 'Password=something' >> $XDG_CONFIG_HOME/burp/burp.conf + +Clone as follows (if you are the current AUR maintainer, use your own +fork as the `upload` script will push commits to your repository): + + git clone git://github.com/benalexau/ib-tws.git + cd ib-tws + git submodule init + git submodule update + +From ib-tws, add symbolic links for the utilities: + + ln -s `pwd`/tws_scripts/tws_get_version $HOME/bin/tws_get_version + ln -s `pwd`/tws_scripts/tws_check_update $HOME/bin/tws_check_update + +Verify correct execution by running `tws_check_update`. It should report +a TWS version number and store files in `$HOME/.tws_scripts/`. + +Usage +----- + +If you *are not* the current AUR maintainer, run `update`. This will: + +* Run `tws_check_update` +* Update the `PKGBUILD` to reflect the reported version and hash codes +* Build the package, including a source version +* Run `namcap` to verify package quality (the build will fail if any + warnings are reported) + +If you *are* the current AUR maintainer, run `upload`. This will: + +* Run `update` (refer above) +* If any changes were made, `burp` is used to upload the new version +* If any changes were made, a Git commit and push is performed + +If you are the current AUR maintainer but used `tws_check_update` and it +updated the version, simply `rm $HOME/.tws_scripts/` and use `upload`. + +License +------- + +All contents of this repository are provided under the +[Apache License, Version 2.0] +(https://www.apache.org/licenses/LICENSE-2.0.html). @@ -0,0 +1,181 @@ +#!/bin/bash +# +# tws: - comfortable shell script for running TWS +# +# usage: - set your paths in config section below +# - see --help +# +# Copyright (C) 2011 Ruediger Meier <sweet_f_a@gmx.de> +# License: BSD 3-Clause + + +#### config section + +TWS_HOME="${HOME}/.tws" +TWS_DIR="/opt/TWS/IBJts" +IBController_DIR="/opt/TWS/IBController" + + +#### defaults, don't change! + +GATEWAY="0" +JAVA_OPTS="" +CONTROLLER="0" +PATCHED="0" +LOOP="0" +DRYRUN="0" + + +#### funcs + +_print_usage() +{ + cat <<EOF +Usage: $0 [--gw] [--javaopts OPTIONS] [-p|--patched] [-c|--controller] \ +[--loop] [--tws TWS_DIR] [--test] [--] [TWS_HOME] +EOF +} + +_parse_cmd() +{ + local TEMP + TEMP=$(getopt -o cph \ + --long gw,javaopts:,controller,patched,loop,tws:,test,help \ + -n "$0" -- "$@" \ + ) || return 1 + eval set -- "$TEMP" + + while true ; do + case "$1" in + --gw) + GATEWAY="1"; shift;; + --javaopts) + JAVA_OPTS="$2"; shift 2;; + -c|--controller) + CONTROLLER="1"; shift;; + -p|--patched) + PATCHED="1"; shift;; + --loop) + LOOP="1"; shift 1;; + --tws) + TWS_DIR="$(readlink -f "$2")"; shift 2;; + --test) + DRYRUN="1"; shift 1;; + --help) + _print_usage; exit 0;; + --) + shift ; break ;; + *) + echo "$0: Internal error!" >&2; return 1;; + esac + done + + #Remaining arguments: + if test "$#" -gt 1 ;then + echo "$0: bad usage" 2>&1 + return 1 + elif test "$#" -gt 0 ;then + TWS_HOME="$1" + fi + + LOGFILE="${TWS_HOME}/tws_restart.log" +} + +echo_log() +{ + local now=`date "+%F %T"` + echo -e "${now}: $@" |tee -a "${LOGFILE}" >&2 +} + +eval_loop() +{ + if test ${LOOP} = 0 ;then + echo_log "start tws" + eval "$@" + echo_log "tws exit code $?" + else + local i="0"; + while true; do + echo_log "start tws loop $i" + eval "$@" + echo_log "tws exit code $? ... will be restarted" + i="$(( i+1 ))" + sleep 1 + done + fi +} + +_java_exec() +{ + if [ "${DRYRUN}" = "1" ] ;then + echo "CONTROLLER='${CONTROLLER}'" + echo "PATCHED='${PATCHED}'" + echo "IBController_DIR='${IBController_DIR}'" + echo "TWS_DIR='${TWS_DIR}'" + echo "TWS_HOME='${TWS_HOME}'" + echo "CLASSPATH='${CLASSPATH}'" + echo "java ${JAVA_OPTS} -cp '${CLASSPATH}' $@" + else + eval_loop "java ${JAVA_OPTS} -cp '${CLASSPATH}' $@" + fi +} + + + + +#### here we go + +if ! _parse_cmd "$@" ;then + exit 1 +fi + + + +if [ "${PATCHED}" = 1 ] ;then + TWS_DIR=${TWS_DIR}-patched +fi + +if ! test -d "${TWS_DIR}" ;then + echo "$0: invalid TWS_DIR: '${TWS_DIR}'" >&2 + exit 1 +fi +if ! test -d "${TWS_HOME}" ;then + echo "$0: invalid TWS_HOME: '${TWS_HOME}'" >&2 + exit 1 +fi + +cd "${TWS_HOME}" || exit 1 + + + +#getting classpath +for jarfile in ${TWS_DIR}/*.jar ;do + CLASSPATH="${CLASSPATH}:${jarfile}" +done +#add path to (eventually existing) patches +CLASSPATH=${TWS_DIR}/include_patches:${TWS_DIR}/jts:${CLASSPATH} + + +if [ "${CONTROLLER}" = 1 ] ;then + temp="" + if ! temp="$(sed '/^IbDir=\.\r\{0,1\}$/!d' IBController.ini 2>/dev/null)" ;then + echo "$0: ${TWS_HOME}/IBController.ini not found" >&2; + exit 1 + fi + if test -z "${temp}" ;then + echo "$0: ${TWS_HOME}/IBController.ini must contain 'IbDir=.'" >&2; + exit 1 + fi + CLASSPATH="${IBController_DIR}/IBController.jar:${CLASSPATH}" + if [ "${GATEWAY}" = 1 ] ;then + _java_exec ibcontroller.IBGatewayController ./IBController.ini + else + _java_exec ibcontroller.IBController ./IBController.ini + fi +else + if [ "${GATEWAY}" = 1 ] ;then + _java_exec ibgateway.GWClient . + else + _java_exec jclient.LoginFrame . + fi +fi diff --git a/tws_check_update b/tws_check_update new file mode 100755 index 000000000000..7b93105c8e20 --- /dev/null +++ b/tws_check_update @@ -0,0 +1,50 @@ +#!/bin/bash + +# Exit status codes: +# 0 = Existing version is latest +# 1 = New version of TWS available +# 2 = Error + +DOWNLOAD_DIR="$HOME/.tws_scripts" +FILE_MIRROR="unixmacosx_latest.jar" +URL_MIRROR="http://download2.interactivebrokers.com/download" +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}" +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}")" + 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 +fi + diff --git a/tws_get_version b/tws_get_version new file mode 100755 index 000000000000..8817d43ca140 --- /dev/null +++ b/tws_get_version @@ -0,0 +1,56 @@ +#!/bin/sh + +# Exit status codes: +# 0 = Version reported correctly +# 1 = Error + +TWS_TIMEOUT="15" + +if ! test -e "$1"; then + echo "Usage: $0 <jar file | TWS dir>" 1>&2 + echo "Example: $0 $HOME/.tws_scripts/unixmacosx_latest.jar" 1>&2 + exit 1 +fi + +ARG1="$(readlink -v -f "$1")" || exit 1 + +TDIR="$(mktemp -d -t twsdir.XXXX)" || exit 1 +trap "rm -rf ${TDIR}" exit +cd "${TDIR}" || exit 1 + +if test -d "${ARG1}"; then + if test -f "${ARG1}/jts.ini" ;then + TWS_DIR="${ARG1}" + else + echo "error: directory '"${ARG1}"' is not a TWS installation" 2>&1 + exit 1 + fi +else + if jar xf "${ARG1}" &>/dev/null && test -f IBJts/jts.jar; then + TWS_DIR="IBJts" + else + echo "error: invalid jar file '"${ARG1}"'" 2>&1 + exit 1 + fi +fi + +TWS_HOME="${TDIR}/twshome" +mkdir "${TWS_HOME}" || exit 1 +cp -a "${TWS_DIR}/jts.ini" "${TWS_HOME}" || exit 1 +LOG_FIFO="${TDIR}/twslogpipe" +mkfifo "${LOG_FIFO}" || exit 1 + +TWS_CP="${TWS_DIR}/jts:${TWS_DIR}/*" +java -cp "${TWS_CP}" jclient.LoginFrame "${TWS_HOME}" &>"${LOG_FIFO}" & +disown +TWS_PID="$!" + +VERSION_LINE="$(timeout --preserve-status "${TWS_TIMEOUT}" grep -m1 --line-buffered ": Build" "${LOG_FIFO}")" +kill -9 "${TWS_PID}" &>/dev/null + +if test "${VERSION_LINE}" == ""; then + echo "could not grep version string" 1>&2 + exit 1 +fi + +echo "${VERSION_LINE}" |sed -e 's/.*Build //1' -e 's/,.*//1' diff --git a/update b/update new file mode 100755 index 000000000000..f7751f5ccd03 --- /dev/null +++ b/update @@ -0,0 +1,62 @@ +#!/bin/bash + +# Exit status codes: +# 0 = PKGBUILD is already up-to-date +# 1 = PKGBUILD has been updated +# 2 = Error + +tws_check_update &> /dev/null +if [ "$?" -eq 2 ]; then echo "tws_check_update failed"; exit 2; fi + +PRG="$0" + +while [ -h "$PRG" ]; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`/"$link" + fi +done +SCRIPT_HOME=`dirname "$PRG"` + +if [ ! -e "$SCRIPT_HOME/PKGBUILD" ] ; then + echo "$SCRIPT_HOME/PKGBUILD missing" + exit 2 +fi +if [ ! -e "$HOME/.tws_scripts/unixmacosx_latest.jar" ] ; then + echo "tws_check_update does not appear to have run" + exit 2 +fi + +VER="`tws_get_version ${HOME}/.tws_scripts/unixmacosx_latest.jar`" +if [ "$?" -eq 1 ]; then echo "tws_get_version failed"; exit 2; fi + +grep -q "pkgver=${VER}" $SCRIPT_HOME/PKGBUILD +if [ "$?" -eq 0 ]; then + exit 0 +else + cd $SCRIPT_HOME + rm -rf *.jar *.xz *.gz pkg src + sed -i "s/pkgver=.*/pkgver=${VER}/" 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 + echo "Package creation failure" + exit 2 + fi + NAMCAP=`namcap -m *.xz | grep -v bash` + if [ ! "$NAMCAP" == "" ]; then + echo "Namcap failed build: $NAMCAP" + exit 2 + fi + mksrcinfo + if ! ls *.gz &> /dev/null ; then + echo "Source tarball creation failure" + exit 2 + fi + echo "$SCRIPT_HOME/PKGBUILD updated for TWS ${VER}" + exit 1 +fi diff --git a/upload b/upload new file mode 100755 index 000000000000..389b4b483317 --- /dev/null +++ b/upload @@ -0,0 +1,24 @@ +#!/bin/bash + +PRG="$0" + +while [ -h "$PRG" ]; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`/"$link" + fi +done +SCRIPT_HOME=`dirname "$PRG"` + +$SCRIPT_HOME/update +if [ "$?" -eq 1 ]; then + echo "Uploading updated TWS" + burp -c office $SCRIPT_HOME/*.gz + echo "Updating Git" + cd $SCRIPT_HOME + git commit -a -m "Commit from upload script due to new version" + git push +fi |