Fix pod
[grml-infrastructure.git] / tools / get_version
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 get_version - get released upstream versions
6
7 =cut
8
9 use strict; 
10 use warnings; 
11
12 use Pod::Usage;
13 use LWP::Simple;
14 use Compress::Zlib;
15 use Getopt::Long; 
16
17 =head1 SYNOPSIS
18
19 get_version [OPTIONS] <packagenames>
20
21 =head1 OPTIONS
22
23 =over 8
24
25 =item B<--release>=VERSION
26
27 Releaseversion where you are looking for (e.g. 1.0, grml-testing would also
28 work).
29
30 =back EXAMPLES
31
32   get_version --release 1.0 zsh-lovers
33
34   get_version --release grml-testing grml2hd
35
36 =cut
37
38 my ($grml_release, $package); 
39
40 GetOptions(
41     "release=s" => \$grml_release,
42     "help" => sub { pod2usage(-exitval => 0, -verbose => 2); },
43 );
44
45 pod2usage("$0: Please provide a releasename.\n") unless $grml_release;
46 pod2usage("$0: Need a packagename to process.\n")  unless @ARGV;
47
48 if ($grml_release =~ /[0-9]/) {
49     $grml_release = "grml-$grml_release"; 
50 }
51
52 my $sources_file =
53     get("http://deb.grml.org/dists/$grml_release/main/source/Sources.gz")
54         or die "Could not open Sources.gz: $!"; 
55
56 $sources_file = Compress::Zlib::memGunzip($sources_file);
57
58 foreach my $package (@ARGV) {
59     my ($found_version,$found); 
60
61     foreach my $line (split("\n", $sources_file)) {
62         if ($line =~ /^Package: $package/) {
63             $found = 1; 
64         }
65         if ($line =~ /^Version: (.*)/ && $found) { 
66             $found_version = $1; 
67             last;
68         }
69     }
70
71     if ($found) {
72         print "$package: $found_version\n";
73     } else {
74         print "$package not found in GRML $grml_release\n"; 
75     }
76 }