Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

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

 rpm -q mypackage || rpm -i mypackage.rpm
share|improve this answer
add comment

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).

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.