andrewm@58
|
1 #!/bin/bash
|
andrewm@58
|
2 #
|
andrewm@58
|
3 # This script compiles a BeagleRT project on the BeagleBone Black and
|
andrewm@58
|
4 # optionally runs it. Pass a directory path in the first argument.
|
andrewm@58
|
5 # The source files in this directory are copied to the board and compiled.
|
andrewm@58
|
6
|
giuliomoro@262
|
7 # set defaults unless variables are already set
|
giuliomoro@262
|
8 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
|
giuliomoro@264
|
9 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/Bela/"
|
giuliomoro@262
|
10 [ -z "$RUN_PROJECT" ] && RUN_PROJECT=1
|
giuliomoro@262
|
11 [ -z "$COMMAND_ARGS" ] && COMMAND_ARGS=
|
giuliomoro@262
|
12 [ -z "$RUN_IN_FOREGROUND" ] && RUN_IN_FOREGROUND=1
|
giuliomoro@262
|
13 [ -z "$RUN_WITHOUT_SCREEN" ] && RUN_WITHOUT_SCREEN=0
|
giuliomoro@262
|
14 [ -z "$SCREEN_NAME" ] && SCREEN_NAME=Bela
|
giuliomoro@264
|
15 [ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/"
|
giuliomoro@264
|
16 [ -x "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME="scriptUploadedProject"
|
andrewm@58
|
17
|
andrewm@58
|
18 function usage
|
andrewm@58
|
19 {
|
andrewm@58
|
20 THIS_SCRIPT=`basename "$0"`
|
andrewm@90
|
21 echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-nfF] <directory-with-source-files>"
|
andrewm@58
|
22 echo "
|
andrewm@58
|
23 This script copies a directory of source files to the BeagleBone, compiles
|
andrewm@58
|
24 and runs it. The BeagleRT core files should have first been copied over
|
andrewm@58
|
25 using the setup_board.sh script supplied with BeagleRT.
|
andrewm@58
|
26
|
andrewm@58
|
27 The source directory should contain at least one .c, .cpp or .S file.
|
andrewm@58
|
28 If the argument -n is passed, the output will not be run after compiling.
|
andrewm@58
|
29 The argument -b will change the local path on the BeagleBone where the
|
andrewm@60
|
30 BeagleRT files are found. The -c option passes command-line arguments to
|
andrewm@90
|
31 the BeagleRT program; enclose the argument string in quotes.
|
andrewm@90
|
32
|
giuliomoro@263
|
33 By default, the project runs in the foreground of the current terminal,
|
andrewm@90
|
34 within a screen session that can be detached later. The -F argument runs
|
giuliomoro@263
|
35 the project in the foreground of the current terminal, without screen, so
|
giuliomoro@263
|
36 the output can be piped to another destination. The -f argument runs it
|
giuliomoro@263
|
37 in a screen in the background, so no output is shown."
|
andrewm@58
|
38 }
|
andrewm@58
|
39
|
andrewm@58
|
40 OPTIND=1
|
andrewm@58
|
41
|
andrewm@90
|
42 while getopts "b:c:nfFh" opt; do
|
andrewm@58
|
43 case $opt in
|
giuliomoro@264
|
44 b) BBB_BELA_HOME=$OPTARG
|
andrewm@58
|
45 ;;
|
andrewm@60
|
46 c) COMMAND_ARGS=$OPTARG
|
andrewm@60
|
47 ;;
|
giuliomoro@264
|
48 f) RUN_IN_FOREGROUND=0
|
andrewm@90
|
49 ;;
|
giuliomoro@264
|
50 F) RUN_WITHOUT_SCREEN=1
|
andrewm@90
|
51 ;;
|
andrewm@58
|
52 n) RUN_PROJECT=0
|
andrewm@58
|
53 ;;
|
andrewm@58
|
54 h|\?) usage
|
andrewm@58
|
55 exit 1
|
andrewm@58
|
56 esac
|
andrewm@58
|
57 done
|
andrewm@58
|
58
|
andrewm@58
|
59 shift $((OPTIND-1))
|
andrewm@58
|
60
|
andrewm@58
|
61 # Check that we have a directory containing at least one source file
|
andrewm@58
|
62 # as an argument
|
giuliomoro@64
|
63
|
andrewm@58
|
64 if [ -z "$1" ]
|
andrewm@58
|
65 then
|
andrewm@58
|
66 usage
|
andrewm@58
|
67 exit
|
andrewm@58
|
68 fi
|
andrewm@58
|
69
|
giuliomoro@64
|
70 FIND_STRING="find $* -maxdepth 10000 -type f "
|
giuliomoro@64
|
71
|
giuliomoro@64
|
72 C_FILES=$($FIND_STRING -name "*.c")
|
giuliomoro@64
|
73 CPP_FILES=$($FIND_STRING -name "*.cpp")
|
giuliomoro@64
|
74 ASM_FILES=$($FIND_STRING -name "*.S")
|
andrewm@58
|
75
|
andrewm@58
|
76 if [[ -z $C_FILES ]] && [[ -z $CPP_FILES ]] && [[ -z $ASM_FILES ]]
|
andrewm@58
|
77 then
|
andrewm@58
|
78 echo "Please provide a directory containing .c, .cpp or .S files."
|
andrewm@58
|
79 # echo "Usage: $THIS_SCRIPT [directory-with-source-files]"
|
andrewm@58
|
80 usage
|
andrewm@58
|
81 exit
|
andrewm@58
|
82 fi
|
andrewm@58
|
83
|
andrewm@58
|
84 # Stop BeagleRT and clean out old source files
|
giuliomoro@261
|
85 echo "Stopping running program..."
|
giuliomoro@261
|
86 # sets the date, stops the running process
|
giuliomoro@261
|
87 ssh $BBB_ADDRESS "date -s '`date`' > /dev/null; screen -X -S '"$SCREEN_NAME"' quit &>/dev/null;"
|
giuliomoro@64
|
88
|
giuliomoro@64
|
89 #concatenate arguments to form path.
|
giuliomoro@264
|
90 HOST_SOURCE_PATH= #initially empty, will be filled with input arguments
|
giuliomoro@64
|
91 for i in "$@" #parse input arguments
|
giuliomoro@64
|
92 do
|
giuliomoro@264
|
93 HOST_SOURCE_PATH+=" $1 "
|
giuliomoro@64
|
94 shift
|
giuliomoro@64
|
95 # Copy new souce files to the board
|
giuliomoro@64
|
96 done
|
andrewm@58
|
97
|
andrewm@58
|
98 # Copy new source files to the board
|
andrewm@58
|
99 echo "Copying new source files to BeagleBone..."
|
giuliomoro@264
|
100 if [ -z `which rsync` ];
|
giuliomoro@264
|
101 then
|
giuliomoro@264
|
102 #if rsync is not available, brutally clean the destination folder
|
giuliomoro@264
|
103 #and copy over all the files again and recompile them
|
giuliomoro@264
|
104 ssh bbb "make -C $BBB_BELA_HOME sourceclean";
|
giuliomoro@264
|
105 scp $HOST_SOURCE_PATH "$BBB_ADDRESS:$BBB_BELA_HOME/source/"
|
giuliomoro@264
|
106 else
|
giuliomoro@264
|
107 #rsync --delete makes sure it removes files that are not in the origin folder
|
giuliomoro@264
|
108 rsync -av --delete-after $HOST_SOURCE_PATH "$BBB_ADDRESS:$BBB_BELA_HOME/source/"
|
giuliomoro@264
|
109 fi;
|
giuliomoro@64
|
110
|
giuliomoro@64
|
111 if [ $? -ne 0 ]
|
giuliomoro@64
|
112 then
|
giuliomoro@64
|
113 echo "Error while copying files"
|
giuliomoro@64
|
114 exit
|
giuliomoro@64
|
115 fi
|
andrewm@58
|
116
|
andrewm@58
|
117 # Make new BeagleRT executable and run
|
andrewm@58
|
118 if [ $RUN_PROJECT -eq 0 ]
|
andrewm@58
|
119 then
|
andrewm@58
|
120 echo "Building project..."
|
giuliomoro@264
|
121 ssh $BBB_ADDRESS "make all -C $BBB_BELA_HOME"
|
andrewm@58
|
122 else
|
andrewm@58
|
123 echo "Building and running project..."
|
andrewm@90
|
124
|
andrewm@90
|
125 if [ $RUN_WITHOUT_SCREEN -ne 0 ]
|
andrewm@90
|
126 then
|
giuliomoro@264
|
127 ssh -t $BBB_ADDRESS "cd $BBB_BELA_HOME && make all && cd source && ../BeagleRT $COMMAND_ARGS"
|
andrewm@90
|
128 elif [ $RUN_IN_FOREGROUND -eq 0 ]
|
andrewm@90
|
129 then
|
giuliomoro@264
|
130 ssh $BBB_ADDRESS "cd $BBB_BELA_HOME && make all && cd source && screen -S $SCREEN_NAME -d -m ../BeagleRT $COMMAND_ARGS"
|
andrewm@90
|
131 else
|
giuliomoro@264
|
132 ssh -t $BBB_ADDRESS "cd $BBB_BELA_HOME && make all && cd source && screen -S $SCREEN_NAME ../BeagleRT $COMMAND_ARGS"
|
andrewm@90
|
133 fi
|
giuliomoro@249
|
134 fi
|