changeset 455:0567af952cfa prerelease

merge
author Giulio Moro <giuliomoro@yahoo.it>
date Sun, 19 Jun 2016 23:31:25 +0100
parents 7f9032f43f41 (current diff) 1d66b4e8ced9 (diff)
children aa3f38d8a9b6
files Makefile scripts/update_board
diffstat 2 files changed, 55 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sun Jun 19 22:43:06 2016 +0100
+++ b/Makefile	Sun Jun 19 23:31:25 2016 +0100
@@ -304,9 +304,10 @@
 
 BELA_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
 UPDATES_DIR?=/root/Bela/updates
-UPDATE_SOURCE_DIR?=/tmp/belaUpdate
+UPDATE_SOURCE_DIR_BASE?=/tmp/belaUpdate
+UPDATE_SOURCE_DIR=$(UPDATE_SOURCE_DIR_BASE)/Bela
 UPDATE_REQUIRED_PATHS?=scripts include core scripts/update_board 
-UPDATE_BELA_TEMP?=/tmp/belaTemp
+UPDATE_BELA_PATCH?=/tmp/belaPatch
 UPDATE_BELA_BACKUP?=/tmp/belaBak
 UPDATE_BELA_MV_BACKUP?=/tmp/belaMvBak
 
@@ -318,16 +319,17 @@
 	@cd $(UPDATES_DIR) && COUNT=`ls -l *.zip | wc -l` && [ $$COUNT -eq 1 ] && rm -rf `ls | grep -v "\.zip$$"`
 	@#TODO: heuristics on available space. Use unzip -l and df
 	@echo uncompressed size: `unzip -l \`ls $(UPDATES_DIR)/*.zip\` | tail -n1 | awk '{print $$1}'`
-	# Delete and re-create the temp directory (first, make sure it is not empty!!)
-	@[ -n $(UPDATE_SOURCE_DIR) ] && rm -rf $(UPDATE_SOURCE_DIR) && mkdir -p $(UPDATE_SOURCE_DIR)
+	# Delete and re-create the temp directory (first, make sure it is not an empty string!)
+	@[ -n $(UPDATE_SOURCE_DIR_BASE) ] && rm -rf $(UPDATE_SOURCE_DIR_BASE) && mkdir -p $(UPDATE_SOURCE_DIR_BASE)
 	# Unzip the contents to the temp folder
-	@cd $(UPDATE_SOURCE_DIR) && unzip -qq $(UPDATES_DIR)/*zip
-	# Strip the top-level folder ( if there is only one )
-	@DIR=`ls -d $(UPDATE_SOURCE_DIR)` && COUNT=`echo $$DIR | wc -l` &&\
+	@cd $(UPDATE_SOURCE_DIR_BASE) && unzip -qq $(UPDATES_DIR)/*zip
+# Strip the top-level folder ( if there is only one )
+#@DIR=`ls -d $(UPDATE_SOURCE_DIR)` && COUNT=`echo $$DIR | wc -l` &&\
 	  [ $$COUNT -eq 1 ] && mv $(UPDATE_SOURCE_DIR)/* /tmp/supertemp && rm -rf $(UPDATE_SOURCE_DIR) && mv /tmp/supertemp $(UPDATE_SOURCE_DIR)
 	# Now actually check if some key-files and folders are there
 	@cd $(UPDATE_SOURCE_DIR) && FAIL=0 && for path in $(UPDATE_REQUIRED_PATHS); do `ls $$path >/dev/null 2>&1` || { FAIL=1; break; }; done;\
 	  [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; }
+	# Success. You can continue the install with "make update"
 UPDATE_LOG?=~/update.log
 LOG=>> $(UPDATE_LOG) 2>&1
 update: ## Installs the update from $(UPDATES_DIR)
@@ -338,28 +340,26 @@
 	# Now actually check if some key-files and folders are there
 	@cd $(UPDATE_SOURCE_DIR) && FAIL=0 && for path in $(UPDATE_REQUIRED_PATHS); do `ls $$path >/dev/null 2>&1` || { FAIL=1; break; }; done;\
 	  [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; }
-	# Duplicate the Bela folder $(BELA_DIR) to $(UPDATE_BELA_TEMP)
-	@[ -n $(UPDATE_BELA_TEMP) ] && mkdir -p $(UPDATE_BELA_TEMP)
+	# Duplicate the Bela folder $(BELA_DIR) to $(UPDATE_BELA_PATCH) ...
+	@[ -n $(UPDATE_BELA_PATCH) ] && mkdir -p $(UPDATE_BELA_PATCH)
 	@#TODO: this would allow to trim trailing slashes in case we want to be safer: a="`pwd`/" ; target=${a%/} ; echo $target
-	@rsync -a --delete-before $(BELA_DIR)/ $(UPDATE_BELA_TEMP)
-	# Also back it up in $(UPDATE_BELA_BACKUP). 
+	@rsync -a --delete-before $(BELA_DIR)/ $(UPDATE_BELA_PATCH)
+	# Also backing it up in $(UPDATE_BELA_BACKUP)...
 	@[ -n $(UPDATE_BELA_BACKUP) ] && mkdir -p $(UPDATE_BELA_BACKUP)
 	@rsync -a $(BELA_DIR)/ $(UPDATE_BELA_BACKUP)
-	@#TODO: add command line switch for update_board which avoids useless stuff (e.g.: setting the date, start/stop the IDE)
-	@cd $(UPDATE_SOURCE_DIR)/scripts && BBB_ADDRESS=root@127.0.0.1 BBB_BELA_HOME=$(UPDATE_BELA_TEMP) ./update_board -y 
-	# If everything went ok, we now have the updated version of $(BELA_DIR) in $(UPDATE_BELA_TEMP) and a backup of $(BELA_DIR) in $(UPDATE_BELA_BACKUP)
-	# So let's operate the magic swap. $(BELA_DIR) is moved to $(UPDATE_BELA_MV_BACKUP) and $(UPDATE_BELA_TEMP) is moved to $(BELA_DIR).
+	# Here's the trick: we run "update_board" ssh'ing into the BeagleBone itself! 
+	@cd $(UPDATE_SOURCE_DIR)/scripts && BBB_ADDRESS=root@127.0.0.1 BBB_BELA_HOME=$(UPDATE_BELA_PATCH) ./update_board -y --no-frills
+	# If everything went ok, we now have the updated version of $(BELA_DIR) in $(UPDATE_BELA_PATCH) and a backup of $(BELA_DIR) in $(UPDATE_BELA_BACKUP)
+	# So let's operate the magic swap. $(BELA_DIR) is moved to $(UPDATE_BELA_MV_BACKUP) and $(UPDATE_BELA_PATCH) is moved to $(BELA_DIR).
 	# If something goes wrong at thie stage, you can always find your old $(BELA_DIR) folder at $(UPDATE_BELA_BACKUP)
 	# The fun part is that this Makefile is moved as well...
 	# We are about to kill the IDE, so just in case you are running this from within the IDE, we run the remainder of this update in a screen.
 	# Output will be logged to $(UPDATE_LOG)
 	@screen -S update-Bela -d -m bash -c '\
-	  echo so let us just make a backup of the Makefile we are working on TODO: remove this one $(LOG);\
-	  cp $(BELA_DIR)/Makefile /tmp/ $(LOG) &&\
 	  [ -n $(UPDATE_BELA_MV_BACKUP) ] $(LOG) && rm -rf $(UPDATE_BELA_MV_BACKUP) $(LOG) &&\
 	  echo Kill the IDE $(LOG) && \
 	  $(MAKE) --no-print-directory idestop $(LOG) &&\
-	  mv $(BELA_DIR) $(UPDATE_BELA_MV_BACKUP) $(LOG) && mv $(UPDATE_BELA_TEMP) $(BELA_DIR) $(LOG) &&\
+	  mv $(BELA_DIR) $(UPDATE_BELA_MV_BACKUP) $(LOG) && mv $(UPDATE_BELA_PATCH) $(BELA_DIR) $(LOG) &&\
 	  echo Hope we are still alive here $(LOG) &&\
 	  echo Restart the IDE $(LOG) &&\
 	  make --no-print-directory -C $(BELA_DIR) idestart $(LOG) &&\
--- a/scripts/update_board	Sun Jun 19 22:43:06 2016 +0100
+++ b/scripts/update_board	Sun Jun 19 23:31:25 2016 +0100
@@ -1,4 +1,4 @@
-\#!/bin/sh
+#!/bin/sh
 #
 # This script copies the core Bela files to the BeagleBone Black
 # in preparation for building projects. It will remove any existing
@@ -6,7 +6,7 @@
 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="/root/Bela/"
 
-# . ./.bela_common || exit 1  
+. ./.bela_common || exit 1  
 
 FILES_TO_COPY="core include Makefile libNE10.a libprussdrv.a examples Doxyfile"
 
@@ -19,7 +19,7 @@
 usage ()
 {
     THIS_SCRIPT=`basename "$0"`
-    echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [--clean] [-y]"
+    echo "Usage: $THIS_SCRIPT [--clean] [--no-frills] [-dy ] [-i user@ip] [-b /path/to/remote/Bela]"
 
     echo "
     This script updates the core Bela files on the BeagleBone, bringing it up
@@ -34,6 +34,8 @@
     -i arg : allows to set the username and IP address of the remote end (default: $BBB_ADDRESS)
     -b arg : allows to set the path to the Bela folder on the remote end. Use quotes if you use the \"~\" symbol (default: $BBB_BELA_HOME)
     --clean : removes all the files in the $BBB_BELA_HOME folder, INCLUDING any source code you may have in the $BBB_BELA_HOME/projects/ subdirectory.
+    -d : skips re-generating Doxygen documentation on the board.
+    --no-frills : skips some optional commands.
     -y : does not prompt the user before deleting the remote files.
     "
 }
@@ -50,9 +52,11 @@
  [ $1 -eq 0 ] && printf "done\n" || { [ -z "$2" ] && printf "\nAn error occurred. Is the board connected?\n" || printf "$2"; exit 1; }
 }
 
+FULL=1
 OPTIND=1
 ALWAYS_YES=0
 RESET_BOARD=0
+DOXYGEN=1
 while [ "$1" != "" ]; do
   case $1 in
     -b)           
@@ -66,6 +70,12 @@
     --clean)
       RESET_BOARD=1
     ;;
+    -d)
+      DOXYGEN=0
+    ;;
+    --no-frills)
+      FULL=0
+    ;;
     -y)          
        ALWAYS_YES=1
     ;;
@@ -82,7 +92,11 @@
 SCRIPTDIR=$(dirname "$0")
 [ -z "$IDE_FOLDER" ] && IDE_FOLDER=$SCRIPTDIR/../../bela-ide/
 
-set_date "stat $BBB_BELA_HOME &>/dev/null" && DESTINATION_EMPTY=0 || DESTINATION_EMPTY=1
+# Check if destination folder exists
+# the StrictHostKeyChecking no should prevent the unkown host prompt
+ssh -o "StrictHostKeyChecking no" $BBB_ADDRESS stat $BBB_BELA_HOME &>/dev/null && DESTINATION_EMPTY=0 || DESTINATION_EMPTY=1
+# Set the date on the board
+[ $FULL -eq 1 ] && set_date 
 
 if [ $DESTINATION_EMPTY -eq 0 ];
 then
@@ -104,11 +118,14 @@
   echo "Installing Bela core code in $BBB_ADDRESS:$BBB_BELA_HOME"
 fi
 
-echo "Updating Bela cores files to remote folder $BBB_BELA_HOME"
+echo "Updating Bela core files to remote folder $BBB_BELA_HOME"
 # Stop Bela if running and remove all files
-printf "Stopping Bela..." 
-ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME idestop stop &>/dev/null; screen -X -S Bela quit &>/dev/null; screen -X -S IDE-Bela quit &>/dev/null; true";
-error_handler $?
+if [ $FULL -eq 1 ]
+then
+  printf "Stopping Bela..." 
+  ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME idestop stop &>/dev/null; screen -X -S Bela quit &>/dev/null; screen -X -S IDE-Bela quit &>/dev/null; true";
+  error_handler $?
+fi
 
 if [ $RESET_BOARD -eq 1 ];
 then
@@ -146,9 +163,12 @@
 ssh $BBB_ADDRESS "mkdir -p $BBB_BELA_HOME/build/core $BBB_BELA_HOME/projects"
 error_handler $?
 
-printf "Generating on-board documentation..."
-#ssh $BBB_ADDRESS "cd $BBB_BELA_HOME; doxygen &> /dev/null"
-error_handler $? "\nError while generating Doxygen documentation\n"
+if [ $DOXYGEN -eq 1 ] 
+then 
+  printf "Generating on-board documentation..."
+  ssh $BBB_ADDRESS "cd $BBB_BELA_HOME; doxygen &> /dev/null"
+  error_handler $? "\nError while generating Doxygen documentation\n"
+fi
 
 printf "Building example projects..."
 ssh $BBB_ADDRESS "sh $BBB_BELA_HOME/examples/core/link_core.sh"
@@ -164,21 +184,21 @@
 ls $IDE_FOLDER/scripts/setup_IDE.sh >/dev/null 2>/dev/null
 if [ $? -eq 0 ]
 then
+  export BBB_ADDRESS BBB_BELA_HOME
   cd $IDE_FOLDER/scripts && ./setup_IDE.sh $ALWAYS_YES_FLAG
   # run the IDE 
-  ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME --no-print-directory idestart"
+  [ $FULL -eq 1 ] && ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME --no-print-directory idestart"
 else
   # run the IDE 
-  ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME --no-print-directory idestart"
-  echo \
-"The Bela core files were updated the board, but a valid IDE folder was not found in $IDE_FOLDER/, so the IDE was not updated. If there was an older version of the IDE on the board, it is being restarted.
+  [ $FULL -eq 1 ] && ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME --no-print-directory idestart"
+  [ $FULL -eq 1 ] && echo "The Bela core files were updated on the board, but a valid IDE folder was not found in $IDE_FOLDER/, so the IDE was not updated. If there was an older version of the IDE on the board, it is being restarted.
 You can get a copy of the most up-to-date IDE files from https://github.com/LBDonovan/bela-ide
 "
 fi
 
-ssh $BBB_ADDRESS make -C $BBB_BELA_HOME --no-print-directory idestartup nostartup && echo "The board will now run the IDE at startup, but startup of the Bela program has been disabled. To enable it, use the set_startup.sh script" 
+[ $FULL -eq 1 ] && ssh $BBB_ADDRESS make -C $BBB_BELA_HOME --no-print-directory idestartup nostartup && echo "The board will now run the IDE at startup, but startup of the Bela program has been disabled. To enable it, use the set_startup.sh script" 
 
-{ [ $ALWAYS_YES -eq 1 ] || [ $SHLVL -ge 1 ]; } && printf "\nSetup complete.\n\n" || {
+[ $ALWAYS_YES -eq 1 ] && printf "\nSetup complete.\n\n" || {
   printf '\nSetup complete, press any key to continue\n\n'
   read 
 }