]> git.sur5r.net Git - bacula/docs/blob - docs/tools/sf2bacula_downloads.pl
fad7bb4f9dfa835670bb8cb1836530e9209d1b89
[bacula/docs] / docs / tools / sf2bacula_downloads.pl
1 #!/usr/bin/perl -w
2 use strict;
3
4 =head HOWTO USE
5
6 When you release a new version ex: 3.0.3
7  - Modify the $version string
8
9 When you add a new category
10  - Add a print_cat() at the end of the script
11
12 To update the downloads.php file
13
14 - Change the version on the top of the file
15 - ./sf2bacula_downloads.pl > downloads.php
16
17 By default, it downloads the sourceforge page in the current directory
18
19
20 You can also use a previous output
21
22  ./sf2bacula_downloads.pl <version> <sf_list_2022.html> > downloads.php
23
24 =cut
25
26 #             bacula|depkgs | depkgs-qt
27 my $version = '5.0.0';
28 if ($ARGV[0] and $ARGV[0] =~ /^[\d\.]+$/) {
29     $version = shift(@ARGV);
30 }
31 my $depkgs_version  = '18Dec09|28Jul09';
32
33 my $base = "http://bacula.git.sourceforge.net/git/gitweb.cgi?p=bacula/bacula;a=blob_plain;hb=Release-$version;f=bacula";
34 my $notes = "$base/ReleaseNotes";
35 my $chglog = "$base/ChangeLog";
36 my %cats;
37 my $cur;
38 my %seen;
39
40 my $file = "sf_list_$$.html";
41 my $cmd = "wget -O $file https://sourceforge.net/projects/bacula/files";
42
43 if ($ARGV[0] && -f $ARGV[0]) {
44     $file = $ARGV[0];
45 } else {
46     system($cmd);
47 }
48
49 open(FP, $file);
50 while (my $l = <FP>)
51 {
52     #                                         cat   vers  file
53     if ($l =~ m!href="(/projects/bacula/files/([^/]+)/([^/]+)/([^/]+)/download)"!) {
54         print STDERR "$4\n";
55         $cur = {
56             dl  => $1,
57             cat => $2,
58             vers => $3,
59             file => $4
60         };
61     }
62
63     # the size, date, and downloads are just after
64     if ($cur && $l =~ m!<td>([\d\.]+ [KMG]B)</td>!) {
65         $cur->{size} = $1;
66         do {
67             $l = <FP>;
68             if ($l =~ m!<td>(\d{4}-\d{2}-\d{2})</td>!) {
69                 $cur->{date} = $1;
70                 print STDERR "  date: $1\n";
71             }
72         } while (!$cur->{date} and !eof(FP));
73         do {
74             $l = <FP>;
75             if ($l =~ m!<td>([\d,]+)</td>!) {
76                 $cur->{downloads} = $1;
77                 print STDERR "  downloads: $1\n";
78             }
79         } while (!exists $cur->{downloads} and !eof(FP));
80
81
82         # once we have a full $cur element, we can store it
83         if (!exists $seen{$cur->{file}}) {
84             push @{$cats{$cur->{cat}}}, $cur;
85             $seen{$cur->{file}} = 1;
86             $cur = undef;
87         }
88     }
89 }
90 close(FP);
91
92 print '
93 <? require_once("inc/header.php"); ?>
94 <table>
95   <tr>
96    <td class="contentTopic">
97    Bacula downloads for version ', $version, '
98    </td>
99    </tr>
100    <tr>
101      <td class="content">
102      <center>
103       <a href="', $notes, '">Release Notes</a>&nbsp;|&nbsp;
104       <a href="', $chglog, '">ChangeLog</a>&nbsp;|&nbsp;
105       <a href="#bacula">Sources</a>&nbsp;|&nbsp;
106       <a href="#Win32_64">Win32/64</a>&nbsp;|&nbsp;
107       <a href="#rpms">RPM</a>&nbsp;|&nbsp;
108       <a href="https://sourceforge.net/projects/bacula/files/Bacula%20Public%20Key/Current%20Public%20Key/bacula.pub/download">Public Key</a>&nbsp;|&nbsp;
109       <a href="https://sourceforge.net/projects/bacula/files/Bacula%20Public%20Key/Current%20Public%20Key/rpmkey-bacula-0.1-3.noarch.rpm/download">RPM Public Key</a>
110      </center>
111      </td>
112    </tr>
113 ';
114
115 my $cat = 'bacula';
116 #use Data::Dumper;
117 #print Data::Dumper::Dumper(\%cats);
118
119 sub print_cat
120 {
121     my ($cat) = @_;
122     my $row = 'odd';
123
124     print '
125    <tr>
126      <td> <br><a name="', $cat, '"></a><font size="+1"><b>', $cat, ':</b></font>
127 <table cellspacing="2">
128 <tr class="title"><th>Name</th><th align="center">', ($cat !~ /rpm/)?'Signature':'', '</th><th>Size</th><th>Date</th><th>Downloads</th></tr>
129 ';
130     foreach my $elt ( sort { $a->{file} cmp $b->{file} }  @{$cats{$cat}})
131     {
132         next if ($elt->{file} =~ /\.sig/); # we skip signature file
133         if ($elt->{vers} eq $version || $elt->{vers} =~ /$depkgs_version/)
134         {
135             print "
136 <tr class=\"$row\">
137  <td><a href='https://sourceforge.net$elt->{dl}'>$elt->{file}</td>
138  <td align=\"center\">", 
139  ($cat !~ /rpm/)?"<a href='https://sourceforge.net/projects/bacula/files/$cat/$elt->{vers}/$elt->{file}.sig/download'>sig":"", 
140  "</td>
141  <td align=\"right\">$elt->{size}</td>
142  <td align=\"center\">$elt->{date}</td>
143  <td align=\"center\">$elt->{downloads}</td>
144 </tr>
145 ";
146             if ($row eq 'odd') { $row = 'even'; } else { $row = 'odd'; }
147         }
148     }
149     print '</table>
150      </td>
151      </tr>';
152 }
153
154 print_cat('bacula');
155 print_cat('Win32_64');
156 print_cat('rpms');
157 print_cat('rpms-contrib-fschwarz');
158 print_cat('rpms-contrib-psheaffer');
159 print_cat('depkgs');
160 print_cat('depkgs-qt');
161
162
163 print '
164 </table>
165 <? require_once("inc/footer.php"); ?>
166 ';