Refactor exit code handling and logging
This commit is contained in:
parent
d64491e574
commit
e75d4fadaa
49
Dockerfile
49
Dockerfile
|
@ -55,25 +55,23 @@ RUN \
|
|||
pattern="fixme:win:NtUserLockWindowUpdate ((nil))"; \
|
||||
# The amount of times the pattern should occur for the process to be considered stuck
|
||||
patternCount=2; \
|
||||
output="$( \
|
||||
sed \
|
||||
# Handle exit hints
|
||||
-e "s/^exit \([[:digit:]]\+\)$/\1/; t end;" \
|
||||
# Handle multiple occurrences of $pattern
|
||||
-e "/$pattern/{ x; s/^x\{$(expr $patternCount - 1)\}$/\0/; t stuck; s/^\(x*\)$/\1x/; x; };" \
|
||||
# Delete output and return to start
|
||||
-e "d; b;" \
|
||||
# Branch "stuck": delete output and exit with code 42
|
||||
-e ":stuck s/.*//; q42;" \
|
||||
# Branch "end": exit with code 0
|
||||
-e ":end q;")"; \
|
||||
sed \
|
||||
-u \
|
||||
# Handle multiple occurrences of $pattern
|
||||
-e "/$pattern/{ x; s/^x\{$(expr $patternCount - 1)\}$/\0/; t stuck; s/^\(x*\)$/\1x/; x; };" \
|
||||
# Delete output and return to start
|
||||
-e "b;" \
|
||||
# Branch "stuck": delete output and exit with code 42
|
||||
-e ":stuck q42;" \
|
||||
# Branch "end": exit with code 0
|
||||
-e ":end q;"; \
|
||||
exitCode="$?"; \
|
||||
# Kill installer if it got stuck (according to console output)
|
||||
[ "$exitCode" -eq 42 ] && pkill -9 MDK537.exe; \
|
||||
# Use `sed`s exit code if non-zero
|
||||
[ "$exitCode" -ne 0 ] && exit $exitCode; \
|
||||
# Use `sed`s output otherwise
|
||||
[ "$exitCode" -eq 0 ] && exit $output; \
|
||||
[ "$exitCode" -ne 0 ] && exit "$exitCode" || \
|
||||
# Return true otherwise
|
||||
true; \
|
||||
}; \
|
||||
# Run actual MDK537 installer
|
||||
install_keil() { \
|
||||
|
@ -82,11 +80,22 @@ RUN \
|
|||
logFile="$(mktemp)"; \
|
||||
# Run installer asynchronously
|
||||
{ \
|
||||
{ 2>&1 WINEDEBUG=+all,trace-all,warn-all /usr/bin/entrypoint wine MDK537.exe --batch-install || echo "exit $?"; } \
|
||||
# Write output to `log.txt`
|
||||
| { [ "$DEBUG" -eq 1 ] && tee "$logFile" || cat; } \
|
||||
# Pipe stdout and stderr to `handle_output` function
|
||||
| handle_output & \
|
||||
{ \
|
||||
local exitCode; \
|
||||
exitCodeFile="$(mktemp)"; \
|
||||
{ \
|
||||
2>&1 WINEDEBUG=+all,trace-all,warn-all /usr/bin/entrypoint wine MDK537.exe --batch-install; \
|
||||
echo "$?" > "$exitCodeFile"; \
|
||||
} \
|
||||
# Write output to a log file when debugging
|
||||
| { [ "$DEBUG" -eq 1 ] && tee "$logFile" || cat; } \
|
||||
# Pipe stdout and stderr to `handle_output` function
|
||||
| handle_output; \
|
||||
outputHandlerCode="$?"; \
|
||||
exitCode="$(cat "$exitCodeFile")"; \
|
||||
rm "$exitCodeFile"; \
|
||||
bash -c "exit $([ "$outputHandlerCode" -ne 0 ] && "$outputHandlerCode" || "$exitCode")"; \
|
||||
} & \
|
||||
}; \
|
||||
pid="$!"; \
|
||||
# Continuously display screenshots and iteration number
|
||||
|
|
Loading…
Reference in a new issue