comparison scripts/update_board @ 434:26f3ecfdf3ad prerelease

made update_board clickable
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 17 Jun 2016 01:10:05 +0100
parents scripts/update_board.sh@8c4b97cc63b8
children 2e058007c6bc
comparison
equal deleted inserted replaced
433:6c6e29391ec9 434:26f3ecfdf3ad
1 #!/bin/sh
2 #
3 # This script copies the core Bela files to the BeagleBone Black
4 # in preparation for building projects. It will remove any existing
5 # Bela directory before copying the files over
6
7 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
8 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="/root/Bela/"
9
10 FILES_TO_COPY="core include Makefile libNE10.a libprussdrv.a examples Doxyfile"
11
12 # The following variables are manually copied from the Makefile.
13 # It is a bit nasty, but here we need to handle the case that the board may be
14 # in any arbitrarily (bad) condition and try to handle it the best we can
15 BELA_IDE_SCREEN_NAME=IDE-Bela
16 SCREEN_NAME=Bela
17
18 usage ()
19 {
20 THIS_SCRIPT=`basename "$0"`
21 echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [--clean] [-y]"
22
23 echo "
24 This script updates the core Bela files on the BeagleBone, bringing it up
25 to date with the files in the folder on the host computer.
26 The script must be run once to initialize the board before running any of
27 the other scripts in this directory. It must also be run every time you
28 wish to update the core code.
29 Running this script will discard all changes to the core code on the remote
30 end.
31
32 Command line options:
33 -i arg : allows to set the username and IP address of the remote end (default: $BBB_ADDRESS)
34 -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)
35 --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.
36 -y : does not prompt the user before deleting the remote files.
37 "
38 }
39
40 signal_handler ()
41 {
42 echo
43 exit
44 }
45
46 trap signal_handler 2
47
48 error_handler () {
49 [ $1 -eq 0 ] && printf "done\n" || { [ -z "$2" ] && printf "\nAn error occurred. Is the board connected?\n" || printf "$2"; exit 1; }
50 }
51
52 OPTIND=1
53 ALWAYS_YES=0
54 RESET_BOARD=0
55 while [ "$1" != "" ]; do
56 case $1 in
57 -b)
58 shift
59 BBB_BELA_HOME=$1
60 ;;
61 -i)
62 shift
63 BBB_ADDRESS=$1
64 ;;
65 --clean)
66 RESET_BOARD=1
67 ;;
68 -y)
69 ALWAYS_YES=1
70 ;;
71 *)
72 usage
73 exit 1
74 ;;
75 esac
76 shift
77 done
78
79
80 # Find location of this script so we can locate the rest of the files
81 SCRIPTDIR=$(dirname "$0")
82 [ -z "$IDE_FOLDER" ] && IDE_FOLDER=$SCRIPTDIR/../../bela-ide/
83
84
85 ssh $BBB_ADDRESS "date -s \"`date '+%Y%m%d %T'`\" > /dev/null; stat $BBB_BELA_HOME &>/dev/null" && DESTINATION_EMPTY=0 || DESTINATION_EMPTY=1
86
87 if [ $DESTINATION_EMPTY -eq 0 ];
88 then
89 echo "Updating the Bela core code in $BBB_ADDRESS:$BBB_BELA_HOME"
90 if [ $RESET_BOARD -eq 1 ];
91 then
92 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) "
93 else
94 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) "
95 fi;
96 if [ $ALWAYS_YES -eq 1 ];
97 then
98 printf "y\n"
99 else
100 read REPLY;
101 [ $REPLY != y ] && [ $REPLY != Y ] && { echo "Aborting..."; exit 1; }
102 fi
103 else
104 echo "Installing Bela core code in $BBB_ADDRESS:$BBB_BELA_HOME"
105 fi
106
107 echo "Updating Bela cores files to remote folder $BBB_BELA_HOME"
108 # Stop Bela if running and remove all files
109 printf "Stopping Bela..."
110 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";
111 error_handler $?
112
113 if [ $RESET_BOARD -eq 1 ];
114 then
115 printf "Removing old files..."
116 ssh $BBB_ADDRESS "rm -rf $BBB_BELA_HOME";
117 error_handler $?
118 fi
119
120 #Check if rsync is available
121 [ -z `which rsync` ] && RSYNC_AVAILABLE=0 || RSYNC_AVAILABLE=1
122
123 # cd to the home of the project to make the following lines less verbose
124 RUN_FOLDER=`pwd`
125 cd $SCRIPTDIR/../
126
127 printf "Updating files..."
128 # Copy relevant files to BeagleBone Black
129 if [ $RSYNC_AVAILABLE -eq 1 ];
130 then
131 [ -z `which sed` ] && FILTER=cat || FILTER="sed s/\\n// | sed s/^.*:/Updated\ files:\/g | tr \"\n\" \" \""
132 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 &&\
133 rsync -ac --no-t libpd.so $BBB_ADDRESS:/usr/lib
134 else
135 # if rsync is not available, then clean the folders before copying the files
136 ssh $BBB_ADDRESS "rm -rf $FILES_TO_COPY; mkdir -p $BBB_BELA_HOME" &&\
137 scp -r -q $FILES_TO_COPY $BBB_ADDRESS:$BBB_BELA_HOME &&\
138 scp -q libpd.so $BBB_ADDRESS:/usr/lib
139 fi
140 error_handler $?
141 # cd back to the original folder.
142 cd "$RUN_FOLDER"
143
144 # Create remaining directories needed for building
145 printf "Creating directory structure on BeagleBone..."
146 ssh $BBB_ADDRESS "mkdir -p $BBB_BELA_HOME/build/core $BBB_BELA_HOME/projects"
147 error_handler $?
148
149 printf "Generating on-board documentation..."
150 ssh $BBB_ADDRESS "cd $BBB_BELA_HOME; doxygen &> /dev/null"
151 error_handler $? "\nError while generating Doxygen documentation\n"
152
153 #-------------
154 #Installing IDE
155 [ $ALWAYS_YES -eq 0 ] && ALWAYS_YES_FLAG= || ALWAYS_YES_FLAG="-y"
156 ls $IDE_FOLDER/scripts/setup_IDE.sh >/dev/null 2>/dev/null
157 if [ $? -eq 0 ]
158 then
159 cd $IDE_FOLDER/scripts && ./setup_IDE.sh $ALWAYS_YES_FLAG
160 # run the IDE
161 ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME --no-print-directory idestart"
162 else
163 # run the IDE
164 ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME --no-print-directory idestart"
165 echo \
166 "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.
167 You can get a copy of the most up-to-date IDE files from https://github.com/LBDonovan/bela-ide
168 "
169 fi
170
171 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"
172
173