annotate scripts/run_pd_libpd.sh @ 239:dca0ca81b685

Typo
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 12 Apr 2016 14:21:40 +0200
parents 64e288a3d881
children a430a16d2c02
rev   line source
giuliomoro@238 1 #!/bin/bash
giuliomoro@238 2 #
giuliomoro@238 3 # This script compiles a BeagleRT project on the BeagleBone Black and
giuliomoro@238 4 # optionally runs it. Pass a directory path in the first argument.
giuliomoro@238 5 # The source files in this directory are copied to the board and compiled.
giuliomoro@238 6
giuliomoro@238 7 BBB_ADDRESS="root@192.168.7.2"
giuliomoro@238 8 BBB_LIBPD_EXECUTABLE_PATH="~/libpd/BeagleRT"
giuliomoro@238 9 BBB_LIBPD_PROJECT_PATH="~/libpd/source/"
giuliomoro@238 10 RUN_PROJECT=1
giuliomoro@238 11 COMMAND_ARGS=
giuliomoro@238 12 RUN_IN_FOREGROUND=0
giuliomoro@238 13 RUN_WITHOUT_SCREEN=0
giuliomoro@238 14
giuliomoro@238 15 function usage
giuliomoro@238 16 {
giuliomoro@238 17 THIS_SCRIPT=`basename "$0"`
giuliomoro@238 18 echo "Usage: $THIS_SCRIPT [-c command-line-args] [-nfF] <directory-with-source-files>"
giuliomoro@238 19 echo "
giuliomoro@238 20 This script copies a PureData project to the BeagleBone and runs it
giuliomoro@238 21 using libpd. The BeagleRT-libpd executable should have first been copied
giuliomoro@238 22 to the $BBB_LIBPD_EXECUTABLE_PATH folder on the Beaglebone.
giuliomoro@238 23 The source directory should contain a file called _main.pd, which is the
giuliomoro@238 24 patch that will be loaded into Pd. All the content of the folder is
giuliomoro@238 25 recursively copied and the folder structure is flattened.
giuliomoro@238 26 If the argument -n is passed, the output will not be run after compiling.
giuliomoro@238 27 The -c option passes command-line arguments to the BeagleRT program;
giuliomoro@238 28 enclose the argument string in quotes.
giuliomoro@238 29
giuliomoro@238 30 The -f argument runs the project in the foreground of the current terminal,
giuliomoro@238 31 within a screen session that can be detached later with ctrl-A ctrl-D.
giuliomoro@238 32 The -F argument runs the project in the foreground of the current terminal,
giuliomoro@238 33 without screen, so the output can be piped to another destination."
giuliomoro@238 34 }
giuliomoro@238 35
giuliomoro@238 36 OPTIND=1
giuliomoro@238 37
giuliomoro@238 38 while getopts "b:c:nfFh" opt; do
giuliomoro@238 39 case $opt in
giuliomoro@238 40 c) COMMAND_ARGS=$OPTARG
giuliomoro@238 41 ;;
giuliomoro@238 42 f) RUN_IN_FOREGROUND=1
giuliomoro@238 43 ;;
giuliomoro@238 44 F) RUN_WITHOUT_SCREEN=1
giuliomoro@238 45 ;;
giuliomoro@238 46 n) RUN_PROJECT=0
giuliomoro@238 47 ;;
giuliomoro@238 48 h|\?) usage
giuliomoro@238 49 exit 1
giuliomoro@238 50 esac
giuliomoro@238 51 done
giuliomoro@238 52
giuliomoro@238 53 shift $((OPTIND-1))
giuliomoro@238 54
giuliomoro@238 55 # Check that we have a directory containing at least one source file
giuliomoro@238 56 # as an argument
giuliomoro@238 57
giuliomoro@238 58 if [ -z "$1" ]
giuliomoro@238 59 then
giuliomoro@238 60 usage
giuliomoro@238 61 exit
giuliomoro@238 62 fi
giuliomoro@238 63
giuliomoro@238 64 FIND_STRING="find $* -maxdepth 10000 -type f "
giuliomoro@238 65
giuliomoro@238 66 PROJECT_FILES=$($FIND_STRING)
giuliomoro@238 67
giuliomoro@238 68 if [[ -z $PROJECT_FILES ]]
giuliomoro@238 69 then
giuliomoro@238 70 echo "Please provide a directory containing the _main.pd file and additional abstractions"
giuliomoro@238 71 usage
giuliomoro@238 72 exit
giuliomoro@238 73 fi
giuliomoro@238 74
giuliomoro@238 75 # Stop BeagleRT and clean out old source files
giuliomoro@238 76 echo "Stopping BeagleRT and removing old source files..."
giuliomoro@238 77 ssh -t -t $BBB_ADDRESS "screen -X -S BeagleRT quit &>/dev/null;\
giuliomoro@238 78 pkill BeagleRT ; rm -rf $BBB_LIBPD_PROJECT_PATH/; mkdir -p $BBB_LIBPD_PROJECT_PATH; "
giuliomoro@238 79
giuliomoro@238 80 # Copy new source files to the board
giuliomoro@238 81 echo "Copying new pd projects to BeagleBone..."
giuliomoro@238 82 scp $PROJECT_FILES "$BBB_ADDRESS:$BBB_LIBPD_PROJECT_PATH"
giuliomoro@238 83
giuliomoro@238 84 if [ $? -ne 0 ]
giuliomoro@238 85 then
giuliomoro@238 86 echo "Error while copying files"
giuliomoro@238 87 exit
giuliomoro@238 88 fi
giuliomoro@238 89
giuliomoro@238 90 # Make new BeagleRT executable and run
giuliomoro@238 91 if [ $RUN_PROJECT -eq 0 ]
giuliomoro@238 92 then
giuliomoro@239 93 echo "Files copied. Run without \"-n\" to run the project"
giuliomoro@238 94 else
giuliomoro@238 95 echo "Running project..."
giuliomoro@238 96
giuliomoro@238 97 if [ $RUN_WITHOUT_SCREEN -ne 0 ]
giuliomoro@238 98 then
giuliomoro@238 99 ssh -t $BBB_ADDRESS "cd $BBB_LIBPD_PROJECT_PATH && $BBB_LIBPD_EXECUTABLE_PATH $COMMAND_ARGS"
giuliomoro@238 100 elif [ $RUN_IN_FOREGROUND -eq 0 ]
giuliomoro@238 101 then
giuliomoro@238 102 ssh $BBB_ADDRESS "cd $BBB_LIBPD_PROJECT_PATH && screen -S BeagleRT -d -m \
giuliomoro@238 103 $BBB_LIBPD_EXECUTABLE_PATH $COMMAND_ARGS"
giuliomoro@238 104 else
giuliomoro@238 105 ssh -t $BBB_ADDRESS "cd $BBB_LIBPD_PROJECT_PATH && screen -S BeagleRT $BBB_LIBPD_EXECUTABLE_PATH $COMMAND_ARGS"
giuliomoro@238 106 fi
giuliomoro@238 107 fi