# HG changeset patch # User Giulio Moro # Date 1466037064 -3600 # Node ID d874b56960781791f03a8994a901be79d470d9d0 # Parent a9c37b2a5b7784c7d5b801df05c9e9248f50c904 renamed setup_board.sh to update_board.sh. Comes with plenty of new functionalities, prompts etc. When called without parameters will only update the relevant files, leaving the projects/ folder alone. When called with --clean will nuke the whole remote Bela folder and restore it. diff -r a9c37b2a5b77 -r d874b5696078 scripts/setup_board.sh --- a/scripts/setup_board.sh Wed Jun 15 23:05:09 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -#!/bin/bash -# -# This script copies the core Bela files to the BeagleBone Black -# in preparation for building projects. It will remove any existing -# Bela directory before copying the files over - -[ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2" -[ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/Bela/" -function usage -{ - THIS_SCRIPT=`basename "$0"` - echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone]" - - echo " - This script copies the core Bela files to the BeagleBone, REMOVING - any previous files found at that location. This should be done before - 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 -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" - -shift $((OPTIND-1)) - -# Find location of this script so we can locate the rest of the files -SCRIPTPATH=$(readlink "$0") -SCRIPTDIR=$(dirname "$SCRIPTPATH") -[ -z "$IDE_FOLDER" ] && IDE_FOLDER=$SCRIPTDIR/../../bela-ide/ - -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 -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 -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 -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 -if [ $? -eq 0 ] -then - cd $IDE_FOLDER/scripts; - ./setup_IDE.sh -y -else - 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; diff -r a9c37b2a5b77 -r d874b5696078 scripts/update_board.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/update_board.sh Thu Jun 16 01:31:04 2016 +0100 @@ -0,0 +1,155 @@ +#!/bin/bash +# +# This script copies the core Bela files to the BeagleBone Black +# in preparation for building projects. It will remove any existing +# Bela directory before copying the files over + +[ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2" +[ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="/root/Bela/" + +FILES_TO_COPY="core include Makefile libNE10.a libprussdrv.a examples Doxyfile" + +# The following variables are manually copied from the Makefile. +# It is a bit nasty, but here we need to handle the case that the board may be +# in any arbitrarily (bad) condition and try to handle it the best we can +BELA_IDE_SCREEN_NAME=IDE-Bela +SCREEN_NAME=Bela + +function usage +{ + THIS_SCRIPT=`basename "$0"` + echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [--clean] [-y]" + + echo " + This script updates the core Bela files on the BeagleBone, bringing it up + to date with the files in the folder on the host comouter. + The script must be run once to initialize the board before running any of + the other scripts in this directory. It must also be run every time you + wish to update the core code. + Running this script will discard all changes to the core code on the remote + end. + +Command line options: + -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. + -y : does not prompt the user before deleting the remote files. + " +} +trap "echo; 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 +ALWAYS_YES=0 +RESET_BOARD=0 +while [ "$1" != "" ]; do + case $1 in + -b) + shift + BBB_BELA_HOME=$1 + ;; + -i) + shift + BBB_ADDRESS=$1 + ;; + --clean) + RESET_BOARD=1 + ;; + -y) + ALWAYS_YES=1 + ;; + *) + usage + exit 1 + ;; + esac + shift +done + + +# Find location of this script so we can locate the rest of the files +SCRIPTPATH=$(readlink "$0") +SCRIPTDIR=$(dirname "$SCRIPTPATH") +[ -z "$IDE_FOLDER" ] && IDE_FOLDER=$SCRIPTDIR/../../bela-ide/ + + +ssh $BBB_ADDRESS "stat $BBB_BELA_HOME &>/dev/null" && DESTINATION_EMPTY=0 || DESTINATION_EMPTY=1 + +if [ $DESTINATION_EMPTY -eq 0 ]; +then + echo "Updating the Bela core code in $BBB_ADDRESS:$BBB_BELA_HOME" + if [ $RESET_BOARD -eq 1 ]; + then + printf "DANGER: you are about to perform a HARD RESET, which will DELETE all the existing files from the folder $BBB_BELA_HOME on the BeagleBone Black.\nAre you sure you want to continue? (y/N) " + else + printf "All the changes to the CORE files in the remote folder $BBB_BELA_HOME will be LOST. The content of these files/folders will be lost:\n $FILES_TO_COPY \nYour projects stored in $BBB_BELA_HOME/projects should be safe (and surely you have already backed them up somewhere safe, haven't you?).\nAre you sure you want to continue? (y/N) " + fi; + if [ $ALWAYS_YES -eq 1 ]; + then + printf "y\n" + else + read REPLY; + [ $REPLY != y ] && [ $REPLY != Y ] && { echo "Aborting..."; exit 1; } + fi +else + echo "Installing Bela core code in $BBB_ADDRESS:$BBB_BELA_HOME" +fi + +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 [ $RESET_BOARD -eq 1 ]; +then + printf "Removing old files..." + ssh $BBB_ADDRESS "rm -rf $BBB_BELA_HOME"; + error_handler $? +fi + +#Check if rsync is available +[ -z `which rsync` ] && RSYNC_AVAILABLE=0 || RSYNC_AVAILABLE=1 + +cd $SCRIPTDIR/../ +printf "Updating files..." +# Copy relevant files to BeagleBone Black +if [ $RSYNC_AVAILABLE -eq 1 ]; +then + [ -z `which sed` ] && FILTER=cat || FILTER="sed s/\\n// | sed s/^.*:/Updated\ files:\/g | tr \"\n\" \" \"" + rsync -ac --no-t --delete-after --stats $FILES_TO_COPY $BBB_ADDRESS:$BBB_BELA_HOME |grep -i "Number" | grep -i "files" | grep -i "transferred" | eval $FILTER &&\ + rsync -ac --no-t libpd.so $BBB_ADDRESS:/usr/lib +else + # if rsync is not available, then clean the folders before copying the files + ssh $BBB_ADDRESS "rm -rf $FILES_TO_COPY; mkdir -p $BBB_BELA_HOME" &&\ + scp -r -q $FILES_TO_COPY $BBB_ADDRESS:$BBB_BELA_HOME &&\ + scp -q libpd.so $BBB_ADDRESS:/usr/lib +fi +error_handler $? + +# Create remaining directories needed for building +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 "Generating 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 +if [ $? -eq 0 ] +then + cd $IDE_FOLDER/scripts; + ./setup_IDE.sh -y + # run the IDE + ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME --no-print-directory idestart" +else + 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;