mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
2.6 KiB

  1. #!/usr/bin/perl -w
  2. use strict;
  3. my $depdb = "scripts/dep_db.txt";
  4. my $pkgfile = "config/default/packages";
  5. my $rootdir = "";
  6. my $showinst = 0;
  7. my $showdups = 0;
  8. sub help()
  9. {
  10. print "\n";
  11. print "Usage $0 [ <options> ] <pkg> [ <pkg> [ .. ] ]\n";
  12. print "\n";
  13. print "Options:\n";
  14. print "\n";
  15. print " -cfg <config> Use package list from config\n";
  16. print " -root <dir> Use dir as root directory\n";
  17. print " -depdb <file> Use file as dependency database\n";
  18. print "\n";
  19. print " -chroot Use 'build/<config>../' as root\n";
  20. print "\n";
  21. print " -showinst Also show already installed deps\n";
  22. print " -showdups Also show already printed deps\n";
  23. print "\n";
  24. exit 1;
  25. }
  26. while ( $#ARGV >= 0 and $ARGV[0] =~ /^-/ )
  27. {
  28. my $opt = shift @ARGV;
  29. if ( $opt eq "-cfg" ) {
  30. $pkgfile = "config/".(shift @ARGV)."/packages";
  31. next;
  32. }
  33. if ( $opt eq "-root" ) {
  34. $rootdir = shift @ARGV;
  35. next;
  36. }
  37. if ( $opt eq "-depdb" ) {
  38. $depdb = shift @ARGV;
  39. next;
  40. }
  41. if ( $opt eq "-chroot" ) {
  42. my $cfgfile = $pkgfile;
  43. $cfgfile =~ s/packages$/config/;
  44. $rootdir = "build/".`source $cfgfile; echo \$ROCKCFG_ID;`;
  45. chomp $rootdir;
  46. next;
  47. }
  48. if ( $opt eq "-showinst" ) {
  49. $showinst = 1;
  50. next;
  51. }
  52. if ( $opt eq "-showdups" ) {
  53. $showdups = 1;
  54. next;
  55. }
  56. help;
  57. }
  58. help if $#ARGV < 0;
  59. my %pkgs;
  60. my %pkgs_reverse;
  61. open(F, "<$pkgfile") or die "Can't open $pkgfile: $!";
  62. while (<F>) {
  63. next unless /^X/;
  64. my @f = split /\s+/;
  65. if ( $f[4] =~ /(.*)=(.*)/ ) {
  66. $pkgs{$2} = $1;
  67. push @{$pkgs_reverse{$1}}, $2;
  68. } else {
  69. $pkgs{$f[4]} = $f[4];
  70. push @{$pkgs_reverse{$f[4]}}, $f[4];
  71. }
  72. }
  73. close F;
  74. my %deps;
  75. open(F, "<$depdb") or die "Can't open $depdb: $!";
  76. while (<F>) {
  77. chomp;
  78. die "DepDB syntax error" unless /^(\S+): \d+ \d+ (.*)\s+\1$/;
  79. next unless defined $pkgs_reverse{$1};
  80. my @deplist = split /\s+/, $2;
  81. foreach (@{$pkgs_reverse{$1}}) {
  82. $deps{$_} = \@deplist;
  83. }
  84. }
  85. close F;
  86. my %duptags;
  87. sub showdeps($$);
  88. sub showdeps($$)
  89. {
  90. my $sp = " " x $_[0];
  91. my $p = $_[1];
  92. my $is_dup = defined $duptags{$p};
  93. $duptags{$p} = 1;
  94. my $is_inst = -f "$rootdir/var/adm/packages/$p";
  95. while (<$rootdir/var/adm/packages/$p:*>) {
  96. $is_inst = 1 if -f "$_";
  97. }
  98. if ( $_[0] > 0 ) {
  99. return if $is_dup and not $showdups;
  100. return if $is_inst and not $showinst;
  101. }
  102. print "${sp}$p";
  103. print " (already_installed)" if $is_inst;
  104. print " (duplicate)" if $is_dup;
  105. print "\n";
  106. if ( $_[0] > 0 ) {
  107. return if $is_dup;
  108. return if $is_inst;
  109. }
  110. foreach (@{$deps{$p}}) {
  111. showdeps($_[0]+1, $_)
  112. if defined $_ and defined $deps{$_};
  113. }
  114. }
  115. foreach my $p (@ARGV) {
  116. showdeps(0, $p);
  117. }