centos – Install a RPM package inside a .rpm

I want to create a .rpm that will do some action before installing an other package
Like so :

%pre
touch /tmp/test.txt

%post
if ! rpm -q tree &>/dev/null; then
    dnf install -y tree
fi
touch /tmp/test-end.txt

As predicted RPM can’t handle a rpm installing inside a rpm installation :

RPM: error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Resource temporarily unavailable)

The Require statement will install the package before the %pre sequence, i’m looking to do the install after it.

Requires(post): tree seems to only check the presence of the package for the %post and does not install the package

Read more here: Source link