File: recommends

package info (click to toggle)
feta 1.4.15
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 444 kB
  • ctags: 85
  • sloc: perl: 1,200; sh: 192; makefile: 55
file content (74 lines) | stat: -rwxr-xr-x 1,831 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl -w
# Copyright (c)2001-2002 Joe Wreschnig
# Feta plugin for installing recommended packages.
# Licensed under the GNU GPL.

use Getopt::Std;
use strict;

my %opts; getopts('tyqV', \%opts);

my @toinstall;

if (@ARGV == 0) {
 print STDERR "E: You must provide at least one package name.\n";
 exit 1;
}

foreach my $package (@ARGV) {
 my @info = `apt-cache depends $package`;
 while (my $p = shift @info) {
  my @possible;
  if ($p =~ /Recommends: (.*)/) {
   $possible[0] = $1;
   my $or = 0;
   if ($p =~ /\|/) { $or = 1; }
   while ($info[0] && ($info[0] !~ /:/ || $or)) {
    $or = 0;
    if ($info[0] =~ /\|/) { $or = 1; }
    $info[0] =~ s/\s+(.*: )?(.+)/$2/g;
    chomp($info[0]);
    push(@possible, shift @info);
   }

   if (@possible == 1 || $opts{'y'}) { push(@toinstall,  $possible[0]); }

   else {
    @possible = sort_uniq(@possible);
    my $i;
    for ( $i = 0; $possible[$i]; $i++) {
     if ($possible[$i] =~ /^<.*>$/) {
      splice (@possible, $i, 1);
      $i--;
     } else { print "$i)  $possible[$i]\n"; }
    }
    print "$i)  None of the above.\n\n";

    print "Please choose one to install [0-$i]: ";
    chomp (my $num = <STDIN>);
    if ($num != $i) { push(@toinstall, $possible[$num]); }
   }
  }
 }
}

if (@toinstall == 0) {
 print STDERR "W: There are no packages to install.\n";
 exit 0;
}

sub sort_uniq { my %a; @a{@_} = 1; return sort keys %a; } # Inefficient. Short.

if (!$opts{'q'}) {
 print "Installing " . join(", ", @toinstall) . ".\n\n";
 print "Some of these packages may already be installed. If they are, they will not\n";
 print "be reinstalled, but they will be upgraded if possible.\n\n";
}

exit system("feta", feta_opts(), "install", @toinstall);

sub feta_opts {
 my @opts;
 foreach ('y','t','V','q') { if ($opts{$_}) { push (@opts, "-$_"); } }
 return @opts;
}