comparison scripts/update_board.sh @ 413:d874b5696078 prerelease

renamed setup_board.sh to update_board.sh. Comes with plenty of new functionalities, prompts etc. When called without parameters will only update the relevant files, leaving the projects/ folder alone. When called with --clean will nuke the whole remote Bela folder and restore it.
author Giulio Moro <giuliomoro@yahoo.it>
date Thu, 16 Jun 2016 01:31:04 +0100
parents scripts/setup_board.sh@a9c37b2a5b77
children 947cb6ef73e7
comparison
equal deleted inserted replaced
412:a9c37b2a5b77 413:d874b5696078
1 #!/bin/bash
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 function 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 comouter.
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 trap "echo; exit" SIGINT SIGTERM
40
41 function error_handler {
42 [ $1 -eq 0 ] && printf "done\n" || { [ -z "$2" ] && printf "\nAn error occurred. Is the board connected?\n" || printf "$2"; exit 1; }
43 }
44
45 OPTIND=1
46 ALWAYS_YES=0
47 RESET_BOARD=0
48 while [ "$1" != "" ]; do
49 case $1 in
50 -b)
51 shift
52 BBB_BELA_HOME=$1
53 ;;
54 -i)
55 shift
56 BBB_ADDRESS=$1
57 ;;
58 --clean)
59 RESET_BOARD=1
60 ;;
61 -y)
62 ALWAYS_YES=1
63 ;;
64 *)
65 usage
66 exit 1
67 ;;
68 esac
69 shift
70 done
71
72
73 # Find location of this script so we can locate the rest of the files
74 SCRIPTPATH=$(readlink "$0")
75 SCRIPTDIR=$(dirname "$SCRIPTPATH")
76 [ -z "$IDE_FOLDER" ] && IDE_FOLDER=$SCRIPTDIR/../../bela-ide/
77
78
79 ssh $BBB_ADDRESS "stat $BBB_BELA_HOME &>/dev/null" && DESTINATION_EMPTY=0 || DESTINATION_EMPTY=1
80
81 if [ $DESTINATION_EMPTY -eq 0 ];
82 then
83 echo "Updating the Bela core code in $BBB_ADDRESS:$BBB_BELA_HOME"
84 if [ $RESET_BOARD -eq 1 ];
85 then
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) "
87 else
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) "
89 fi;
90 if [ $ALWAYS_YES -eq 1 ];
91 then
92 printf "y\n"
93 else
94 read REPLY;
95 [ $REPLY != y ] && [ $REPLY != Y ] && { echo "Aborting..."; exit 1; }
96 fi
97 else
98 echo "Installing Bela core code in $BBB_ADDRESS:$BBB_BELA_HOME"
99 fi
100
101 echo "Updating Bela core files to remote folder $BBB_BELA_HOME"
102 # Stop Bela if running and remove all files
103 printf "Stopping Bela..."
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";
105 error_handler $?
106
107 if [ $RESET_BOARD -eq 1 ];
108 then
109 printf "Removing old files..."
110 ssh $BBB_ADDRESS "rm -rf $BBB_BELA_HOME";
111 error_handler $?
112 fi
113
114 #Check if rsync is available
115 [ -z `which rsync` ] && RSYNC_AVAILABLE=0 || RSYNC_AVAILABLE=1
116
117 cd $SCRIPTDIR/../
118 printf "Updating files..."
119 # Copy relevant files to BeagleBone Black
120 if [ $RSYNC_AVAILABLE -eq 1 ];
121 then
122 [ -z `which sed` ] && FILTER=cat || FILTER="sed s/\\n// | sed s/^.*:/Updated\ files:\/g | tr \"\n\" \" \""
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 &&\
124 rsync -ac --no-t libpd.so $BBB_ADDRESS:/usr/lib
125 else
126 # if rsync is not available, then clean the folders before copying the files
127 ssh $BBB_ADDRESS "rm -rf $FILES_TO_COPY; mkdir -p $BBB_BELA_HOME" &&\
128 scp -r -q $FILES_TO_COPY $BBB_ADDRESS:$BBB_BELA_HOME &&\
129 scp -q libpd.so $BBB_ADDRESS:/usr/lib
130 fi
131 error_handler $?
132
133 # Create remaining directories needed for building
134 printf "Creating directory structure on BeagleBone..."
135 #ssh $BBB_ADDRESS "mkdir -p $BBB_BELA_HOME/build ; mkdir -p $BBB_BELA_HOME/build/core ; mkdir -p $BBB_BELA_HOME/build/projects; mkdir -p $BBB_BELA_HOME/projects"
136 error_handler $?
137
138 printf "Generating on-board documentation..."
139 ssh $BBB_ADDRESS "cd $BBB_BELA_HOME; doxygen &>/dev/null"
140 error_handler $? "\nError while generating Doxygen documentation\n"
141
142 #-------------
143 #Installing IDE
144 stat $IDE_FOLDER/scripts/setup_IDE.sh &> /dev/null
145 if [ $? -eq 0 ]
146 then
147 cd $IDE_FOLDER/scripts;
148 ./setup_IDE.sh -y
149 # run the IDE
150 ssh $BBB_ADDRESS "make -C $BBB_BELA_HOME --no-print-directory idestart"
151 else
152 echo \
153 "Bela was installed on the board, but No IDE was found, so the IDE was not installed.
154 You can get a copy of the IDE files from https://github.com/LBDonovan/bela-ide"
155 fi;