forked from Percona-Lab/patchelf-packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatchelf_builder.sh
488 lines (438 loc) · 13.5 KB
/
patchelf_builder.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
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
#!/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 1 src rpm will be built
--build_source_deb If it is 1 source deb package will be built
--build_rpm If it is 1 rpm will be built
--build_deb If it is 1 deb will be built
--install_deps Install build dependencies(root previlages are required)
--branch Branch for build
--repo Repo for build
--rpm_release RPM version( default = 1)
--deb_release DEB version( default = 1)
--help) usage ;;
Example $0 --builddir=/tmp/patchelf --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
# these get passed explicitly to mysqld
--builddir=*) WORKDIR="$val" ;;
--build_src_rpm=*) SRPM="$val" ;;
--build_source_deb=*) SDEB="$val" ;;
--build_rpm=*) RPM="$val" ;;
--build_deb=*) DEB="$val" ;;
--get_sources=*) SOURCE="$val" ;;
--branch=*) BRANCH="$val" ;;
--install_deps=*) INSTALL="$val" ;;
--repo=*) REPO="$val" ;;
--rpm_release=*) RPM_RELEASE="$val" ;;
--deb_release=*) DEB_RELEASE="$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
git clone "$REPO"
retval=$?
if [ $retval != 0 ]
then
echo "There were some issues during repo cloning from github. Please retry one more time"
exit 1
fi
cd patchelf
if [ ! -z $BRANCH ]
then
git reset --hard
git clean -xdf
git checkout $BRANCH
fi
REVISION=$(git rev-parse --short HEAD)
git reset --hard
#
PRODUCT=patchelf
VERSION="$(cat version)"
BRANCH_NAME="${BRANCH}"
PRODUCT_FULL="${PRODUCT}"-"${VERSION}"
echo "REVISION=${REVISION}" >> ${CURDIR}/patchelf.properties
echo "RPM_RELEASE=${RPM_RELEASE}" >> ${CURDIR}/patchelf.properties
echo "DEB_RELEASE=${DEB_RELEASE}" >> ${CURDIR}/patchelf.properties
echo "GIT_REPO=${GIT_REPO}" >> ${CURDIR}/patchelf.properties
echo "BRANCH_NAME=${BRANCH_NAME}" >> ${CURDIR}/patchelf.properties
echo "PRODUCT=${PRODUCT}" >> ${CURDIR}/patchelf.properties
echo "PRODUCT_FULL=${PRODUCT_FULL}" >> ${CURDIR}/patchelf.properties
echo "BUILD_NUMBER=${BUILD_NUMBER}" >> ${CURDIR}/patchelf.properties
echo "BUILD_ID=${BUILD_ID}" >> ${CURDIR}/patchelf.properties
echo "VERSION=${VERSION}" > ${CURDIR}/patchelf.properties
#
if [ -z "${DESTINATION}" ]; then
export DESTINATION=experimental
fi
#
TIMESTAMP=$(date "+%Y%m%d-%H%M%S")
echo "DESTINATION=${DESTINATION}" >> ${CURDIR}/patchelf.properties
echo "UPLOAD=UPLOAD/${DESTINATION}/BUILDS/${PRODUCT}/${PRODUCT_FULL}/${BRANCH_NAME}/${REVISION}${TIMESTAMP}" >> ${CURDIR}/patchelf.properties
cd ${WORKDIR}
git clone https://github.com/Percona-Lab/patchelf-packaging.git
cp -ap ${WORKDIR}/patchelf-packaging/*.spec ${PRODUCT}/
cp -ap ${WORKDIR}/patchelf-packaging/debian ${PRODUCT}/
sed -i "s:@PACKAGE_VERSION@:${VERSION}:g" ${PRODUCT}/patchelf.spec
sed -i "s:@RPM_RELEASE@:${RPM_RELEASE}:g" ${PRODUCT}/patchelf.spec
cd ${WORKDIR}
mv ${PRODUCT} ${PRODUCT_FULL}
tar --owner=0 --group=0 --exclude=.bzr --exclude=.git -czf ${PRODUCT}-${VERSION}.tar.gz ${PRODUCT_FULL}
rm -rf ${PRODUCT_FULL}
mkdir $WORKDIR/source_tarball
mkdir $CURDIR/source_tarball
cp ${PRODUCT}-${VERSION}.tar.gz $WORKDIR/source_tarball
cp ${PRODUCT}-${VERSION}.tar.gz $CURDIR/source_tarball
cd $CURDIR
rm -rf patchelf
return
}
get_system(){
if [ -f /etc/redhat-release ]; then
export RHEL=$(rpm --eval %rhel)
export ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g')
export OS_NAME="el$RHEL"
export OS="rpm"
else
export ARCH=$(uname -m)
export OS_NAME="$(lsb_release -sc)"
export OS="deb"
fi
return
}
enable_venv(){
if [ "$OS" == "rpm" ]; then
if [ "${RHEL}" -eq 7 ]; then
source /opt/rh/devtoolset-8/enable
export CMAKE_BIN="cmake3"
elif [ "${RHEL}" -eq 6 ]; then
source /opt/rh/devtoolset-8/enable
fi
fi
}
install_deps() {
if [ $INSTALL = 0 ]
then
echo "Dependencies will not be installed"
return;
fi
if [ ! $( id -u ) -eq 0 ]
then
echo "It is not possible to instal dependencies. Please run as root"
exit 1
fi
CURPLACE=$(pwd)
if [ "x$OS" = "xrpm" ]
then
yum -y install git wget
if [[ "${RHEL}" -eq 8 ]]; then
PKGLIST+=" binutils-devel libev-devel bison make gcc"
PKGLIST+=" rpm-build gcc-c++"
PKGLIST+=" rpmlint autoconf automake "
until yum -y install ${PKGLIST}; do
echo "waiting"
sleep 1
done
else
until yum -y install epel-release centos-release-scl; do
yum clean all
sleep 1
echo "waiting"
done
until yum -y makecache; do
yum clean all
sleep 1
echo "waiting"
done
PKGLIST+=" devtoolset-8-gcc-c++ devtoolset-8-binutils"
PKGLIST+=" make gcc gcc-c++ libev-devel rpm-build autoconf automake rpmlint"
until yum -y install ${PKGLIST}; do
echo "waiting"
sleep 1
done
fi
else
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y install lsb-release gnupg git wget
PKGLIST+=" bison make devscripts debconf debhelper dpkg-dev automake bison autoconf automake"
PKGLIST+=" build-essential rsync"
until DEBIAN_FRONTEND=noninteractive apt-get -y install ${PKGLIST}; do
sleep 1
echo "waiting"
done
fi
return;
}
get_tar(){
TARBALL=$1
TARFILE=$(basename $(find $WORKDIR/$TARBALL -name 'patchelf*.tar.gz' | sort | tail -n1))
if [ -z $TARFILE ]
then
TARFILE=$(basename $(find $CURDIR/$TARBALL -name 'patchelf*.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 "patchelf*.$param" | sort | tail -n1))
if [ -z $FILE ]
then
FILE=$(basename $(find $CURDIR/source_deb -name "patchelf*.$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
cd $WORKDIR
get_tar "source_tarball"
if [ -d rpmbuild ]; then
rm -fr rpmbuild
fi
ls | grep -v patchelf*.tar.* | xargs rm -rf
mkdir -vp rpmbuild/{SOURCES,SPECS,BUILD,SRPMS,RPMS}
TARFILE=$(basename $(find . -name 'patchelf-*.tar.gz' | sort | tail -n1))
NAME=$(echo ${TARFILE}| awk -F '-' '{print $1}')
VERSION_TMP=$(echo ${TARFILE}| awk -F '-' '{print $2}')
VERSION=${VERSION_TMP%.tar.gz}
#
cd $WORKDIR/rpmbuild/SPECS
tar vxzf ${WORKDIR}/${TARFILE} --wildcards '*.spec' --strip=1
#
cd $WORKDIR
#
cd $WORKDIR/rpmbuild/SOURCES
tar vxzf ${WORKDIR}/${TARFILE} --wildcards "patchelf-$VERSION/debian/patches/*.patch" --strip=3
mv -fv $WORKDIR/$TARFILE $WORKDIR/rpmbuild/SOURCES
cd $WORKDIR
#
enable_venv
rpmbuild -bs --define "_topdir $WORKDIR/rpmbuild" --define "dist .generic" rpmbuild/SPECS/patchelf.spec
mkdir -p ${WORKDIR}/srpm
mkdir -p ${CURDIR}/srpm
cp $WORKDIR/rpmbuild/SRPMS/*.src.rpm $CURDIR/srpm
cp $WORKDIR/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
SRC_RPM=$(basename $(find $WORKDIR/srpm -name 'patchelf-*.src.rpm' | sort | tail -n1))
if [ -z $SRC_RPM ]
then
SRC_RPM=$(basename $(find $CURDIR/srpm -name 'patchelf-*.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
if [ -d rpmbuild ]; then
rm -fr rpmbuild
fi
mkdir -vp rpmbuild/{SOURCES,SPECS,BUILD,SRPMS,RPMS}
cp $SRC_RPM rpmbuild/SRPMS/
#
echo "RHEL=${RHEL}" >> ${CURDIR}/patchelf.properties
echo "ARCH=${ARCH}" >> ${CURDIR}/patchelf.properties
#
SRCRPM=$(basename $(find . -name '*.src.rpm' | sort | tail -n1))
enable_venv
rpmbuild --define "_topdir ${WORKDIR}/rpmbuild" --define "dist .el${RHEL}" --rebuild rpmbuild/SRPMS/${SRCRPM}
return_code=$?
if [ $return_code != 0 ]; then
exit $return_code
fi
mkdir -p ${WORKDIR}/rpm
mkdir -p ${CURDIR}/rpm
cp rpmbuild/RPMS/*/*.rpm ${WORKDIR}/rpm
cp rpmbuild/RPMS/*/*.rpm ${CURDIR}/rpm
}
build_source_deb(){
if [ $SDEB = 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
rm -rf patchelf*
get_tar "source_tarball"
rm -f *.dsc *.orig.tar.gz *.changes *.debian.tar.xz
TARFILE=$(basename $(find . -name 'patchelf-*.tar.gz' | sort | tail -n1))
NAME=$(echo ${TARFILE}| awk -F '-' '{print $1}')
VERSION_TMP=$(echo ${TARFILE}| awk -F '-' '{print $2}')
VERSION=${VERSION_TMP%.tar.gz}
echo "DEB_RELEASE=${DEB_RELEASE}" >> ${CURDIR}/patchelf.properties
NEWTAR=${NAME}_${VERSION}.orig.tar.gz
mv ${TARFILE} ${NEWTAR}
tar xzf ${NEWTAR}
cd $NAME-$VERSION
dch -D unstable --force-distribution -v "1:${VERSION}-${DEB_RELEASE}" "Update to new upstream release patchelf ${VERSION}-${DEB_RELEASE}"
dpkg-buildpackage -S
cd ${WORKDIR}
mkdir -p $WORKDIR/source_deb
mkdir -p $CURDIR/source_deb
cp *.debian.tar.xz $WORKDIR/source_deb
cp *.dsc $WORKDIR/source_deb
cp *.orig.tar.gz $WORKDIR/source_deb
cp *.changes $WORKDIR/source_deb
cp *.debian.tar.xz $CURDIR/source_deb
cp *.dsc $CURDIR/source_deb
cp *.orig.tar.gz $CURDIR/source_deb
cp *.changes $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.tar.xz'
do
get_deb_sources $file
done
cd $WORKDIR
DSC=$(basename $(find . -name '*.dsc' | sort | tail -n 1))
DIRNAME=$(echo ${DSC} | sed -e 's:_:-:g' | awk -F'-' '{print $1"-"$2}')
VERSION=$(echo ${DSC} | sed -e 's:_:-:g' | awk -F'-' '{print $2}')
#
echo "DEB_RELEASE=${DEB_RELEASE}" >> ${CURDIR}/patchelf.properties
echo "DEBIAN_VERSION=${OS_NAME}" >> ${CURDIR}/patchelf.properties
echo "ARCH=${ARCH}" >> ${CURDIR}/patchelf.properties
dpkg-source -x $DSC
cd $DIRNAME
sed -i "s: serial-tests::g" configure.ac
dch -m -D "$OS_NAME" --force-distribution -v "1:$VERSION-$DEB_RELEASE.$OS_NAME" 'Update distribution'
dpkg-buildpackage -rfakeroot -uc -us -b
cd ${WORKDIR}
mkdir -p $CURDIR/deb
mkdir -p $WORKDIR/deb
cp $WORKDIR/*.deb $WORKDIR/deb
cp $WORKDIR/*.deb $CURDIR/deb
}
CURDIR=$(pwd)
VERSION_FILE=$CURDIR/patchelf.properties
args=
WORKDIR=
SRPM=0
SDEB=0
RPM=0
DEB=0
SOURCE=0
TARBALL=0
OS_NAME=
ARCH=
OS=
REVISION=0
BRANCH="master"
INSTALL=0
RPM_RELEASE=1
DEB_RELEASE=1
REPO="https://github.com/NixOS/patchelf.git"
parse_arguments PICK-ARGS-FROM-ARGV "$@"
check_workdir
get_system
install_deps
get_sources
build_srpm
build_source_deb
build_rpm
build_deb