From 8d4adb41ec51beda664be4cf0009278b66d64699 Mon Sep 17 00:00:00 2001 From: Rowan Decker Date: Thu, 12 Feb 2015 19:42:01 -0800 Subject: [PATCH] Check for needed programs 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/7377271 --- LoadFile/load.dfu | 18 ++++++++++++++---- LoadFile/load.teensy | 11 ++++++++--- LoadFile/winload.teensy | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/LoadFile/load.dfu b/LoadFile/load.dfu index a3769e3..7f55c2c 100755 --- a/LoadFile/load.dfu +++ b/LoadFile/load.dfu @@ -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 diff --git a/LoadFile/load.teensy b/LoadFile/load.teensy index 83b48d6..df16dfc 100755 --- a/LoadFile/load.teensy +++ b/LoadFile/load.teensy @@ -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 diff --git a/LoadFile/winload.teensy b/LoadFile/winload.teensy index 6d354fa..1d86daf 100755 --- a/LoadFile/winload.teensy +++ b/LoadFile/winload.teensy @@ -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