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.

RichVel
  • 3,554
  • 1
  • 18
  • 23
JackLeo
  • 258
  • 2
  • 11
  • 1
    yum localinstall for installing local package – c4f4t0r Oct 26 '17 at 10:07
  • @c4f4t0r localinstall is a legacy option. yum install behaves the same given the rpm local file. Same exit code, same error. https://linux.die.net/man/8/yum – JackLeo Oct 26 '17 at 10:12
  • Why not to use `rpm -F packages/*` for update? – Alexander Tolkachev Oct 26 '17 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 '17 at 10:21
  • @JackLeo could you show output for `rpm -F .rpm`? – Alexander Tolkachev Oct 26 '17 at 10:24
  • @AlexanderTolkachev I could generate it a tad later, yes, I've only checked that with the manual. https://linux.die.net/man/8/rpm At the moment I am looking into install via `rpm` directly, and that trows more explicit exit codes. In a case of no updates it trows 3. So I am looking into it at the moment. – JackLeo Oct 26 '17 at 10:27
  • @AlexanderTolkachev added. No output at all. Just ignores the package both if given a list `*.rpm` or explicitly the name of the package. – JackLeo Oct 26 '17 at 10:40

1 Answers1

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
tonioc
  • 1,047
  • 8
  • 11
  • 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 '17 at 11:05
  • Indeed, it looks like a bug that should be submitted to redhat... – tonioc Oct 27 '17 at 16:14