forked from RedHatSatellite/soe-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpmbuild.sh
executable file
·71 lines (59 loc) · 1.93 KB
/
rpmbuild.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
#!/bin/bash
# Search for RPM source directories and package
#
# e.g. ${WORKSPACE}/scripts/rpmbuilder.sh ${WORKSPACE}/soe/rpms/
#
. ${WORKSPACE}/scripts/common.sh
function build_srpm {
if [[ -e "$1" ]]
then
git_commit=$(git log --format="%H" -1 $(pwd))
if ! [[ ${git_commit} == $(cat .rpmbuild-hash) ]]
then
# determine the name of the rpm from the specfile
rpmname=$(IGNORECASE=1 awk '/^Name:/ {print $2}' ${SPECFILE})
rm -f ${WORKSPACE}/tmp/srpms/${rpmname}-*.src.rpm
/usr/bin/mock --buildsrpm --spec ${SPECFILE} --sources $(pwd) --resultdir ${WORKSPACE}/tmp/srpms
RETVAL=$?
if [[ ${RETVAL} != 0 ]]
then
echo "Could not build SRPM ${rpmname} using the specfile ${SPECFILE}"
exit ${SRPMBUILD_ERR}
fi
srpmname=${WORKSPACE}/tmp/srpms/${rpmname}-*.src.rpm
/usr/bin/mock --rebuild ${srpmname} -D "%debug_package %{nil}" --resultdir ${YUM_REPO}
RETVAL=$?
if [[ ${RETVAL} != 0 ]]
then
echo "Could not build RPM ${rpmname} from ${srpmname}"
exit ${RPMBUILD_ERR}
fi
echo ${git_commit} > .rpmbuild-hash
else
echo "No changes since last build - skipping ${SPECFILE}"
fi
fi
}
if [[ -z "$1" ]] || [[ ! -d "$1" ]]
then
echo "Usage: $0 <directory containing RPM source directories>"
exit ${NOARGS}
fi
workdir=$1
if [[ -z ${WORKSPACE} ]] || [[ ! -w ${WORKSPACE} ]]
then
echo "WORKSPACE not set or not found"
exit ${WORKSPACE_ERR}
fi
mkdir -p ${WORKSPACE}/tmp/srpms
# Traverse directories looking for spec files and build SRPMs
cd ${workdir}
for I in $( ls -d */ )
do
SPECFILE=""
pushd ${I}
# find the spec files
SPECFILE=$(find . -name "*.spec")
if [[ -n ${SPECFILE} ]] ; then build_srpm ${SPECFILE} ; fi
popd
done