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