comparison scripts/setup_board.sh @ 412:a9c37b2a5b77 prerelease

Updated setup_board.sh, cleaner error handling, cleaner output
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 15 Jun 2016 23:05:09 +0100
parents 5f3d7c23ffa7
children
comparison
equal deleted inserted replaced
411:429260bd99b2 412:a9c37b2a5b77
15 This script copies the core Bela files to the BeagleBone, REMOVING 15 This script copies the core Bela files to the BeagleBone, REMOVING
16 any previous files found at that location. This should be done before 16 any previous files found at that location. This should be done before
17 running any of the other build scripts in this directory. The -b option 17 running any of the other build scripts in this directory. The -b option
18 changes the default path, which is otherwise $BBB_BELA_HOME." 18 changes the default path, which is otherwise $BBB_BELA_HOME."
19 } 19 }
20 trap "exit" SIGINT SIGTERM
21
22 function error_handler {
23 [ $1 -eq 0 ] && printf "done\n" || { [ -z "$2" ] && printf "\nAn error occurred. Is the board connected?\n" || printf "$2"; exit 1; }
24 }
20 25
21 OPTIND=1 26 OPTIND=1
22 27 ALWAYS_YES=0
23 while getopts "b:h" opt; do 28 while getopts "b:hy" opt; do
24 case $opt in 29 case $opt in
25 b) BBB_BELA_HOME=$OPTARG 30 b) BBB_BELA_HOME=$OPTARG
26 ;; 31 ;;
27 h|\?) usage 32 h|\?) usage
28 exit 1 33 exit 1
29 esac 34 ;;
35 y) ALWAYS_YES=1
36 ;;
37 esac
30 done 38 done
31 39
32 echo "Copying Bela core files to $BBB_BELA_HOME" 40 echo "Copying Bela core files to $BBB_BELA_HOME"
33 41
34 shift $((OPTIND-1)) 42 shift $((OPTIND-1))
36 # Find location of this script so we can locate the rest of the files 44 # Find location of this script so we can locate the rest of the files
37 SCRIPTPATH=$(readlink "$0") 45 SCRIPTPATH=$(readlink "$0")
38 SCRIPTDIR=$(dirname "$SCRIPTPATH") 46 SCRIPTDIR=$(dirname "$SCRIPTPATH")
39 [ -z "$IDE_FOLDER" ] && IDE_FOLDER=$SCRIPTDIR/../../bela-ide/ 47 [ -z "$IDE_FOLDER" ] && IDE_FOLDER=$SCRIPTDIR/../../bela-ide/
40 48
41 read -p "Warning: this script will DELETE any existing Bela files from your BeagleBone! Continue? (y/N) " -r 49 if [ $ALWAYS_YES -ne 1 ];
42 echo
43 if [[ $REPLY = [yY] ]]
44 then 50 then
51 printf "Warning: this script will DELETE any existing Bela files from your BeagleBone! Continue? (y/N) "
52 read REPLY;
53 [ $REPLY != y ] && [ $REPLY != Y ] && { echo "Aborting..."; exit 1; }
54 fi;
55
45 # Stop Bela if running and remove all files 56 # Stop Bela if running and remove all files
46 echo "Stopping Bela and removing old files." 57 printf "Stopping Bela and removing old files..."
47 ssh $BBB_ADDRESS "screen -X -S Bela quit &>/dev/null; pkill Bela; sleep 0.5 ; rm -rf $BBB_BELA_HOME ; mkdir $BBB_BELA_HOME" 58 ssh $BBB_ADDRESS "screen -X -S Bela quit &>/dev/null; pkill Bela; sleep 0.5 ; rm -rf $BBB_BELA_HOME ; mkdir $BBB_BELA_HOME";
59 error_handler $?
48 60
49 # Copy relevant files to BeagleBone Black 61 # Copy relevant files to BeagleBone Black
50 echo "Copying new files to BeagleBone..." 62 printf "Copying new files to BeagleBone..."
51 scp -q -r $SCRIPTDIR/../core $SCRIPTDIR/../include $SCRIPTDIR/../Makefile $SCRIPTDIR/../libNE10.a $SCRIPTDIR/../libprussdrv.a $SCRIPTDIR/../examples $SCRIPTDIR/../Doxyfile $BBB_ADDRESS:$BBB_BELA_HOME &&\ 63 scp -q -r $SCRIPTDIR/../core $SCRIPTDIR/../include $SCRIPTDIR/../Makefile $SCRIPTDIR/../libNE10.a $SCRIPTDIR/../libprussdrv.a $SCRIPTDIR/../examples $SCRIPTDIR/../Doxyfile $BBB_ADDRESS:$BBB_BELA_HOME &&\
52 scp -q $SCRIPTDIR/../libpd.so $BBB_ADDRESS:/usr/lib 64 scp -q $SCRIPTDIR/../libpd.so $BBB_ADDRESS:/usr/lib
53 if [ $? -ne 0 ] 65 error_handler $?
54 then 66
55 echo "Error while copying files"
56 exit
57 fi
58 # Create remaining directories needed for building 67 # Create remaining directories needed for building
59 echo "Creating directory structure on BeagleBone..." 68 printf "Creating directory structure on BeagleBone..."
60 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" &&\ 69 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"
61 echo "Done." 70 error_handler $?
62 echo "Creating on-board documentation..." 71
63 ssh $BBB_ADDRESS "cd $BBB_BELA_HOME; doxygen" &&\ 72 printf "Creating on-board documentation..."
64 echo "Done." 73 ssh $BBB_ADDRESS "cd $BBB_BELA_HOME; doxygen &>/dev/null"
65 else 74 error_handler $? "\nError while generating Doxygen documentation\n"
66 echo "Aborting..."
67 exit
68 fi
69 75
70 #------------- 76 #-------------
71 #Installing IDE 77 #Installing IDE
72 stat $IDE_FOLDER/scripts/setup_IDE.sh > /dev/null 78 stat $IDE_FOLDER/scripts/setup_IDE.sh &> /dev/null
73 if [ $? -eq 0 ] 79 if [ $? -eq 0 ]
74 then 80 then
75 cd $IDE_FOLDER/scripts; 81 cd $IDE_FOLDER/scripts;
76 ./setup_IDE.sh 82 ./setup_IDE.sh -y
77 else 83 else
78 echo "No IDE found, no IDE installed. You can get a copy of the IDE files from https://github.com/LBDonovan/bela-ide" 84 echo "Bela was installed on the board, but No IDE was found, so the IDE was not installed. You can get a copy of the IDE files from https://github.com/LBDonovan/bela-ide"
79 fi; 85 fi;