giuliomoro@238: #!/bin/bash giuliomoro@238: # giuliomoro@238: # This script compiles a BeagleRT project on the BeagleBone Black and giuliomoro@238: # optionally runs it. Pass a directory path in the first argument. giuliomoro@238: # The source files in this directory are copied to the board and compiled. giuliomoro@238: giuliomoro@238: BBB_ADDRESS="root@192.168.7.2" giuliomoro@238: BBB_LIBPD_EXECUTABLE_PATH="~/libpd/BeagleRT" giuliomoro@238: BBB_LIBPD_PROJECT_PATH="~/libpd/source/" giuliomoro@238: RUN_PROJECT=1 giuliomoro@238: COMMAND_ARGS= giuliomoro@238: RUN_IN_FOREGROUND=0 giuliomoro@238: RUN_WITHOUT_SCREEN=0 giuliomoro@238: giuliomoro@238: function usage giuliomoro@238: { giuliomoro@238: THIS_SCRIPT=`basename "$0"` giuliomoro@238: echo "Usage: $THIS_SCRIPT [-c command-line-args] [-nfF] " giuliomoro@238: echo " giuliomoro@238: This script copies a PureData project to the BeagleBone and runs it giuliomoro@238: using libpd. The BeagleRT-libpd executable should have first been copied giuliomoro@238: to the $BBB_LIBPD_EXECUTABLE_PATH folder on the Beaglebone. giuliomoro@238: The source directory should contain a file called _main.pd, which is the giuliomoro@238: patch that will be loaded into Pd. All the content of the folder is giuliomoro@238: recursively copied and the folder structure is flattened. giuliomoro@238: If the argument -n is passed, the output will not be run after compiling. giuliomoro@238: The -c option passes command-line arguments to the BeagleRT program; giuliomoro@238: enclose the argument string in quotes. giuliomoro@238: giuliomoro@238: The -f argument runs the project in the foreground of the current terminal, giuliomoro@238: within a screen session that can be detached later with ctrl-A ctrl-D. giuliomoro@238: The -F argument runs the project in the foreground of the current terminal, giuliomoro@238: without screen, so the output can be piped to another destination." giuliomoro@238: } giuliomoro@238: giuliomoro@238: OPTIND=1 giuliomoro@238: giuliomoro@238: while getopts "b:c:nfFh" opt; do giuliomoro@238: case $opt in giuliomoro@238: c) COMMAND_ARGS=$OPTARG giuliomoro@238: ;; giuliomoro@238: f) RUN_IN_FOREGROUND=1 giuliomoro@238: ;; giuliomoro@238: F) RUN_WITHOUT_SCREEN=1 giuliomoro@238: ;; giuliomoro@238: n) RUN_PROJECT=0 giuliomoro@238: ;; giuliomoro@238: h|\?) usage giuliomoro@238: exit 1 giuliomoro@238: esac giuliomoro@238: done giuliomoro@238: giuliomoro@238: shift $((OPTIND-1)) giuliomoro@238: giuliomoro@238: # Check that we have a directory containing at least one source file giuliomoro@238: # as an argument giuliomoro@238: giuliomoro@238: if [ -z "$1" ] giuliomoro@238: then giuliomoro@238: usage giuliomoro@238: exit giuliomoro@238: fi giuliomoro@238: giuliomoro@238: FIND_STRING="find $* -maxdepth 10000 -type f " giuliomoro@238: giuliomoro@238: PROJECT_FILES=$($FIND_STRING) giuliomoro@238: giuliomoro@238: if [[ -z $PROJECT_FILES ]] giuliomoro@238: then giuliomoro@238: echo "Please provide a directory containing the _main.pd file and additional abstractions" giuliomoro@238: usage giuliomoro@238: exit giuliomoro@238: fi giuliomoro@238: giuliomoro@238: # Stop BeagleRT and clean out old source files giuliomoro@238: echo "Stopping BeagleRT and removing old source files..." giuliomoro@238: ssh -t -t $BBB_ADDRESS "screen -X -S BeagleRT quit &>/dev/null;\ giuliomoro@238: pkill BeagleRT ; rm -rf $BBB_LIBPD_PROJECT_PATH/; mkdir -p $BBB_LIBPD_PROJECT_PATH; " giuliomoro@238: giuliomoro@238: # Copy new source files to the board giuliomoro@238: echo "Copying new pd projects to BeagleBone..." giuliomoro@238: scp $PROJECT_FILES "$BBB_ADDRESS:$BBB_LIBPD_PROJECT_PATH" giuliomoro@238: giuliomoro@238: if [ $? -ne 0 ] giuliomoro@238: then giuliomoro@238: echo "Error while copying files" giuliomoro@238: exit giuliomoro@238: fi giuliomoro@238: giuliomoro@238: # Make new BeagleRT executable and run giuliomoro@238: if [ $RUN_PROJECT -eq 0 ] giuliomoro@238: then giuliomoro@239: echo "Files copied. Run without \"-n\" to run the project" giuliomoro@238: else giuliomoro@238: echo "Running project..." giuliomoro@238: giuliomoro@238: if [ $RUN_WITHOUT_SCREEN -ne 0 ] giuliomoro@238: then giuliomoro@238: ssh -t $BBB_ADDRESS "cd $BBB_LIBPD_PROJECT_PATH && $BBB_LIBPD_EXECUTABLE_PATH $COMMAND_ARGS" giuliomoro@238: elif [ $RUN_IN_FOREGROUND -eq 0 ] giuliomoro@238: then giuliomoro@238: ssh $BBB_ADDRESS "cd $BBB_LIBPD_PROJECT_PATH && screen -S BeagleRT -d -m \ giuliomoro@238: $BBB_LIBPD_EXECUTABLE_PATH $COMMAND_ARGS" giuliomoro@238: else giuliomoro@238: ssh -t $BBB_ADDRESS "cd $BBB_LIBPD_PROJECT_PATH && screen -S BeagleRT $BBB_LIBPD_EXECUTABLE_PATH $COMMAND_ARGS" giuliomoro@238: fi giuliomoro@238: fi