SHARE
TWEET

Script to show suggested or recommended packages of Ubuntu.

moonchild_it Nov 9th, 2016 (edited) 275 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use utf8;
  6.  
  7. my %INSTALLED  = ();
  8. my %RECOMMENDS = ();
  9. my %SUGGESTS   = ();
  10. my %SKIP       = ();
  11. my %ESSENTIAL  = ();
  12.  
  13. my $line;
  14. my %hash;
  15. open( PIPE, '-|', 'dpkg-query', '-W',
  16.     '-f=${Package}/${Status}/${Recommends}/${Suggests}/${Replaces}/${Provides}/${Essential}\n' )
  17.   or die "could'nt open pipe: $!";
  18. while ( $line = <PIPE> ) {
  19.  
  20.     chomp $line;
  21.    
  22.     $line =~ s/\(.+?\)//g;
  23.     $line =~ s/\s+//g;
  24.     $line =~ s/\:\w+//g;
  25.        
  26.     my @input = split( '/', $line );
  27.     next if ( $input[1] ne 'installokinstalled' );
  28.     $INSTALLED{ $input[0] }  = 1;
  29.         $RECOMMENDS{ $input[0] } = $input[2] if ( $input[2] );
  30.     $SUGGESTS{ $input[0] }   = $input[3] if ( $input[3] );  
  31.     if ( $input[4] ) {
  32.         my @list = split (',', $input[4]);
  33.         my $i; foreach $i (@list) { $SKIP{ $i } = 1; };
  34.     }
  35.     if ( $input[5] ) {
  36.         my @list = split (',', $input[5]);
  37.         my $i; foreach $i (@list) { $SKIP{ $i } = 1; };
  38.     }
  39.     $ESSENTIAL{$input[0]} = 1 if ($input[6] eq 'yes');
  40. }
  41.  
  42. sub get_items {
  43.  
  44.     my $string = shift;
  45.  
  46.     return unless $string;
  47.  
  48.     my %ret = ();
  49.     my @packages = split ',', $string;
  50.  
  51.     my $package;
  52.     foreach $package (@packages) {
  53.  
  54.         my @items = split '\|', $package;
  55.  
  56.         my $ret = 1;
  57.         my $item;
  58.         foreach $item (@items) {
  59.             $ret = 0 if ($INSTALLED{$item} or $SKIP{$item});
  60.         }
  61.         $ret{$package} = 1 if $ret;
  62.     }
  63.  
  64.     return join( ' ', keys %ret );
  65. }
  66.  
  67. my $package;
  68. foreach $package ( sort keys %INSTALLED ) {
  69.  
  70.     my $recommends = get_items( $RECOMMENDS{$package} );
  71.     my $suggests   = get_items( $SUGGESTS{$package} );
  72.     next unless ( $recommends or $suggests );
  73.  
  74.     print "PACKAGE:    $package";
  75.     print " (ESSENTIAL)" if ($ESSENTIAL{$package});
  76.     print "\n";
  77.     print "RECOMMENDS: " . $recommends . "\n" if ($recommends);
  78.     print "SUGGESTS:   " . $suggests . "\n"   if ($suggests);
  79.     print "\n";
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top