7

When installing rpm packages from local file directory it runs fine the first time

sudo yum install packages/* -y --disablerepo=*

When the same thing is run the second time as part of automated scripts, it throws an error (exit code 1)

packages/package.rpm: does not update installed package.
Error: Nothing to do

I can run yum update (exit code 0)

sudo yum update packages/* -y --disablerepo=*
...
No packages marked for update

The problem with this is that update will skip the packages that are not installed.

I don't want to ignore exit code if there are any real problems here, and just want to do install-or-update. Is there a rpm -i equivalent that would achieve that? Please take note that this is done on a group of rpm packages that might at any point include additional ones.

I guess one option would be to iterate over them in a shell script and check if they are installed or not, but then again dependency resolution might become rather painful and it does sound like re-inventing a bike.

UPDATE:

rpm --install will throw exit code depending on the number of failed packages. https://www.redhat.com/archives/rpm-list/2005-July/msg00071.html

rpm --freshen will ignore any rpms that are not installed previously while giving no output at all.

7
  • 1
    yum localinstall for installing local package
    – c4f4t0r
    Oct 26, 2017 at 10:07
  • @c4f4t0r localinstall is a legacy option. yum install behaves the same given the rpm local file. Same exit code, same error. linux.die.net/man/8/yum
    – JackLeo
    Oct 26, 2017 at 10:12
  • Why not to use rpm -F packages/* for update? Oct 26, 2017 at 10:17
  • @AlexanderTolkachev same issue as yum update. It updates/freshens the packages that are already installed. If the list of packages includes a new one, it will be skipped.
    – JackLeo
    Oct 26, 2017 at 10:21
  • @JackLeo could you show output for rpm -F <a new one>.rpm? Oct 26, 2017 at 10:24

1 Answer 1

7

on my system (centos6, centos7) "yum localinstall" will return code 0 even with "Error: Nothing to do" message, while "yum install" returns 1.

sudo yum localinstall packages/* -y --disablerepo=*

Anyway you can also check the message result to ignore this as a "normal error" in your automation scripts, like for example using bash:

sudo yum install packages/* -y --disablerepo=* 2>&1 | tee /tmp/yum.output
grep -q "Error: Nothing to do" /tmp/yum.output
if [ $? -eq 0 ]; then
  ... code for no error
else 
  ... code for error
fi
2
  • Your comment regards localinstall exit code seems to be true. Not sure how I got the previous result that mimicked install, but seems to be my bad. It's not ideal to rely on legacy option, but then again we're talking about centos/redhat. the snippet was something that I was aiming to avoid since you would think it would be a desired option but hey ho...
    – JackLeo
    Oct 26, 2017 at 11:05
  • Indeed, it looks like a bug that should be submitted to redhat...
    – tonioc
    Oct 27, 2017 at 16:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .