changeset 412:a9c37b2a5b77 prerelease

Updated setup_board.sh, cleaner error handling, cleaner output
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 15 Jun 2016 23:05:09 +0100
parents 429260bd99b2
children d874b5696078
files scripts/setup_board.sh
diffstat 1 files changed, 40 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/setup_board.sh	Wed Jun 15 21:59:02 2016 +0100
+++ b/scripts/setup_board.sh	Wed Jun 15 23:05:09 2016 +0100
@@ -17,16 +17,24 @@
     running any of the other build scripts in this directory. The -b option
     changes the default path, which is otherwise $BBB_BELA_HOME."
 }
+trap "exit" SIGINT SIGTERM
+
+function error_handler {
+ [ $1 -eq 0 ] && printf "done\n" || { [ -z "$2" ] && printf "\nAn error occurred. Is the board connected?\n" || printf "$2"; exit 1; }
+}
 
 OPTIND=1
-
-while getopts "b:h" opt; do
-    case $opt in
-        b)            BBB_BELA_HOME=$OPTARG
-                      ;;
-        h|\?)         usage
-                      exit 1
-    esac
+ALWAYS_YES=0
+while getopts "b:hy" opt; do
+  case $opt in
+    b)            BBB_BELA_HOME=$OPTARG
+                  ;;
+    h|\?)         usage
+                  exit 1
+		  ;;
+    y)            ALWAYS_YES=1
+                  ;;
+  esac
 done
 
 echo "Copying Bela core files to $BBB_BELA_HOME"
@@ -38,42 +46,40 @@
 SCRIPTDIR=$(dirname "$SCRIPTPATH")
 [ -z "$IDE_FOLDER" ] && IDE_FOLDER=$SCRIPTDIR/../../bela-ide/
 
-read -p "Warning: this script will DELETE any existing Bela files from your BeagleBone! Continue? (y/N) " -r
-echo
-if [[ $REPLY = [yY]  ]]
+if [ $ALWAYS_YES -ne 1 ];
 then
+  printf "Warning: this script will DELETE any existing Bela files from your BeagleBone! Continue? (y/N) "
+  read REPLY;
+  [ $REPLY !=  y ] && [ $REPLY != Y ] && { echo "Aborting..."; exit 1; }
+fi;
+
 # Stop Bela if running and remove all files
-  echo "Stopping Bela and removing old files." 
-  ssh $BBB_ADDRESS "screen -X -S Bela quit &>/dev/null; pkill Bela; sleep 0.5 ; rm -rf $BBB_BELA_HOME ; mkdir $BBB_BELA_HOME"
+printf "Stopping Bela and removing old files..." 
+ssh $BBB_ADDRESS "screen -X -S Bela quit &>/dev/null; pkill Bela; sleep 0.5 ; rm -rf $BBB_BELA_HOME ; mkdir $BBB_BELA_HOME";
+error_handler $?
 
 # Copy relevant files to BeagleBone Black
-  echo "Copying new files to BeagleBone..."
-  scp -q -r $SCRIPTDIR/../core $SCRIPTDIR/../include $SCRIPTDIR/../Makefile $SCRIPTDIR/../libNE10.a $SCRIPTDIR/../libprussdrv.a $SCRIPTDIR/../examples $SCRIPTDIR/../Doxyfile $BBB_ADDRESS:$BBB_BELA_HOME &&\
-  scp -q $SCRIPTDIR/../libpd.so $BBB_ADDRESS:/usr/lib
-  if [ $? -ne 0 ]
-  then 
-	  echo "Error while copying files"
-	  exit
-  fi
+printf "Copying new files to BeagleBone..."
+scp -q -r $SCRIPTDIR/../core $SCRIPTDIR/../include $SCRIPTDIR/../Makefile $SCRIPTDIR/../libNE10.a $SCRIPTDIR/../libprussdrv.a $SCRIPTDIR/../examples $SCRIPTDIR/../Doxyfile $BBB_ADDRESS:$BBB_BELA_HOME &&\
+scp -q $SCRIPTDIR/../libpd.so $BBB_ADDRESS:/usr/lib
+error_handler $?
+
 # Create remaining directories needed for building
-  echo "Creating directory structure on BeagleBone..."
-  ssh $BBB_ADDRESS "mkdir -p $BBB_BELA_HOME/build ; mkdir -p $BBB_BELA_HOME/build/core ; mkdir -p $BBB_BELA_HOME/build/projects; mkdir -p $BBB_BELA_HOME/projects" &&\
-  echo "Done."
-  echo "Creating on-board documentation..."
-  ssh $BBB_ADDRESS "cd $BBB_BELA_HOME; doxygen" &&\
-  echo "Done."
-else
-  echo "Aborting..."
-  exit
-fi
+printf "Creating directory structure on BeagleBone..."
+ssh $BBB_ADDRESS "mkdir -p $BBB_BELA_HOME/build ; mkdir -p $BBB_BELA_HOME/build/core ; mkdir -p $BBB_BELA_HOME/build/projects; mkdir -p $BBB_BELA_HOME/projects"
+error_handler $?
+
+printf "Creating on-board documentation..."
+ssh $BBB_ADDRESS "cd $BBB_BELA_HOME; doxygen &>/dev/null"
+error_handler $? "\nError while generating Doxygen documentation\n"
 
 #-------------
 #Installing IDE
-stat $IDE_FOLDER/scripts/setup_IDE.sh > /dev/null
+stat $IDE_FOLDER/scripts/setup_IDE.sh &> /dev/null
 if [ $? -eq 0 ]
 then
   cd $IDE_FOLDER/scripts;
-  ./setup_IDE.sh
+  ./setup_IDE.sh -y
 else
-  echo "No IDE found, no IDE installed. You can get a copy of the IDE files from https://github.com/LBDonovan/bela-ide"
+  echo "Bela was installed on the board, but No IDE was found, so the IDE was not installed. You can get a copy of the IDE files from https://github.com/LBDonovan/bela-ide"
 fi;