#!/usr/bin/perl -w use strict; =head HOWTO USE When you release a new version ex: 3.0.3 - Modify the $version string When you add a new category - Add a print_cat() at the end of the script To update the downloads.php file - Change the version on the top of the file - ./sf2bacula_downloads.pl > downloads.php By default, it downloads the sourceforge page in the current directory You can also use a previous output ./sf2bacula_downloads.pl > downloads.php =cut # bacula|depkgs | depkgs-qt my $version = '5.0.1'; if ($ARGV[0] and $ARGV[0] =~ /^[\d\.]+$/) { $version = shift(@ARGV); } my $depkgs_version = '18Dec09|28Jul09|15May10'; my $base = "http://bacula.git.sourceforge.net/git/gitweb.cgi?p=bacula/bacula;a=blob_plain;hb=Release-$version;f=bacula"; my $notes = "$base/ReleaseNotes"; my $chglog = "$base/ChangeLog"; my %cats; my $cur; my %seen; my $file = "sf_list_$$.html"; my $cmd = "wget -O $file https://sourceforge.net/projects/bacula/files"; if ($ARGV[0] && -f $ARGV[0]) { $file = $ARGV[0]; } else { system($cmd); } open(FP, $file); while (my $l = ) { # cat vers file if ($l =~ m!href="(?:http://sourceforge.net)(/projects/bacula/files/([^/]+)/([^/]+)/([^/]+)/download)"!) { print STDERR "$4\n"; $cur = { dl => $1, cat => $2, vers => $3, file => $4 }; } # the size, date, and downloads are just after if ($cur && $l =~ m!([\d\.]+ [KMG]B)!) { $cur->{size} = $1; do { $l = ; if ($l =~ m!(\d{4}-\d{2}-\d{2})!) { $cur->{date} = $1; print STDERR " date: $1\n"; } } while (!$cur->{date} and !eof(FP)); do { $l = ; if ($l =~ m!([\d,]+)!) { $cur->{downloads} = $1; print STDERR " downloads: $1\n"; } } while (!exists $cur->{downloads} and !eof(FP)); # once we have a full $cur element, we can store it if (!exists $seen{$cur->{file}}) { push @{$cats{$cur->{cat}}}, $cur; $seen{$cur->{file}} = 1; $cur = undef; } } } close(FP); print ' '; my $cat = 'bacula'; #use Data::Dumper; #print Data::Dumper::Dumper(\%cats); sub print_cat { my ($cat) = @_; my $row = 'odd'; print ' '; } print_cat('bacula'); print_cat('Win32_64'); print_cat('rpms'); print_cat('rpms-contrib-fschwarz'); print_cat('rpms-contrib-psheaffer'); print_cat('depkgs'); print_cat('depkgs-qt'); print '
Bacula downloads for version ', $version, '
Release Notes |  ChangeLog |  Sources |  Win32/64 |  RPM |  Public Key |  RPM Public Key

', $cat, ': '; foreach my $elt ( sort { $a->{file} cmp $b->{file} } @{$cats{$cat}}) { next if ($elt->{file} =~ /\.sig/); # we skip signature file if ($elt->{vers} eq $version || $elt->{vers} =~ /$depkgs_version/) { print " "; if ($row eq 'odd') { $row = 'even'; } else { $row = 'odd'; } } } print '
Name', ($cat !~ /rpm/)?'Signature':'', 'SizeDateDownloads
$elt->{file} ", ($cat !~ /rpm/)?"sig":"", " $elt->{size} $elt->{date} $elt->{downloads}
', scalar(localtime), ' ';