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