Tuesday, November 16, 2021

[SOLVED] YUM/RPM - How to specify a requirement not installed with RPM

Issue

I have a package X depending on a software Y. Y is often compiled and installed manually by users but not always.

If I put a requirement in my spec file such as "requires: Y" the package Y will be downloaded by YUM and installed. If Y was installed by the user, it is simply overwritten which is not ok.

If I don't put a requirement, those who don't have Y will end up missing a necessary software to run X.

There is a way to know if Y is installed by checking the existence of a binary in a certain place or by checking an environment variable.

How to handle this situation ?


Solution

The %pre section of your RPM .spec file can be setup to check for the existence of the binary file.

 %pre
    # Check if binary file exists . If not, exit with an error. 
    if [ -f /path/to/binary/file ]; then
        echo "Info: Pre-requisite exists: /path/to/binary/file"
    else
        echo "Error: Pre-requisite <name> not installed. Exiting..."
        exit 1
    fi


Answered By - nohup