3

I wish to install some RPM packages from a shell script. I want to ensure that each package is indeed installed, but I do not want to update a package that would already have an older version installed (to avoid going to deep into dependency resolution).

How can I achieve this in such a way, that a case where an older version is already installed will return without an error code, while in other cases of failures there will be an error code returned? This so that I am able to control the good execution of the script.

4 Answers 4

7

you can install depending of package existence in the system by:

 rpm -q mypackage || rpm -i mypackage.rpm 
2

Use the following command rpm -q mypackage && rpm -i mypackage.rpm. If querying for the rpm succeeds then installation of the rpm package will proceed. Else If the query fails then the installation will not proceed. However If you use || instead of &&, then despite of the previous command of querying the package fails, it will try to install the package, which anyway doesn't make sense.

0

What if you first test on whether the package in question is already installed and if not, you then install it. As you wrote you want to realize this within a Shell script, this would be some kind of if-clause.

Pseudo code:

if is_installed($package) then return is_already_installed else rpm -i $package return $? fi 

The first part could be extended by another test on the currently installed version (e.g. for a final report of the script).

0

You may find rpm -q <package name> helpful, or even rpm -U for an upgrade.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.