forked from RedHatSatellite/soe-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpmbuild.sh
executable file
·83 lines (74 loc) · 2.74 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# Search for RPM source directories and package
#
# e.g. ${WORKSPACE}/scripts/rpmbuilder.sh ${WORKSPACE}/soe/rpms/
#
# Load common parameter variables
. $(dirname "${0}")/common.sh
function build_srpm {
if [[ -e "$1" ]]
then
git_commit=$(git log --format="%H" -1 $(pwd))
if [[ ! -e .rpmbuild-hash ]] || [[ ${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 ${SRPMS_DIR}/${rpmname}-*.src.rpm
/usr/bin/mock --buildsrpm --spec ${SPECFILE} --sources $(pwd) --resultdir ${SRPMS_DIR} --root ${MOCK_CONFIG}
RETVAL=$?
if [[ ${RETVAL} != 0 ]]
then
err "Could not build SRPM ${rpmname} using the specfile ${SPECFILE}"
exit ${SRPMBUILD_ERR}
fi
srpmname=${SRPMS_DIR}/${rpmname}-*.src.rpm
/usr/bin/mock --rebuild ${srpmname} -D "%debug_package %{nil}" --resultdir ${RPMS_DIR} --root ${MOCK_CONFIG}
RETVAL=$?
if [[ ${RETVAL} != 0 ]]
then
err "Could not build RPM ${rpmname} from ${srpmname}"
exit ${RPMBUILD_ERR}
fi
mv -nv ${RPMS_DIR}/*.rpm ${YUM_REPO} # don't overwrite RPMs
restorecon -F ${YUM_REPO}/*.rpm
if [ "$(echo ${RPMS_DIR}/*.rpm)" != "${RPMS_DIR}/*.rpm" ]
then # not all RPM files could be moved, some are remaining
warn "RPM package '${rpmname}' already in repository," \
"You might have forgotten to increase the version" \
"after doing changes. Skipping ${SPECFILE}"
fi
# Something has changed, track it for build and for tests
echo ${git_commit} > .rpmbuild-hash
echo "#${rpmname}#" >> "${MODIFIED_CONTENT_FILE}"
echo "${rpmname}" >> "${MODIFIED_RPMS_FILE}"
else
inform "No changes since last build - skipping ${SPECFILE}"
fi
fi
}
if [[ -z "$1" ]] || [[ ! -d "$1" ]]
then
usage "$0 <directory containing RPM source directories>"
exit ${NOARGS}
fi
workdir=$1
if [[ -z ${WORKSPACE} ]] || [[ ! -w ${WORKSPACE} ]]
then
err "WORKSPACE not set or not found"
exit ${WORKSPACE_ERR}
fi
SRPMS_DIR=${WORKSPACE}/tmp/srpms
RPMS_DIR=${WORKSPACE}/tmp/rpms
mkdir -p ${SRPMS_DIR} ${RPMS_DIR}
# 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
wait # TODO: add comment to explain why this?