Add executable flag
[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 =item B<--release>=VERSION
24
25 Releaseversion where you are looking for (e.g. 1.0, grml-testing would also
26 work).
27
28 =back EXAMPLES
29
30   get_version --release 1.0 zsh-lovers
31
32   get_version --release grml-testing grml2hd
33
34 =cut
35
36 my ($grml_release, $package); 
37
38 GetOptions(
39     "release=s" => \$grml_release,
40     "help" => sub { pod2usage(-exitval => 0, -verbose => 2); },
41 );
42
43 pod2usage("$0: Please provide a releasename.\n") unless $grml_release;
44 pod2usage("$0: Need a packagename to process.\n")  unless @ARGV;
45
46 if ($grml_release =~ /[0-9]/) {
47     $grml_release = "grml-$grml_release"; 
48 }
49
50 my $sources_file =
51     get("http://deb.grml.org/dists/$grml_release/main/source/Sources.gz")
52         or die "Could not open Sources.gz: $!"; 
53
54 $sources_file = Compress::Zlib::memGunzip($sources_file);
55
56 foreach my $package (@ARGV) {
57     my ($found_version,$found); 
58
59     foreach my $line (split("\n", $sources_file)) {
60         if ($line =~ /^Package: $package/) {
61             $found = 1; 
62         }
63         if ($line =~ /^Version: (.*)/ && $found) { 
64             $found_version = $1; 
65             last;
66         }
67     }
68
69     if ($found) {
70         print "$package: $found_version\n";
71     } else {
72         print "$package not found in GRML $grml_release\n"; 
73     }
74 }