-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathhaproxy-builder.sh
More file actions
462 lines (435 loc) · 12.9 KB
/
haproxy-builder.sh
File metadata and controls
462 lines (435 loc) · 12.9 KB
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
#!/usr/bin/env bash
shell_quote_string() {
echo "$1" | sed -e 's,\([^a-zA-Z0-9/_.=-]\),\\\1,g'
}
usage () {
cat <<EOF
Usage: $0 [OPTIONS]
The following options may be given :
--builddir=DIR Absolute path to the dir where all actions will be performed
--get_sources Source will be downloaded from github
--build_src_rpm If it is set - src rpm will be built
--build_src_deb If it is set - source deb package will be built
--build_rpm If it is set - rpm will be built
--build_deb If it is set - deb will be built
--install_deps Install build dependencies(root privilages are required)
--branch Branch for build
--repo Repo for build
--build_branch Branch for build packaging
--build_repo Repo for build packaging
--help) usage ;;
Example $0 --builddir=/tmp/BUILD --get_sources=1 --build_src_rpm=1 --build_rpm=1
EOF
exit 1
}
append_arg_to_args () {
args="$args "$(shell_quote_string "$1")
}
parse_arguments() {
pick_args=
if test "$1" = PICK-ARGS-FROM-ARGV
then
pick_args=1
shift
fi
for arg do
val=$(echo "$arg" | sed -e 's;^--[^=]*=;;')
case "$arg" in
--builddir=*) WORKDIR="$val" ;;
--build_src_rpm=*) SRPM="$val" ;;
--build_src_deb=*) SDEB="$val" ;;
--build_rpm=*) RPM="$val" ;;
--build_deb=*) DEB="$val" ;;
--get_sources=*) SOURCE="$val" ;;
--branch=*) BRANCH="$val" ;;
--repo=*) REPO="$val" ;;
--build_branch=*) BUILD_BRANCH="$val" ;;
--build_repo=*) BUILD_REPO="$val" ;;
--install_deps=*) INSTALL="$val" ;;
--help) usage ;;
*)
if test -n "$pick_args"
then
append_arg_to_args "$arg"
fi
;;
esac
done
}
check_workdir(){
if [ "x$WORKDIR" = "x$CURDIR" ]
then
echo >&2 "Current directory cannot be used for building!"
exit 1
else
if ! test -d "$WORKDIR"
then
echo >&2 "$WORKDIR is not a directory."
exit 1
fi
fi
return
}
get_sources(){
cd "${WORKDIR}"
if [ "${SOURCE}" = 0 ]
then
echo "Sources will not be downloaded"
return 0
fi
PRODUCT=percona-haproxy
echo "PRODUCT=${PRODUCT}" > haproxy.properties
PRODUCT_FULL=${PRODUCT}-${VERSION}
echo "PRODUCT_FULL=${PRODUCT_FULL}" >> haproxy.properties
echo "VERSION=${VERSION}" >> haproxy.properties
echo "BUILD_NUMBER=${BUILD_NUMBER}" >> haproxy.properties
echo "BUILD_ID=${BUILD_ID}" >> haproxy.properties
#git clone https://github.com/percona/haproxy-packaging.git
git clone ${BUILD_REPO}
cd haproxy-packaging
if [ ! -z "$BUILD_BRANCH" ]
then
git checkout ${BUILD_BRANCH}
fi
sed -i s/@@VERSION@@/${VERSION}/ rpm/percona-haproxy.spec
cd ..
git clone "$REPO" ${PRODUCT_FULL}
retval=$?
if [ $retval != 0 ]
then
echo "There were some issues during repo cloning from github. Please retry one more time"
exit 1
fi
cd ${PRODUCT_FULL}
if [ ! -z "$BRANCH" ]
then
git reset --hard
git clean -xdf
git checkout "$BRANCH"
fi
REVISION=$(git rev-parse --short HEAD)
echo "REVISION=${REVISION}" >> ${WORKDIR}/haproxy.properties
rm -fr debian rpm
mv ${WORKDIR}/haproxy-packaging/rpm ./
mv ${WORKDIR}/haproxy-packaging/debian ./
cd ../
tar --owner=0 --group=0 --exclude=.* -czf ${PRODUCT_FULL}.tar.gz ${PRODUCT_FULL}
DATE_TIMESTAMP=$(date +%F_%H-%M-%S)
echo "UPLOAD=UPLOAD/experimental/BUILDS/${PRODUCT}/${PRODUCT_FULL}/${BRANCH}/${REVISION}/${DATE_TIMESTAMP}/${BUILD_ID}" >> haproxy.properties
mkdir $WORKDIR/source_tarball
mkdir $CURDIR/source_tarball
cp ${PRODUCT_FULL}.tar.gz $WORKDIR/source_tarball
cp ${PRODUCT_FULL}.tar.gz $CURDIR/source_tarball
cd $CURDIR
rm -rf percona-haproxy*
return
}
get_system(){
if [ -f /etc/redhat-release ]; then
RHEL=$(rpm --eval %rhel)
ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g')
OS_NAME="el$RHEL"
OS="rpm"
elif [ -f /etc/amazon-linux-release ]; then
RHEL=$(rpm --eval %amzn)
ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g')
OS_NAME="amzn$RHEL"
OS="rpm"
else
ARCH=$(uname -m)
OS_NAME="$(lsb_release -sc)"
OS="deb"
fi
return
}
install_lua(){
cd /tmp
curl https://www.lua.org/ftp/lua-5.3.5.tar.gz > lua-5.3.5.tar.gz
tar xf lua-5.3.5.tar.gz
cd lua-5.3.5
sed -i '10s/-O2/-O2 -fPIC/' src/Makefile
make INSTALL_TOP=/opt/lua-5.3.5 linux install
make linux install
mv /usr/local/bin/lua* /usr/bin
mv /usr/local/include/lua* /usr/include
mv /usr/local/lib/liblua.a /usr/lib
cd $WORKDIR
rm -rf /tmp/lua-5.3.5*
}
switch_to_vault_repo() {
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
}
install_deps() {
if [ $INSTALL = 0 ]
then
echo "Dependencies will not be installed"
return;
fi
if [ $( id -u ) -ne 0 ]
then
echo "It is not possible to instal dependencies. Please run as root"
exit 1
fi
CURPLACE=$(pwd)
if [ "x$OS" = "xrpm" ]; then
if [ x"$RHEL" = x8 ]; then
switch_to_vault_repo
fi
yum -y install wget
yum clean all
INSTALL_LIST="git wget rpm-build gcc make tar pcre2-devel zlib-devel openssl-devel systemd systemd-devel readline-devel"
yum -y install ${INSTALL_LIST}
yum -y install lua-devel
install_lua
else
export DEBIAN=$(lsb_release -sc)
export ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g')
apt-get update || true
INSTALL_LIST="vim wget curl git debconf debhelper devscripts dh-exec libpcre2-dev libssl-dev liblua5.3-dev libsystemd-dev python3-sphinx zlib1g-dev python3-mako"
DEBIAN_FRONTEND=noninteractive apt-get -y install ${INSTALL_LIST}
if [ "x${DEBIAN}" = "xxenial" ]; then
DEBIAN_FRONTEND=noninteractive apt-get -y install dh-autoreconf=12~ubuntu16.04.1 debhelper=10.2.2ubuntu1~ubuntu16.04.1
fi
fi
return;
}
get_tar(){
TARBALL=$1
TARFILE=$(basename $(find $WORKDIR/$TARBALL -name 'percona-haproxy*.tar.gz' | sort | tail -n1))
if [ -z $TARFILE ]
then
TARFILE=$(basename $(find $CURDIR/$TARBALL -name 'percona-haproxy*.tar.gz' | sort | tail -n1))
if [ -z $TARFILE ]
then
echo "There is no $TARBALL for build"
exit 1
else
cp $CURDIR/$TARBALL/$TARFILE $WORKDIR/$TARFILE
fi
else
cp $WORKDIR/$TARBALL/$TARFILE $WORKDIR/$TARFILE
fi
return
}
get_deb_sources(){
param=$1
echo $param
FILE=$(basename $(find $WORKDIR/source_deb -name "percona-haproxy*.$param" | sort | tail -n1))
if [ -z $FILE ]
then
FILE=$(basename $(find $CURDIR/source_deb -name "percona-haproxy*.$param" | sort | tail -n1))
if [ -z $FILE ]
then
echo "There is no sources for build"
exit 1
else
cp $CURDIR/source_deb/$FILE $WORKDIR/
fi
else
cp $WORKDIR/source_deb/$FILE $WORKDIR/
fi
return
}
build_srpm(){
if [ $SRPM = 0 ]
then
echo "SRC RPM will not be created"
return;
fi
if [ "x$OS" = "xdeb" ]
then
echo "It is not possible to build src rpm here"
exit 1
fi
if [ x"$RHEL" = x8 ]; then
switch_to_vault_repo
fi
cd $WORKDIR
get_tar "source_tarball"
rm -fr rpmbuild
ls | grep -v tar.gz | xargs rm -rf
TARFILE=$(find . -name 'percona-haproxy*.tar.gz' | sort | tail -n1)
SRC_DIR=${TARFILE%.tar.gz}
#
mkdir -vp rpmbuild/{SOURCES,SPECS,BUILD,SRPMS,RPMS}
tar vxzf ${WORKDIR}/${TARFILE} --wildcards '*/rpm' --strip=1
#
cp -av rpm/* rpmbuild/SOURCES
cp -av rpm/percona-haproxy.spec rpmbuild/SPECS
cp -av rpm/haproxy* rpmbuild/SOURCES
#
mv -fv ${TARFILE} ${WORKDIR}/rpmbuild/SOURCES
rpmbuild -bs --define "_topdir ${WORKDIR}/rpmbuild" --define "dist .generic" \
--define "version ${VERSION}" rpmbuild/SPECS/percona-haproxy.spec
mkdir -p ${WORKDIR}/srpm
mkdir -p ${CURDIR}/srpm
cp rpmbuild/SRPMS/*.src.rpm ${CURDIR}/srpm
cp rpmbuild/SRPMS/*.src.rpm ${WORKDIR}/srpm
return
}
build_rpm(){
if [ $RPM = 0 ]
then
echo "RPM will not be created"
return;
fi
if [ "x$OS" = "xdeb" ]
then
echo "It is not possible to build rpm here"
exit 1
fi
if [ x"$RHEL" = x8 ]; then
switch_to_vault_repo
fi
SRC_RPM=$(basename $(find $WORKDIR/srpm -name 'percona-haproxy*.src.rpm' | sort | tail -n1))
if [ -z $SRC_RPM ]
then
SRC_RPM=$(basename $(find $CURDIR/srpm -name 'percona-haproxy*.src.rpm' | sort | tail -n1))
if [ -z $SRC_RPM ]
then
echo "There is no src rpm for build"
echo "You can create it using key --build_src_rpm=1"
exit 1
else
cp $CURDIR/srpm/$SRC_RPM $WORKDIR
fi
else
cp $WORKDIR/srpm/$SRC_RPM $WORKDIR
fi
cd $WORKDIR
rm -fr rb
mkdir -vp rb/{SOURCES,SPECS,BUILD,SRPMS,RPMS,BUILDROOT}
cp $SRC_RPM rb/SRPMS/
cd rb/SRPMS/
#
cd $WORKDIR
ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g')
rpmbuild --define "_topdir ${WORKDIR}/rb" --define "dist .$OS_NAME" --define "version ${VERSION}" --rebuild rb/SRPMS/$SRC_RPM
return_code=$?
if [ $return_code != 0 ]; then
exit $return_code
fi
mkdir -p ${WORKDIR}/rpm
mkdir -p ${CURDIR}/rpm
cp rb/RPMS/*/*.rpm ${WORKDIR}/rpm
cp rb/RPMS/*/*.rpm ${CURDIR}/rpm
}
build_source_deb(){
if [ $SDEB = 0 ]
then
echo "source deb package will not be created"
return;
fi
if [ "x$OS" = "xrpm" ]
then
echo "It is not possible to build source deb here"
exit 1
fi
rm -rf percona-haproxy*
get_tar "source_tarball"
rm -f *.dsc *.orig.tar.gz *.diff.gz *.changes
#
TARFILE=$(basename $(find . -name 'percona-haproxy*.tar.gz' | sort | tail -n1))
DEBIAN=$(lsb_release -sc)
ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g')
tar zxf ${TARFILE}
BUILDDIR=${TARFILE%.tar.gz}
#
mv ${TARFILE} ${PRODUCT}_${VERSION}.orig.tar.gz
cd ${BUILDDIR}
cd debian
rm -rf changelog
echo "percona-haproxy (${VERSION}-${RELEASE}) unstable; urgency=low" >> changelog
echo " * Initial Release." >> changelog
echo " -- EvgeniyPatlan <evgeniy.patlan@percona.com> $(date -R)" >> changelog
cd ../
dch -D unstable --force-distribution -v "${VERSION}-${RELEASE}" "Update to new haproxy version ${VERSION}"
dpkg-buildpackage -S
cd ../
mkdir -p $WORKDIR/source_deb
mkdir -p $CURDIR/source_deb
cp *_source.changes $WORKDIR/source_deb
cp *.dsc $WORKDIR/source_deb
cp *.orig.tar.gz $WORKDIR/source_deb
cp *.debian.tar.* $WORKDIR/source_deb
cp *.debian.tar.* $CURDIR/source_deb
cp *_source.changes $CURDIR/source_deb
cp *.dsc $CURDIR/source_deb
cp *.orig.tar.gz $CURDIR/source_deb
}
build_deb(){
if [ $DEB = 0 ]
then
echo "source deb package will not be created"
return;
fi
if [ "x$OS" = "xrmp" ]
then
echo "It is not possible to build source deb here"
exit 1
fi
for file in 'dsc' 'orig.tar.gz' 'changes' 'debian*'
do
get_deb_sources $file
done
cd $WORKDIR
rm -fv *.deb
#
export DEBIAN=$(lsb_release -sc)
export ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g')
#
echo "DEBIAN=${DEBIAN}" >> haproxy.properties
echo "ARCH=${ARCH}" >> haproxy.properties
#
DSC=$(basename $(find . -name '*.dsc' | sort | tail -n1))
#
dpkg-source -x ${DSC}
#
cd ${PRODUCT}-${VERSION}
#upstream set Epoch: 1 so we need to increase epoch
dch -m -D "${DEBIAN}" --force-distribution -v "2:${VERSION}-${RELEASE}.${DEBIAN}" 'Update distribution'
dpkg-buildpackage -rfakeroot -us -uc -b
mkdir -p $CURDIR/deb
mkdir -p $WORKDIR/deb
cd $WORKDIR/
for file in $(ls | grep ddeb); do
mv "$file" "${file%.ddeb}.deb";
done
cp $WORKDIR/*.*deb $WORKDIR/deb
cp $WORKDIR/*.*deb $CURDIR/deb
}
#main
CURDIR=$(pwd)
VERSION_FILE=$CURDIR/haproxy.properties
args=
WORKDIR=
SRPM=0
SDEB=0
RPM=0
DEB=0
SOURCE=0
OS_NAME=
ARCH=
OS=
INSTALL=0
RPM_RELEASE=1
DEB_RELEASE=1
REVISION=0
BUILD_REPO=https://github.com/percona/haproxy-packaging.git
BRANCH="v2.8.18"
REPO="http://git.haproxy.org/git/haproxy-2.8.git/"
PRODUCT=percona-haproxy
DEBUG=0
parse_arguments PICK-ARGS-FROM-ARGV "$@"
VERSION='2.8.18'
RELEASE='1'
PRODUCT_FULL=${PRODUCT}-${VERSION}-${RELEASE}
check_workdir
get_system
install_deps
get_sources
build_srpm
build_source_deb
build_rpm
build_deb