From 084679d2d124088c27116083a7897852380109b5 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Thu, 8 Mar 2018 11:39:17 +0000 Subject: [PATCH] Deal with the device port containing unexpected whitespace This should never happen, but could if something goes badly wrong in the device detection code, e.g. someone changing it in a way which caused extra output on STDOUT. --- bin/kaleidoscope-builder | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/bin/kaleidoscope-builder b/bin/kaleidoscope-builder index 4bf28ffb..8f4007bb 100755 --- a/bin/kaleidoscope-builder +++ b/bin/kaleidoscope-builder @@ -249,13 +249,27 @@ reset_device() { } check_device_port () { - if [ -z $DEVICE_PORT ]; then - echo "Couldn't autodetect the keyboard's serial port." - echo "If you see this message and your keyboard is connected to your computer," - echo "it probably means that our serial port detection logic is buggy or incomplete." - echo - echo "Please report this issue at https://github.com/keyboardio/Kaleidoscope"; - exit 0; + if [ -z "$DEVICE_PORT" ]; then + cat <&2 +Couldn't autodetect the keyboard's serial port. +If you see this message and your keyboard is connected to your computer, +it probably means that our serial port detection logic is buggy or incomplete. + +Please report this issue at https://github.com/keyboardio/Kaleidoscope +EOF + exit 1 + elif echo "$DEVICE_PORT" | grep -q '[[:space:]]'; then + cat <&2 +Unexpected whitespace found in detected serial port: + + $DEVICE_PORT + +If you see this message, it means that our serial port +detection logic is buggy or incomplete. + +Please report this issue at https://github.com/keyboardio/Kaleidoscope +EOF + exit 1 fi }