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