| andrewm@58 | 1 #!/bin/bash | 
| andrewm@58 | 2 # | 
| giuliomoro@377 | 3 # This script copies the core Bela files to the BeagleBone Black | 
| andrewm@58 | 4 # in preparation for building projects. It will remove any existing | 
| giuliomoro@377 | 5 # Bela directory before copying the files over | 
| andrewm@58 | 6 | 
| giuliomoro@367 | 7 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2" | 
| giuliomoro@377 | 8 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/Bela/" | 
| andrewm@58 | 9 function usage | 
| andrewm@58 | 10 { | 
| andrewm@58 | 11     THIS_SCRIPT=`basename "$0"` | 
| andrewm@58 | 12     echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone]" | 
| andrewm@58 | 13 | 
| andrewm@58 | 14     echo " | 
| giuliomoro@377 | 15     This script copies the core Bela files to the BeagleBone, REMOVING | 
| andrewm@58 | 16     any previous files found at that location. This should be done before | 
| andrewm@58 | 17     running any of the other build scripts in this directory. The -b option | 
| giuliomoro@367 | 18     changes the default path, which is otherwise $BBB_BELA_HOME." | 
| andrewm@58 | 19 } | 
| giuliomoro@412 | 20 trap "exit" SIGINT SIGTERM | 
| giuliomoro@412 | 21 | 
| giuliomoro@412 | 22 function error_handler { | 
| giuliomoro@412 | 23  [ $1 -eq 0 ] && printf "done\n" || { [ -z "$2" ] && printf "\nAn error occurred. Is the board connected?\n" || printf "$2"; exit 1; } | 
| giuliomoro@412 | 24 } | 
| andrewm@58 | 25 | 
| andrewm@58 | 26 OPTIND=1 | 
| giuliomoro@412 | 27 ALWAYS_YES=0 | 
| giuliomoro@412 | 28 while getopts "b:hy" opt; do | 
| giuliomoro@412 | 29   case $opt in | 
| giuliomoro@412 | 30     b)            BBB_BELA_HOME=$OPTARG | 
| giuliomoro@412 | 31                   ;; | 
| giuliomoro@412 | 32     h|\?)         usage | 
| giuliomoro@412 | 33                   exit 1 | 
| giuliomoro@412 | 34 		  ;; | 
| giuliomoro@412 | 35     y)            ALWAYS_YES=1 | 
| giuliomoro@412 | 36                   ;; | 
| giuliomoro@412 | 37   esac | 
| andrewm@58 | 38 done | 
| andrewm@58 | 39 | 
| giuliomoro@377 | 40 echo "Copying Bela core files to $BBB_BELA_HOME" | 
| andrewm@58 | 41 | 
| andrewm@58 | 42 shift $((OPTIND-1)) | 
| andrewm@58 | 43 | 
| andrewm@58 | 44 # Find location of this script so we can locate the rest of the files | 
| giuliomoro@300 | 45 SCRIPTPATH=$(readlink "$0") | 
| andrewm@58 | 46 SCRIPTDIR=$(dirname "$SCRIPTPATH") | 
| l@405 | 47 [ -z "$IDE_FOLDER" ] && IDE_FOLDER=$SCRIPTDIR/../../bela-ide/ | 
| andrewm@58 | 48 | 
| giuliomoro@412 | 49 if [ $ALWAYS_YES -ne 1 ]; | 
| andrewm@58 | 50 then | 
| giuliomoro@412 | 51   printf "Warning: this script will DELETE any existing Bela files from your BeagleBone! Continue? (y/N) " | 
| giuliomoro@412 | 52   read REPLY; | 
| giuliomoro@412 | 53   [ $REPLY !=  y ] && [ $REPLY != Y ] && { echo "Aborting..."; exit 1; } | 
| giuliomoro@412 | 54 fi; | 
| giuliomoro@412 | 55 | 
| giuliomoro@377 | 56 # Stop Bela if running and remove all files | 
| giuliomoro@412 | 57 printf "Stopping Bela and removing old files..." | 
| giuliomoro@412 | 58 ssh $BBB_ADDRESS "screen -X -S Bela quit &>/dev/null; pkill Bela; sleep 0.5 ; rm -rf $BBB_BELA_HOME ; mkdir $BBB_BELA_HOME"; | 
| giuliomoro@412 | 59 error_handler $? | 
| andrewm@58 | 60 | 
| andrewm@58 | 61 # Copy relevant files to BeagleBone Black | 
| giuliomoro@412 | 62 printf "Copying new files to BeagleBone..." | 
| giuliomoro@412 | 63 scp -q -r $SCRIPTDIR/../core $SCRIPTDIR/../include $SCRIPTDIR/../Makefile $SCRIPTDIR/../libNE10.a $SCRIPTDIR/../libprussdrv.a $SCRIPTDIR/../examples $SCRIPTDIR/../Doxyfile $BBB_ADDRESS:$BBB_BELA_HOME &&\ | 
| giuliomoro@412 | 64 scp -q $SCRIPTDIR/../libpd.so $BBB_ADDRESS:/usr/lib | 
| giuliomoro@412 | 65 error_handler $? | 
| giuliomoro@412 | 66 | 
| giuliomoro@402 | 67 # Create remaining directories needed for building | 
| giuliomoro@412 | 68 printf "Creating directory structure on BeagleBone..." | 
| giuliomoro@412 | 69 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" | 
| giuliomoro@412 | 70 error_handler $? | 
| giuliomoro@412 | 71 | 
| giuliomoro@412 | 72 printf "Creating on-board documentation..." | 
| giuliomoro@412 | 73 ssh $BBB_ADDRESS "cd $BBB_BELA_HOME; doxygen &>/dev/null" | 
| giuliomoro@412 | 74 error_handler $? "\nError while generating Doxygen documentation\n" | 
| andrewm@58 | 75 | 
| giuliomoro@402 | 76 #------------- | 
| giuliomoro@402 | 77 #Installing IDE | 
| giuliomoro@412 | 78 stat $IDE_FOLDER/scripts/setup_IDE.sh &> /dev/null | 
| giuliomoro@402 | 79 if [ $? -eq 0 ] | 
| giuliomoro@402 | 80 then | 
| giuliomoro@402 | 81   cd $IDE_FOLDER/scripts; | 
| giuliomoro@412 | 82   ./setup_IDE.sh -y | 
| giuliomoro@402 | 83 else | 
| giuliomoro@412 | 84   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" | 
| giuliomoro@402 | 85 fi; |