giuliomoro@425
|
1 #!/bin/sh
|
andrewm@58
|
2 #
|
giuliomoro@377
|
3 # This script copies the core Bela files to the BeagleBone Black
|
andrewm@58
|
4 # in preparation for building projects. It will remove any existing
|
giuliomoro@377
|
5 # Bela directory before copying the files over
|
giuliomoro@367
|
6 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
|
giuliomoro@413
|
7 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="/root/Bela/"
|
giuliomoro@447
|
8
|
giuliomoro@447
|
9 . ./.bela_common || exit 1
|
giuliomoro@413
|
10
|
giuliomoro@413
|
11 FILES_TO_COPY="core include Makefile libNE10.a libprussdrv.a examples Doxyfile"
|
giuliomoro@413
|
12
|
giuliomoro@413
|
13 # The following variables are manually copied from the Makefile.
|
giuliomoro@413
|
14 # It is a bit nasty, but here we need to handle the case that the board may be
|
giuliomoro@413
|
15 # in any arbitrarily (bad) condition and try to handle it the best we can
|
giuliomoro@413
|
16 BELA_IDE_SCREEN_NAME=IDE-Bela
|
giuliomoro@413
|
17 SCREEN_NAME=Bela
|
giuliomoro@413
|
18
|
giuliomoro@428
|
19 usage ()
|
andrewm@58
|
20 {
|
andrewm@58
|
21 THIS_SCRIPT=`basename "$0"`
|
giuliomoro@452
|
22 echo "Usage: $THIS_SCRIPT [--clean] [--no-frills] [-dy ] [-i user@ip] [-b /path/to/remote/Bela]"
|
andrewm@58
|
23
|
andrewm@58
|
24 echo "
|
giuliomoro@413
|
25 This script updates the core Bela files on the BeagleBone, bringing it up
|
giuliomoro@415
|
26 to date with the files in the folder on the host computer.
|
giuliomoro@413
|
27 The script must be run once to initialize the board before running any of
|
giuliomoro@413
|
28 the other scripts in this directory. It must also be run every time you
|
giuliomoro@413
|
29 wish to update the core code.
|
giuliomoro@413
|
30 Running this script will discard all changes to the core code on the remote
|
giuliomoro@413
|
31 end.
|
giuliomoro@413
|
32
|
giuliomoro@413
|
33 Command line options:
|
giuliomoro@413
|
34 -i arg : allows to set the username and IP address of the remote end (default: $BBB_ADDRESS)
|
giuliomoro@413
|
35 -b arg : allows to set the path to the Bela folder on the remote end. Use quotes if you use the \"~\" symbol (default: $BBB_BELA_HOME)
|
giuliomoro@413
|
36 --clean : removes all the files in the $BBB_BELA_HOME folder, INCLUDING any source code you may have in the $BBB_BELA_HOME/projects/ subdirectory.
|
giuliomoro@452
|
37 -d : skips re-generating Doxygen documentation on the board.
|
giuliomoro@452
|
38 --no-frills : skips some optional commands.
|
giuliomoro@413
|
39 -y : does not prompt the user before deleting the remote files.
|
giuliomoro@413
|
40 "
|
andrewm@58
|
41 }
|
giuliomoro@412
|
42
|
giuliomoro@428
|
43 signal_handler ()
|
giuliomoro@428
|
44 {
|
giuliomoro@428
|
45 echo
|
giuliomoro@428
|
46 exit
|
giuliomoro@428
|
47 }
|
giuliomoro@428
|
48
|
giuliomoro@432
|
49 trap signal_handler 2
|
giuliomoro@428
|
50
|
giuliomoro@428
|
51 error_handler () {
|
giuliomoro@412
|
52 [ $1 -eq 0 ] && printf "done\n" || { [ -z "$2" ] && printf "\nAn error occurred. Is the board connected?\n" || printf "$2"; exit 1; }
|
giuliomoro@412
|
53 }
|
andrewm@58
|
54
|
giuliomoro@452
|
55 FULL=1
|
andrewm@58
|
56 OPTIND=1
|
giuliomoro@412
|
57 ALWAYS_YES=0
|
giuliomoro@413
|
58 RESET_BOARD=0
|
giuliomoro@452
|
59 DOXYGEN=1
|
giuliomoro@413
|
60 while [ "$1" != "" ]; do
|
giuliomoro@413
|
61 case $1 in
|
giuliomoro@413
|
62 -b)
|
giuliomoro@413
|
63 shift
|
giuliomoro@413
|
64 BBB_BELA_HOME=$1
|
giuliomoro@413
|
65 ;;
|
giuliomoro@413
|
66 -i)
|
giuliomoro@413
|
67 shift
|
giuliomoro@413
|
68 BBB_ADDRESS=$1
|
giuliomoro@413
|
69 ;;
|
giuliomoro@413
|
70 --clean)
|
giuliomoro@413
|
71 RESET_BOARD=1
|
giuliomoro@413
|
72 ;;
|
giuliomoro@452
|
73 -d)
|
giuliomoro@452
|
74 DOXYGEN=0
|
giuliomoro@452
|
75 ;;
|
giuliomoro@452
|
76 --no-frills)
|
giuliomoro@452
|
77 FULL=0
|
giuliomoro@452
|
78 ;;
|
giuliomoro@413
|
79 -y)
|
giuliomoro@413
|
80 ALWAYS_YES=1
|
giuliomoro@413
|
81 ;;
|
giuliomoro@413
|
82 *)
|
giuliomoro@413
|
83 usage
|
giuliomoro@413
|
84 exit 1
|
giuliomoro@413
|
85 ;;
|
giuliomoro@412
|
86 esac
|
giuliomoro@413
|
87 shift
|
andrewm@58
|
88 done
|
andrewm@58
|
89
|
andrewm@58
|
90
|
andrewm@58
|
91 # Find location of this script so we can locate the rest of the files
|
giuliomoro@427
|
92 SCRIPTDIR=$(dirname "$0")
|
l@405
|
93 [ -z "$IDE_FOLDER" ] && IDE_FOLDER=$SCRIPTDIR/../../bela-ide/
|
andrewm@58
|
94
|
giuliomoro@452
|
95 # Set the date on the board
|
giuliomoro@452
|
96 [ $FULL -eq 1 ] && set_date
|
giuliomoro@452
|
97 # Check if destination folder exists
|
giuliomoro@452
|
98 ssh $BBB_ADDRESS stat $BBB_BELA_HOME &>/dev/null && DESTINATION_EMPTY=0 || DESTINATION_EMPTY=1
|
giuliomoro@413
|
99
|
giuliomoro@413
|
100 if [ $DESTINATION_EMPTY -eq 0 ];
|
andrewm@58
|
101 then
|
giuliomoro@413
|
102 echo "Updating the Bela core code in $BBB_ADDRESS:$BBB_BELA_HOME"
|
giuliomoro@413
|
103 if [ $RESET_BOARD -eq 1 ];
|
giuliomoro@413
|
104 then
|
giuliomoro@413
|
105 printf "DANGER: you are about to perform a HARD RESET, which will DELETE all the existing files from the folder $BBB_BELA_HOME on the BeagleBone Black.\nAre you sure you want to continue? (y/N) "
|
giuliomoro@413
|
106 else
|
giuliomoro@413
|
107 printf "All the changes to the CORE files in the remote folder $BBB_BELA_HOME will be LOST. The content of these files/folders will be lost:\n $FILES_TO_COPY \nYour projects stored in $BBB_BELA_HOME/projects should be safe (and surely you have already backed them up somewhere safe, haven't you?).\nAre you sure you want to continue? (y/N) "
|
giuliomoro@413
|
108 fi;
|
giuliomoro@413
|
109 if [ $ALWAYS_YES -eq 1 ];
|
giuliomoro@413
|
110 then
|
giuliomoro@413
|
111 printf "y\n"
|
giuliomoro@413
|
112 else
|
giuliomoro@413
|
113 read REPLY;
|
giuliomoro@439
|
114 [ -z "$REPLY" ] || { [ "$REPLY" != y ] && [ "$REPLY" != Y ]; } && { echo "Aborting..."; exit 1; }
|
giuliomoro@413
|
115 fi
|
giuliomoro@413
|
116 else
|
giuliomoro@413
|
117 echo "Installing Bela core code in $BBB_ADDRESS:$BBB_BELA_HOME"
|
giuliomoro@413
|
118 fi
|
giuliomoro@412
|
119
|
giuliomoro@452
|
120 echo "Updating Bela core files to remote folder $BBB_BELA_HOME"
|
giuliomoro@377
|
121 # Stop Bela if running and remove all files
|
giuliomoro@413
|
122 printf "Stopping Bela..."
|
giuliomoro@413
|
123 ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME idestop stop &>/dev/null; screen -X -S Bela quit &>/dev/null; screen -X -S IDE-Bela quit &>/dev/null; true";
|
giuliomoro@412
|
124 error_handler $?
|
andrewm@58
|
125
|
giuliomoro@413
|
126 if [ $RESET_BOARD -eq 1 ];
|
giuliomoro@413
|
127 then
|
giuliomoro@413
|
128 printf "Removing old files..."
|
giuliomoro@413
|
129 ssh $BBB_ADDRESS "rm -rf $BBB_BELA_HOME";
|
giuliomoro@413
|
130 error_handler $?
|
giuliomoro@413
|
131 fi
|
giuliomoro@413
|
132
|
giuliomoro@413
|
133 #Check if rsync is available
|
giuliomoro@413
|
134 [ -z `which rsync` ] && RSYNC_AVAILABLE=0 || RSYNC_AVAILABLE=1
|
giuliomoro@413
|
135
|
giuliomoro@420
|
136 # cd to the home of the project to make the following lines less verbose
|
giuliomoro@420
|
137 RUN_FOLDER=`pwd`
|
giuliomoro@413
|
138 cd $SCRIPTDIR/../
|
giuliomoro@420
|
139
|
giuliomoro@413
|
140 printf "Updating files..."
|
andrewm@58
|
141 # Copy relevant files to BeagleBone Black
|
giuliomoro@413
|
142 if [ $RSYNC_AVAILABLE -eq 1 ];
|
giuliomoro@413
|
143 then
|
giuliomoro@413
|
144 [ -z `which sed` ] && FILTER=cat || FILTER="sed s/\\n// | sed s/^.*:/Updated\ files:\/g | tr \"\n\" \" \""
|
giuliomoro@413
|
145 rsync -ac --no-t --delete-after --stats $FILES_TO_COPY $BBB_ADDRESS:$BBB_BELA_HOME |grep -i "Number" | grep -i "files" | grep -i "transferred" | eval $FILTER &&\
|
giuliomoro@413
|
146 rsync -ac --no-t libpd.so $BBB_ADDRESS:/usr/lib
|
giuliomoro@413
|
147 else
|
giuliomoro@413
|
148 # if rsync is not available, then clean the folders before copying the files
|
giuliomoro@413
|
149 ssh $BBB_ADDRESS "rm -rf $FILES_TO_COPY; mkdir -p $BBB_BELA_HOME" &&\
|
giuliomoro@413
|
150 scp -r -q $FILES_TO_COPY $BBB_ADDRESS:$BBB_BELA_HOME &&\
|
giuliomoro@413
|
151 scp -q libpd.so $BBB_ADDRESS:/usr/lib
|
giuliomoro@413
|
152 fi
|
giuliomoro@412
|
153 error_handler $?
|
giuliomoro@420
|
154 # cd back to the original folder.
|
giuliomoro@420
|
155 cd "$RUN_FOLDER"
|
giuliomoro@412
|
156
|
giuliomoro@402
|
157 # Create remaining directories needed for building
|
giuliomoro@412
|
158 printf "Creating directory structure on BeagleBone..."
|
giuliomoro@415
|
159 ssh $BBB_ADDRESS "mkdir -p $BBB_BELA_HOME/build/core $BBB_BELA_HOME/projects"
|
giuliomoro@412
|
160 error_handler $?
|
giuliomoro@412
|
161
|
giuliomoro@452
|
162 if [ $DOXYGEN -eq 1 ]
|
giuliomoro@452
|
163 then
|
giuliomoro@452
|
164 printf "Generating on-board documentation..."
|
giuliomoro@452
|
165 ssh $BBB_ADDRESS "cd $BBB_BELA_HOME; doxygen &> /dev/null"
|
giuliomoro@452
|
166 error_handler $? "\nError while generating Doxygen documentation\n"
|
giuliomoro@452
|
167 fi
|
andrewm@58
|
168
|
giuliomoro@402
|
169 #-------------
|
giuliomoro@402
|
170 #Installing IDE
|
giuliomoro@432
|
171 [ $ALWAYS_YES -eq 0 ] && ALWAYS_YES_FLAG= || ALWAYS_YES_FLAG="-y"
|
giuliomoro@428
|
172 ls $IDE_FOLDER/scripts/setup_IDE.sh >/dev/null 2>/dev/null
|
giuliomoro@402
|
173 if [ $? -eq 0 ]
|
giuliomoro@402
|
174 then
|
giuliomoro@432
|
175 cd $IDE_FOLDER/scripts && ./setup_IDE.sh $ALWAYS_YES_FLAG
|
giuliomoro@413
|
176 # run the IDE
|
giuliomoro@452
|
177 [ $FULL -eq 1 ] && ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME --no-print-directory idestart"
|
giuliomoro@402
|
178 else
|
giuliomoro@419
|
179 # run the IDE
|
giuliomoro@452
|
180 [ $FULL -eq 1 ] && ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME --no-print-directory idestart"
|
giuliomoro@452
|
181 [ $FULL -eq 1 ] && echo "The Bela core files were updated the board, but a valid IDE folder was not found in $IDE_FOLDER/, so the IDE was not updated. If there was an older version of the IDE on the board, it is being restarted.
|
giuliomoro@428
|
182 You can get a copy of the most up-to-date IDE files from https://github.com/LBDonovan/bela-ide
|
giuliomoro@428
|
183 "
|
giuliomoro@419
|
184 fi
|
giuliomoro@421
|
185
|
giuliomoro@421
|
186 ssh $BBB_ADDRESS make -C $BBB_BELA_HOME --no-print-directory idestartup nostartup && echo "The board will now run the IDE at startup, but startup of the Bela program has been disabled. To enable it, use the set_startup.sh script"
|
giuliomoro@421
|
187
|
giuliomoro@452
|
188 [ $ALWAYS_YES -eq 1 ] && printf "\nSetup complete.\n\n" || {
|
giuliomoro@437
|
189 printf '\nSetup complete, press any key to continue\n\n'
|
giuliomoro@437
|
190 read
|
giuliomoro@437
|
191 }
|