-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildremote.sh
280 lines (219 loc) · 5.5 KB
/
buildremote.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/bin/bash
#
##########################################################################
# Clue Configuration Manager
#
# Custom build workflow to compile annd build binaries for Splash module
#
# @version $Id: buildremote.sh 2087 2018-05-13 15:18:08Z stefan $
##########################################################################
# Set global variables and execute initialization operation
DPLDIR=/opt/clue
SRCDIR=/var/clue/sources
RLSDIR=/var/clue/releases
export MODULE="splash"
##########################################################################
function help()
{
echo "Usage: $0 [-rtmpa]"
echo " -r = remove completely target installation path"
echo " -m = create deployment target and run compiling process"
echo " -t = remove old target archive and create the new one"
echo " -p = install prerequisites"
echo " -d = download the source code"
echo " -c = cleaning compiling outputs"
echo " -a = execute pre-configuration before compiling"
echo " -i = install compiled binaries and resources"
echo
}
function start()
{
if [ "${MODULE}" != "" ]; then
NAME=$(echo "${MODULE}" | tr '[:lower:]' '[:upper:]')
echo ; echo "=============================================================================="
echo "Start building $NAME package" ; echo
fi
}
function stop()
{
if [ "${MODULE}" != "" ]; then
NAME=$(echo "${MODULE}" | tr '[:lower:]' '[:upper:]')
echo ; echo "End of building $NAME package"
echo "==============================================================================" ; echo
fi
}
function banner()
{
if [ "$1" != "" ] ; then
echo ; echo "------------------------------------------------------------------------------"
echo "$1" ; echo
fi
}
function check()
{
if [[ $? -ne 0 ]]; then
echo
echo "Builing process has been stopped because of error(s) met. Check the output messages or log file.." ;
exit $?
fi
}
function runPreparation()
{
if [[ "$1" = -*r* ]]; then
rm -rf $DPLDIR
fi
if [[ "$1" = -*m* ]] || [ "$1" = "" ] ; then
if [ ! -d $DPLDIR ]; then
mkdir -p $DPLDIR
fi
fi
if [[ "$1" = -*t* ]] || [ "$1" = "" ] ; then
rm -rf ${RLSDIR}/${MODULE}.tar.gz
if [ ! -d ${RLSDIR} ]; then
mkdir -p ${RLSDIR}
fi
fi
}
function runPrerequisites()
{
if [[ "$1" = -*p* ]] || [ "$1" = "" ] ; then
banner "Installing prerequisites.."
/opt/clue/bin/setup -s update -r expand
check
local kv=$(/usr/bin/dpkg -l | grep linux-image | sed -e 's/\s\+/ /g' | cut -f2 -d' ' | sed -e 's/linux-image//g')
apt-get install -y build-essential autoconf autopoint libtool pkg-config cmake gcc g++
apt-get install -y libraspberrypi-dev linux-headers${kv}
apt-get install -y git subversion wget curl tar zip unzip
prerequisites
/opt/clue/bin/setup -s update -r compact
fi
}
function runDownload()
{
if [[ "$1" = -*d* ]] || [ "$1" = "" ] ; then
banner "Downloading source code.."
if [ ! -d ${SRCDIR} ]; then mkdir -p ${SRCDIR}; fi
if [ -d ${SRCDIR}/${MODULE} ]; then
cd ${SRCDIR}/${MODULE}
svn update
else
cd ${SRCDIR}
svn checkout svn://amsd.go.ro/rootsvn/Clue/clue-1/${MODULE}/src ${MODULE}
/usr/bin/find ${SRCDIR}/${MODULE} -type f -exec chmod +x {} \;
fi
fi
}
function runClean()
{
if [[ "$1" = -*c* ]] ; then
banner "Cleaning environment.."
clean
fi
}
function runConfiguration()
{
if [[ "$1" = -*a* ]] || [ "$1" = "" ] ; then
banner "Configuring environment.."
configure
fi
}
function runMake()
{
BUILDTHREADS=${BUILDTHREADS:-$(grep -c "^processor" /proc/cpuinfo)}
[ ${BUILDTHREADS} -eq 0 ] && BUILDTHREADS=1
export BUILDTHREADS
if [[ "$1" = -*m* ]] || [ "$1" = "" ] ; then
banner "Compiling source code.."
make
fi
}
function runMakeInstall()
{
if [[ "$1" = -*i* ]] || [[ "$1" = -*m* ]] || [ "$1" = "" ] ; then
if [[ "$1" != -*i* ]]; then
if [[ "$1" = -*t* ]] || [ -d ${DPLDIR} ]; then
mv ${DPLDIR} ${DPLDIR}-bak
fi
fi
banner "Deploying binaries.."
makeinstall
fi
}
function runTar()
{
if [[ "$1" != -*i* ]]; then
if [[ "$1" = -*t* ]] || [ "$1" = "" ] ; then
banner "Writing binary package.."
/bin/tar -zcvf ${RLSDIR}/${MODULE}.tar.gz ${DPLDIR}
if [ -d ${DPLDIR}-bak ]; then
rm -rf ${DPLDIR}
mv ${DPLDIR}-bak ${DPLDIR}
fi
fi
fi
}
function run()
{
start
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
help
exit 0
fi
runPreparation $1
runPrerequisites $1
check
CURDIR=`pwd`
runDownload $1
check
if [ ! -d ${SRCDIR}/${MODULE} ]; then
echo -e "\tError: Package location doesn't exist: ${SRCDIR}/${MODULE}\n"
exit 1
fi
cd ${SRCDIR}/${MODULE}
runClean $1
check
cd ${SRCDIR}/${MODULE}
runConfiguration $1
check
cd ${SRCDIR}/${MODULE}
runMake $1
check
cd ${SRCDIR}/${MODULE}
runMakeInstall $1
check
cd ${SRCDIR}/${MODULE}
runTar $1
check
cd ${CURDIR}
stop
}
##########################################################################
# Implement specific functions
function prerequisites()
{
apt-get install -y libpng-dev libjpeg-dev libfreetype6-dev uthash-dev
## Stop service and make it to not run automatically
/opt/clue/bin/setup -s service -m "clue-splash"
}
function clean()
{
if [ -f ${SRCDIR}/${MODULE}/Makefile ]; then
/usr/bin/make clean
fi
}
function configure()
{
#nothing to do
echo "Nothing to configure additionally.."
}
function make()
{
/usr/bin/make -j ${BUILDTHREADS}
}
function makeinstall()
{
/usr/bin/make install
}
##########################################################################
run "$@" 2>&1 | tee /tmp/${MODULE}.log
##########################################################################