0

I've been given a task to process several RPM package names from a file, uninstall them (if necessary) with a 'cascading delete' option and then install in the reverse order. For example, if there're packages a, b, and c, where c depends on b and b depends on a, the uninstallation order should be c, b, a and installation order a, b, c.

After some thinking, it appears that one way to do this is to build a dependency graph and then sort on the degree of a vertex. So far, I've found 2 libraries, JGraphT and Grph, both promising but with pitiful or non-existent code samples. The former has a org.jgrapht.alg.util.VertexDegreeComparator and the later grph.algo.sort. OutDegreeSorter. Before I dig into the source code and try to figure out how to use those, I'm wondering if there are better ways to do this (including algorithm and libraries)? The number of packages is not going to be huge (< 100), so performance is not a big concern. Maintenance of the code I'll write, is.

Hasty duplicate call out alert: I read this thread and it is not what I'm looking for. The poster there is asking how to build a dependency graph, which is not my question.

Community
  • 1
  • 1
Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
  • @fge Can yum do a 'cascade delete', that is sort the given packages names by dependency and uninstall them in order? And then install in the reverse order? Also, for security reasons, the servers don't have access to a yum repo and I can't change that. Even if I use yum, it'll have to deal with local RPMs. – Abhijit Sarkar Nov 13 '15 at 18:32
  • No. The installation has to be from RPM. No local or remote yum repo. – Abhijit Sarkar Nov 13 '15 at 19:07
  • Let's put it this way - I don't own the company. We all would like to live in an ideal world but it doesn't work that way. – Abhijit Sarkar Nov 13 '15 at 19:11
  • Now we're spinning our wheels. If you've a suggestion that works within the restrictions of the problem space, feel free to suggest. – Abhijit Sarkar Nov 13 '15 at 19:21

1 Answers1

0

Instead of building a dependency graph myself, I decided to use yum for local package installation as below:

PKGS=$(find "$RPM_DIR" -iname "*.rpm" -type f -exec rpm -qp --qf "%{NAME} " {} \; | sed 's/ $//')
RPMS=$(find "$RPM_DIR" -iname "*.rpm" -type f | awk '{print}' ORS=' ')

if [ "$INTERACTIVE" != true ]; then
  sudo yum -y --disablerepo=* remove $PKGS
  sudo yum -y --nogpgcheck localinstall $RPMS
else
  sudo yum --disablerepo=* remove $PKGS
  sudo yum --nogpgcheck localinstall $RPMS
fi
Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219