8

I am looking for a way to have yum install only dependencies for a given package, something like an --prepare-for-install option so I can take a snapshot of the prepared system and test the rpm setup with different options or rebuilds of the package itself on a clean system without having to rely on the rpm uninstall and without downloading the dependencies each time.

a1an
  • 417
  • 2
  • 7
  • 16

3 Answers3

11

This might be really dumb but it should work.

PACKAGE=awstats
yum deplist $PACKAGE | grep provider | awk '{print $2}' | sort | uniq | grep -v $PACKAGE | sed ':a;N;$!ba;s/\n/ /g' | xargs yum -y install
ablackhat
  • 1,923
  • 2
  • 14
  • 19
  • Works like a charm, who said dumb isn't good :) Would you explain the :a;N;$!ba; part of the sed command for completeness? Thanks – a1an Sep 18 '12 at 10:30
  • I honestly don't know, but I pulled it from here, http://stackoverflow.com/a/1252191 – ablackhat Sep 18 '12 at 17:35
  • Ok, +1 to him also then – a1an Sep 19 '12 at 08:10
  • 1
    The `sed` expression joins the multiple lines returned by `yum deplist` and the intervening pipeline, transforming it into a single line of space-separated dependencies. It's not actually necessary. You can simplify the above as: `yum deplist $PACKAGE | awk '/provider/ {print $2}' | sort -u | xargs yum -y install`. – larsks Apr 21 '15 at 13:22
  • 2
    Your solution has an error. Say, if we try to install dependencies for package "mysql" and it has "mysql-common" and "init-mysql" dependencies, we will not see them installed, because they both will be filtered by 'grep -v mysql'. – Nikita Kipriyanov Jan 27 '16 at 13:18
  • 1
    I believe [this answer](http://unix.stackexchange.com/a/220531/26613) addresses @NikitaKipriyanov's point. – floer_m Jan 18 '17 at 03:44
4
yum install $(repoquery --requires <package>)
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • Note that this doesn't account for providers. For instance, I have `git18` which provides `git`; the above command attempts to install `git` as a dependency anyway. – Aaron Adams Nov 30 '13 at 17:53
  • 1
    I believe [this answer](http://unix.stackexchange.com/a/220531/26613) addresses the valid concern raised by @AaronAdams, above. – floer_m Jan 18 '17 at 03:44
0

Best option I found until now for my packages is to put an "exit 1" into the %pre scriptlet the first time the package is built but I'm looking for cleaner options, not requiring modification of the package itself.

a1an
  • 417
  • 2
  • 7
  • 16