Knowing what rpms you’ve just built
One idiom I’ve found myself repeating in various projects is a build-all script that builds multiple rpm packages in a certain order. This isn’t very sophisticated – each time I’ve ordered the packages being built manually.
But how do you know what rpms you will get, when you run rpmbuild? You need to know this, so you can install the rpms. Here is a solution:
specfile=project.spec
RPMDIR=$(rpm --eval '%{_rpmdir}')
# What format does rpm use for built binary rpms?
# %{ARCH}/%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm
BUILD_NAME_FMT=`rpm --eval '%{_build_name_fmt}'`
rpms=$(rpm -q --specfile $specfile --queryformat "$BUILD_NAME_FMT ")
pushd $RPMDIR
rpm -ivh $rpms
popd
This works as follows: get the rpm root directory into $RPMDIR; find the format rpmbuild uses for built binary rpms; query the rpm specfile for packages and format the results using the build rpm filename format; finally, go into the rpm root and install all the binary rpms.