Skip to content

Commit

Permalink
Fix bugs in low-level scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rlktradewright committed Dec 3, 2022
1 parent 774deb2 commit 4081161
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
25 changes: 12 additions & 13 deletions resources/scripts/StartIBC.bat
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,9 @@ set JAVA_TOOL_OPTIONS=
pushd %TWS_SETTINGS_PATH%

echo Renaming TWS or Gateway .exe file to prevent restart without IBC
IF /I "%PROGRAM%"=="TWS" (
ren %PROGRAM_PATH%\tws.exe zztws.exe
) else (
ren %PROGRAM_PATH%\ibgateway.exe zzibgateway.exe
)
IF exist "%PROGRAM_PATH%\tws.exe" ren "%PROGRAM_PATH%\tws.exe" tws1.exe
IF exist "%PROGRAM_PATH%\ibgateway.exe" ren "%PROGRAM_PATH%\ibgateway.exe" ibgateway1.exe
echo .

:startIBC

Expand Down Expand Up @@ -453,16 +451,17 @@ echo Error level is %ERRORLEVEL%
echo Check for 2FA dialog timed out
if %ERRORLEVEL% EQU %E_2FA_DIALOG_TIMED_OUT% (
if /I "%TWOFA_TO_ACTION%" == "RESTART" (
:: wait a few seconds before restarting
echo IBC will restart shortly due to 2FA completion timeout
ping localhost -n 2 >NUL
goto :startIBC
) else (
echo 2FA completion timed-out but TWOFA_TO_ACTION=EXIT so not restarting IBC
goto :NormalExit
)
)

echo Check for login dialog display timeout
if %ERRORLEVEL% EQU %E_LOGIN_DIALOG_DISPLAY_TIMEOUT% (
:: wait a few seconds before restarting
echo IBC will restart shortly due to login dialog display timeout
ping localhost -n 2 >NUL
goto :startIBC
Expand All @@ -472,18 +471,17 @@ echo Check for restart
echo call :GetAutoRestartOption
call :GetAutoRestartOption
if defined AUTORESTART_OPTION (
:: wait a few seconds before restarting
echo IBC will autorestart shortly
ping localhost -n 2 >NUL
goto :startIBC
)

:NormalExit

echo Renaming TWS or Gateway .exe file to original name
if /I "%PROGRAM%"=="TWS" (
ren %PROGRAM_PATH%\zztws.exe tws.exe
) else (
ren %PROGRAM_PATH%\zzibgateway.exe ibgateway.exe
)
IF exist "%PROGRAM_PATH%\tws1.exe" ren "%PROGRAM_PATH%\tws1.exe" tws.exe
IF exist "%PROGRAM_PATH%\ibgateway1.exe" ren "%PROGRAM_PATH%\ibgateway1.exe" ibgateway.exe
echo.

echo Normal exit

Expand All @@ -500,6 +498,7 @@ exit /B %ERRORLEVEL%
:GetAutoRestartOption

echo Finding autorestart file

set AUTORESTART_OPTION=
for /f "usebackq" %%I in (`where /R %TWS_SETTINGS_PATH% autorestart`) do (
for %%A in ("%%~pI.") do set AUTORESTART_OPTION=-Drestart=%%~nxA
Expand Down
19 changes: 17 additions & 2 deletions resources/scripts/ibcstart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,14 @@ JAVA_TOOL_OPTIONS=
pushd "$tws_settings_path" > /dev/null

echo "Renaming IB's TWS or Gateway start script to prevent restart without IBC"
mv "${program_path}/tws" "${program_path}/zztws"
if [[ "$os" = "$OS_LINUX" ]]; then
if [[ -e "${program_path}/tws" ]]; then mv "${program_path}/tws" "${program_path}/tws1"; fi
if [[ -e "${program_path}/ibgateway" ]]; then mv "${program_path}/ibgateway" "${program_path}/ibgateway1"; fi
elif [[ "$os" = "$OS_OSX" ]]; then
if [[ -e "${program_path}/Trader Workstation ${tws_version}.app" ]]; then mv "${program_path}/Trader Workstation ${tws_version}.app" "${program_path}/Trader Workstation ${tws_version}-1.app"; fi
if [[ -e "${program_path}/IB Gateway ${tws_version}.app" ]]; then mv "${program_path}/IB Gateway ${tws_version}.app" "${program_path}/IB Gateway ${tws_version}-1.app"; fi
fi
echo

while :
do
Expand Down Expand Up @@ -484,7 +491,15 @@ do
echo sleep 2
done

mv "${program_path}/zztws" "${program_path}/tws"
echo "Renaming TWS or Gateway .exe file to original name"
if [[ "$os" = "$OS_LINUX" ]]; then
if [[ -e "${program_path}/tws1" ]]; then mv "${program_path}/tws1" "${program_path}/tws"; fi
if [[ -e "${program_path}/ibgateway1" ]]; then mv "${program_path}/ibgateway1" "${program_path}/ibgateway"; fi
elif [[ "$os" = "$OS_OSX" ]]; then
if [[ -e "${program_path}/Trader Workstation ${tws_version}.app-1" ]]; then mv "${program_path}/Trader Workstation ${tws_version}.app-1" "${program_path}/Trader Workstation ${tws_version}.app"; fi
if [[ -e "${program_path}/IB Gateway ${tws_version}.app-1" ]]; then mv "${program_path}/IB Gateway ${tws_version}.app-1" "${program_path}/IB Gateway ${tws_version}.app"; fi
fi
echo

echo "$program finished"
echo
Expand Down

0 comments on commit 4081161

Please sign in to comment.