comparison scripts/build_project.sh @ 264:60ccd1fe5a58 prerelease

Using rsync instead of scp. scp remains as as fallback
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 16 May 2016 15:56:42 +0100
parents 7fe0d7c54bce
children 156191dffa8c
comparison
equal deleted inserted replaced
263:7fe0d7c54bce 264:60ccd1fe5a58
4 # optionally runs it. Pass a directory path in the first argument. 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. 5 # The source files in this directory are copied to the board and compiled.
6 6
7 # set defaults unless variables are already set 7 # set defaults unless variables are already set
8 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2" 8 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
9 [ -z "$BBB_PATH" ] && BBB_PATH="~/BeagleRT" 9 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/Bela/"
10 [ -z "$RUN_PROJECT" ] && RUN_PROJECT=1 10 [ -z "$RUN_PROJECT" ] && RUN_PROJECT=1
11 [ -z "$COMMAND_ARGS" ] && COMMAND_ARGS= 11 [ -z "$COMMAND_ARGS" ] && COMMAND_ARGS=
12 [ -z "$RUN_IN_FOREGROUND" ] && RUN_IN_FOREGROUND=1 12 [ -z "$RUN_IN_FOREGROUND" ] && RUN_IN_FOREGROUND=1
13 [ -z "$RUN_WITHOUT_SCREEN" ] && RUN_WITHOUT_SCREEN=0 13 [ -z "$RUN_WITHOUT_SCREEN" ] && RUN_WITHOUT_SCREEN=0
14 [ -z "$SCREEN_NAME" ] && SCREEN_NAME=Bela 14 [ -z "$SCREEN_NAME" ] && SCREEN_NAME=Bela
15 [ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/"
16 [ -x "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME="scriptUploadedProject"
15 17
16 function usage 18 function usage
17 { 19 {
18 THIS_SCRIPT=`basename "$0"` 20 THIS_SCRIPT=`basename "$0"`
19 echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-nfF] <directory-with-source-files>" 21 echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-nfF] <directory-with-source-files>"
37 39
38 OPTIND=1 40 OPTIND=1
39 41
40 while getopts "b:c:nfFh" opt; do 42 while getopts "b:c:nfFh" opt; do
41 case $opt in 43 case $opt in
42 b) BBB_PATH=$OPTARG 44 b) BBB_BELA_HOME=$OPTARG
43 ;; 45 ;;
44 c) COMMAND_ARGS=$OPTARG 46 c) COMMAND_ARGS=$OPTARG
45 ;; 47 ;;
46 f) RUN_IN_FOREGROUND=0 48 f) RUN_IN_FOREGROUND=0
47 ;; 49 ;;
48 F) RUN_WITHOUT_SCREEN=1 50 F) RUN_WITHOUT_SCREEN=1
49 ;; 51 ;;
50 n) RUN_PROJECT=0 52 n) RUN_PROJECT=0
51 ;; 53 ;;
52 h|\?) usage 54 h|\?) usage
53 exit 1 55 exit 1
83 echo "Stopping running program..." 85 echo "Stopping running program..."
84 # sets the date, stops the running process 86 # sets the date, stops the running process
85 ssh $BBB_ADDRESS "date -s '`date`' > /dev/null; screen -X -S '"$SCREEN_NAME"' quit &>/dev/null;" 87 ssh $BBB_ADDRESS "date -s '`date`' > /dev/null; screen -X -S '"$SCREEN_NAME"' quit &>/dev/null;"
86 88
87 #concatenate arguments to form path. 89 #concatenate arguments to form path.
88 BBB_SOURCE_PATH= #initially empty, will be filled with input arguments 90 HOST_SOURCE_PATH= #initially empty, will be filled with input arguments
89 for i in "$@" #parse input arguments 91 for i in "$@" #parse input arguments
90 do 92 do
91 if [ -d "$1" ] #check if the path is a folder 93 HOST_SOURCE_PATH+=" $1 "
92 then #if it is, include all of its files
93 BBB_SOURCE_PATH+=" ${1}/* "
94 else
95 BBB_SOURCE_PATH+=" $1 "
96 fi
97 shift 94 shift
98 # Copy new souce files to the board 95 # Copy new souce files to the board
99 done 96 done
100 97
101 # Copy new source files to the board 98 # Copy new source files to the board
102 echo "Copying new source files to BeagleBone..." 99 echo "Copying new source files to BeagleBone..."
103 scp $BBB_SOURCE_PATH "$BBB_ADDRESS:$BBB_PATH/source/" 100 if [ -z `which rsync` ];
101 then
102 #if rsync is not available, brutally clean the destination folder
103 #and copy over all the files again and recompile them
104 ssh bbb "make -C $BBB_BELA_HOME sourceclean";
105 scp $HOST_SOURCE_PATH "$BBB_ADDRESS:$BBB_BELA_HOME/source/"
106 else
107 #rsync --delete makes sure it removes files that are not in the origin folder
108 rsync -av --delete-after $HOST_SOURCE_PATH "$BBB_ADDRESS:$BBB_BELA_HOME/source/"
109 fi;
104 110
105 if [ $? -ne 0 ] 111 if [ $? -ne 0 ]
106 then 112 then
107 echo "Error while copying files" 113 echo "Error while copying files"
108 exit 114 exit
110 116
111 # Make new BeagleRT executable and run 117 # Make new BeagleRT executable and run
112 if [ $RUN_PROJECT -eq 0 ] 118 if [ $RUN_PROJECT -eq 0 ]
113 then 119 then
114 echo "Building project..." 120 echo "Building project..."
115 ssh $BBB_ADDRESS "make all -C $BBB_PATH" 121 ssh $BBB_ADDRESS "make all -C $BBB_BELA_HOME"
116 else 122 else
117 echo "Building and running project..." 123 echo "Building and running project..."
118 124
119 if [ $RUN_WITHOUT_SCREEN -ne 0 ] 125 if [ $RUN_WITHOUT_SCREEN -ne 0 ]
120 then 126 then
121 ssh -t $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && ../BeagleRT $COMMAND_ARGS" 127 ssh -t $BBB_ADDRESS "cd $BBB_BELA_HOME && make all && cd source && ../BeagleRT $COMMAND_ARGS"
122 elif [ $RUN_IN_FOREGROUND -eq 0 ] 128 elif [ $RUN_IN_FOREGROUND -eq 0 ]
123 then 129 then
124 ssh $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && screen -S $SCREEN_NAME -d -m ../BeagleRT $COMMAND_ARGS" 130 ssh $BBB_ADDRESS "cd $BBB_BELA_HOME && make all && cd source && screen -S $SCREEN_NAME -d -m ../BeagleRT $COMMAND_ARGS"
125 else 131 else
126 ssh -t $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && screen -S $SCREEN_NAME ../BeagleRT $COMMAND_ARGS" 132 ssh -t $BBB_ADDRESS "cd $BBB_BELA_HOME && make all && cd source && screen -S $SCREEN_NAME ../BeagleRT $COMMAND_ARGS"
127 fi 133 fi
128 fi 134 fi