This was caused because screen uses 'screen.linux' instead of 'screen' as
$TERM on a linux console which wasn't checked correctly.
# RUN COMMANDS
# If not already in screen reattach to a running session or create a new one.
-if [[ $TERM != 'screen' && $TERM != 'dumb' ]]; then
+#
+# screen* is necessary as `screen` uses screen.linux for example for a linux
+# console which would otherwise cause an infinite loop.
+if [[ $TERM != screen* && $TERM != 'dumb' ]]; then
# Create a new session if none is running.
if [[ $(screen -list | grep "Detached" | wc -l) == 0 ]]; then
screen