Check for dfu-util and screen before using them. Also aborts if teensy_loader_cli compilation fails. Uses the type builtin to determine if a command exists. See here: https://gist.github.com/sdelmas/7377271simple
@@ -54,13 +54,23 @@ fi | |||
# Load via dfu-util | |||
# Used for McHCK based uCs | |||
dfu-util -D @TARGET_BIN@ | |||
EXIT_STATUS=$? | |||
if type dfu-util &>/dev/null; then | |||
dfu-util -D @TARGET_BIN@ | |||
EXIT_STATUS=$? | |||
else | |||
echo "dfu-util is required to reprogram the device" | |||
exit 3 | |||
fi | |||
# Load Screen Session if specified | |||
if (( "$EXIT_STATUS" == "0" )) && [[ "$AUTO_SCREEN_SESSION" != "" ]]; then | |||
sleep 0.1 | |||
screen $AUTO_SCREEN_SESSION | |||
if type screen &>/dev/null; then | |||
sleep 0.1 | |||
screen $AUTO_SCREEN_SESSION | |||
else | |||
echo "screen is not installed" | |||
exit 3 | |||
fi | |||
fi | |||
exit $EXIT_STATUS |
@@ -50,7 +50,7 @@ if [ ! -e teensy-loader-cli/teensy-loader-cli ]; then | |||
mkdir -p teensy-loader-cli | |||
cd teensy-loader-cli | |||
cmake -G "Unix Makefiles" @CMAKE_SOURCE_DIR@/LoadFile | |||
make | |||
make || exit 3 | |||
cd - | |||
fi | |||
@@ -68,8 +68,13 @@ EXIT_STATUS=$? | |||
# Load Screen Session if specified | |||
if (( "$EXIT_STATUS" == "0" )) && [[ "$AUTO_SCREEN_SESSION" != "" ]]; then | |||
sleep 0.1 | |||
screen $AUTO_SCREEN_SESSION | |||
if type screen &>/dev/null; then | |||
sleep 0.1 | |||
screen $AUTO_SCREEN_SESSION | |||
else | |||
echo "screen is not installed" | |||
exit 3 | |||
fi | |||
fi | |||
exit $EXIT_STATUS |
@@ -49,7 +49,7 @@ if [ ! -e teensy-loader-cli/teensy-loader-cli ]; then | |||
mkdir -p teensy-loader-cli | |||
cd teensy-loader-cli | |||
cmake -G "Unix Makefiles" $(cygpath -u @CMAKE_SOURCE_DIR@/LoadFile) | |||
make | |||
make || exit 3 | |||
cd - | |||
fi | |||