-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·240 lines (200 loc) · 5.17 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/bash
### Defaults ###
auto=false
threads=1
default_command="all"
### Config ###
opencv_version="3.2.0"
### Usage ###
usage() {
echo "
usage: ./build.sh [options] [command]
Note -- script should be run only when in the same directory as the script.
Available commands:
all - run all of the following, in order.
update - download updates and build dependencies (via apt-get)
download - download and decompress source code
build - run the configure and build steps
install - install opencv globally
Available options:
--auto - No \"Are you sure\" questions.
--threads n - execute the build process with n number of threads. 1 is recommended due to opencv stability issues with multiple threads running.
--usage - show this text.
Examples:
./build.sh all (runs all steps)
./build.sh build --threads 2 (runs the build step only with 2 threads (update and download need to already have been run)
"
exit 0
}
### Get arguments using getopt###
getopt --test > /dev/null
if [[ $? -ne 4 ]]; then
echo "I’m sorry, `getopt --test` failed in this environment."
exit 1
fi
SHORT=aft:u
LONG=auto,threads:,usage
PARSED=$(getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@")
if [[ $? -ne 0 ]]; then
exit 2
fi
eval set -- "$PARSED"
while true; do
case "$1" in
-a|--auto)
auto=true
shift
;;
-t|--threads)
threads="$2"
shift 2
;;
-u|--usage)
usage
shift
;;
--)
shift
break
;;
*)
shift
echo "Internal error"
exit 3
;;
esac
done
if [[ $# -ne 1 ]]; then
read -p "No command given. Did you want to run all steps for global installation (y/n)? " choice
case "$choice" in
y|Y )
echo
;;
n|N )
usage
exit 1
;;
* )
echo "Invalid choice."
usage
exit 1
;;
esac
fi
### WARNING ###
echo "Designed for only for Raspberry Pis running Raspbian Jessie."
echo "This script is in active development and may contain bugs."
echo "Please ensure all your files are backed up before continuing."
echo "--------------------------------------------------------------"
echo
if [ "$auto" = false ]; then
read -p "Continue (y/n)? " choice
case "$choice" in
y|Y )
echo
;;
n|N )
exit 1
;;
* )
echo "Invalid choice."
exit 1
;;
esac
fi
### Defining functions ###
main() {
command=$1
threads=$2
case "$command" in
all)
update
get_dependencies
download
expand
configure
build $threads
install
;;
update)
update
get_dependencies
;;
download)
download
expand
;;
build)
configure
build $threads
;;
install)
install
;;
esac
}
update() {
### system upgrade ###
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get upgrade --yes
}
get_dependencies() {
export DEBIAN_FRONTEND=noninteractive
sudo apt-get install --yes build-essential cmake pkg-config libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev libgtk2.0-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libv4l-0 libv4l-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libatlas-base-dev gfortran python-numpy python-scipy python-matplotlib default-jdk ant libgtkglext1-dev v4l-utils
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
sudo apt install python2.7-dev
sudo pip install numpy
}
download() {
echo 'Downloading opencv source'
### Get opencv ###
wget -O opencv.zip https://github.com/opencv/opencv/archive/"$opencv_version".zip
### Get opencv_contrib ###
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/"$opencv_version".zip
}
expand() {
echo 'Expanding source code'
unzip opencv.zip
unzip opencv_contrib.zip
}
configure() {
echo 'Configuring opencv'
cd $PWD/opencv-3.2.0/
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=$PWD/../../opencv_contrib-3.2.0/modules \
-D BUILD_EXAMPLES=ON \
-D ENABLE_NEON=ON ..
cd ..
cd ..
}
build() {
threads=$1
echo "Building with $threads thread(s)."
cd $PWD/opencv-3.2.0/
cd build
threadArg="-j$threads"
make "$threadArg"
cd ..
cd ..
}
install() {
echo 'Installing opencv to system.'
cd $PWD/opencv-3.2.0/
cd build
sudo make install
cd ..
cd ..
}
#todo implement cleanup()
#todo implement uninstall()
### End function definitions ###
### Execute command
command=$1
main $command $threads