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.

183 lines
3.3 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. my $showopt = 0;
  9. my $listmode = 0;
  10. my @ignore_list;
  11. sub help()
  12. {
  13. print "\n";
  14. print "Usage $0 [ <options> ] <pkg> [ <pkg> [ .. ] ]\n";
  15. print "\n";
  16. print "Options:\n";
  17. print "\n";
  18. print " -cfg <config> Use package list from config\n";
  19. print " -root <dir> Use dir as root directory\n";
  20. print " -depdb <file> Use file as dependency database\n";
  21. print "\n";
  22. print " -ignore <regex> Ignore all packages matching the regex\n";
  23. print "\n";
  24. print " -chroot Use 'build/<config>../' as root\n";
  25. print "\n";
  26. print " -showinst Also show already installed deps\n";
  27. print " -showdups Also show already printed deps\n";
  28. print " -showopt Also show packages marked as optional\n";
  29. print "\n";
  30. print " -listmod Run in list mode\n";
  31. print "\n";
  32. exit 1;
  33. }
  34. while ( $#ARGV >= 0 and $ARGV[0] =~ /^-/ )
  35. {
  36. my $opt = shift @ARGV;
  37. if ( $opt eq "-cfg" ) {
  38. $pkgfile = "config/".(shift @ARGV)."/packages";
  39. next;
  40. }
  41. if ( $opt eq "-root" ) {
  42. $rootdir = shift @ARGV;
  43. next;
  44. }
  45. if ( $opt eq "-depdb" ) {
  46. $depdb = shift @ARGV;
  47. next;
  48. }
  49. if ( $opt eq "-ignore" ) {
  50. push @ignore_list, shift @ARGV;
  51. next;
  52. }
  53. if ( $opt eq "-chroot" ) {
  54. my $cfgfile = $pkgfile;
  55. $cfgfile =~ s/packages$/config/;
  56. $rootdir = "build/".`source $cfgfile; echo \$ROCKCFG_ID;`;
  57. chomp $rootdir;
  58. next;
  59. }
  60. if ( $opt eq "-showinst" ) {
  61. $showinst = 1;
  62. next;
  63. }
  64. if ( $opt eq "-showdups" ) {
  65. $showdups = 1;
  66. next;
  67. }
  68. if ( $opt eq "-showopt" ) {
  69. $showopt = 1;
  70. next;
  71. }
  72. if ( $opt eq "-listmode" ) {
  73. $listmode = 1;
  74. next;
  75. }
  76. help;
  77. }
  78. help if $#ARGV < 0;
  79. my %pkgs;
  80. my %pkgs_reverse;
  81. open(F, "<$pkgfile") or die "Can't open $pkgfile: $!";
  82. while (<F>) {
  83. next unless /^X/ or $showopt;
  84. my @f = split /\s+/;
  85. if ( $f[4] =~ /(.*)=(.*)/ ) {
  86. $pkgs{$2} = $1;
  87. push @{$pkgs_reverse{$1}}, $2;
  88. } else {
  89. $pkgs{$f[4]} = $f[4];
  90. push @{$pkgs_reverse{$f[4]}}, $f[4];
  91. }
  92. }
  93. close F;
  94. my %deps;
  95. open(F, "<$depdb") or die "Can't open $depdb: $!";
  96. while (<F>) {
  97. chomp;
  98. die "DepDB syntax error" unless /^(\S+): \d+ \d+ (.*)\s+\1$/;
  99. next unless defined $pkgs_reverse{$1};
  100. my @deplist = split /\s+/, $2;
  101. foreach (@{$pkgs_reverse{$1}}) {
  102. $deps{$_} = \@deplist;
  103. }
  104. }
  105. close F;
  106. my %duptags;
  107. my @rawlist;
  108. sub showdeps($$);
  109. sub showdeps($$)
  110. {
  111. my $depth = $_[0];
  112. my $sp = " " x $_[0];
  113. my $p = $_[1];
  114. foreach (@ignore_list) {
  115. return if $p =~ /$_/;
  116. }
  117. my $is_dup = defined $duptags{$p};
  118. $duptags{$p} = 1;
  119. my $is_inst = -f "$rootdir/var/adm/packages/$p";
  120. while (<$rootdir/var/adm/packages/$p:*>) {
  121. $is_inst = 1 if -f "$_";
  122. }
  123. if ( $_[0] > 0 ) {
  124. return if $is_dup and not $showdups;
  125. return if $is_inst and not $showinst;
  126. }
  127. if ($listmode) {
  128. push @{$rawlist[$depth]}, $p;
  129. } else {
  130. print "${sp}$p";
  131. print " (already_installed)" if $is_inst;
  132. print " (duplicate)" if $is_dup;
  133. print "\n";
  134. }
  135. if ( $depth > 0 ) {
  136. return if $is_dup;
  137. return if $is_inst;
  138. }
  139. foreach (@{$deps{$p}}) {
  140. showdeps($depth+1, $_)
  141. if defined $_ and defined $deps{$_};
  142. }
  143. }
  144. foreach my $p (@ARGV) {
  145. showdeps(0, $p);
  146. }
  147. if ($listmode) {
  148. my $isfirst = 1;
  149. foreach my $l (reverse @rawlist) {
  150. foreach (@{$l}) {
  151. print " " unless $isfirst;
  152. $isfirst = 0;
  153. print $_;
  154. }
  155. }
  156. print "\n";
  157. }