Is extracting files on %post when installing an RPM a good practice?

-1

I'm creating an RPM to distribute a conda environment and I came up with this solution:

I was able to do it. Here's my .spec file from a Stackexchange answer.

Summarizing: I use the install phase to just unpack the dependencies and the installation script and in %post I run that script, which is creating files under /opt/miniconda. Due to this, I need to specify manually the steps to clean the environment when uninstalling and also check manually if everything is working correctly.

Is this a good practice? I'd like to be able to do everything in the install phase so the installation could be aborted if something goes bad but I wasn't able to achieve this.

Raúl García

Posted 2017-06-01T08:51:51.890

Reputation: 1

Answers

0

It is very bad practice.

Few pointers:

Instead of:

if [ -f /opt/miniconda/bin/python ]; then
    echo "Python is there!"
    echo "Checking version..."

    python_version="$(/opt/miniconda/bin/python --version)"
    if [[ "3.6.0" =~ "$python_version" ]]; then

You should put either

Requires: python >= 3.6.0

If system python is enough for you, or if you create RPM with your own python then something like:

Requires: miniconda-python >= 3.6.0

Similary for all those modules.

It seems to me that you do not know the difference between %install and %post. So please read https://stackoverflow.com/questions/34631942/how-to-run-and-interact-with-a-script-from-within-an-rpm/34634718#34634718 Do all the move part in %install and you do not need %post part at all.

msuchy

Posted 2017-06-01T08:51:51.890

Reputation: 504

The machine does not have access to network, so I cannot add Requires: python there. I need to extract and execute the script that is installing the dependencies correctly, is not a matter of just moving some files. Install.sh is the one that creates files under /opt/miniconda and later on I check that everything went fine with those if-else statements. – Raúl García – 2017-06-05T08:19:03.733

You can run the script which is installing the dependencies in %install section.. Then all the dependencies will be in RPM package. You really should start creating RPM package on some smaller and simplier package so you get familier with the concept. – msuchy – 2017-06-06T08:10:20.867