]> git.sur5r.net Git - bacula/docs/blob - docs/tools/sf2bacula_downloads.pl
Update downloads
[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 = '3.0.3';
28 if ($ARGV[0] =~ /^[\d\.]+$/) {
29     $version = shift(@ARGV);
30 }
31 my $depkgs_version  = '18Feb09|28Jul09';
32
33 my $base = "http://bacula.svn.sourceforge.net/viewvc/bacula/tags/Release-$version/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         $cur = {
55             dl  => $1,
56             cat => $2,
57             vers => $3,
58             file => $4
59         };
60     }
61
62     # the size, date, and downloads are just after
63     if ($cur && $l =~ m!<td>([\d\.]+ [KMG]B)</td>!) {
64         $cur->{size} = $1;
65         do {
66             $l = <FP>;
67             if ($l =~ m!<td>(.*?)</td>!) {
68                 $cur->{date} = $1;
69             }
70         } while (!$cur->{date});
71         do {
72             $l = <FP>;
73             if ($l =~ m!<td>(.*?)</td>!) {
74                 $cur->{downloads} = $1;
75             }
76         } while (!$cur->{downloads});
77
78
79         # once we have a full $cur element, we can store it
80         if (!exists $seen{$cur->{file}}) {
81             push @{$cats{$cur->{cat}}}, $cur;
82             $seen{$cur->{file}} = 1;
83             $cur = undef;
84         }
85     }
86 }
87 close(FP);
88
89 print '
90 <? require_once("inc/header.php"); ?>
91 <table>
92   <tr>
93    <td class="contentTopic">
94    Bacula downloads for version ', $version, '
95    </td>
96    </tr>
97    <tr>
98      <td class="content">
99      <center>
100       <a href="', $notes, '">Release Notes</a>&nbsp;|&nbsp;
101       <a href="', $chglog, '">ChangeLog</a>&nbsp;|&nbsp;
102       <a href="#bacula">Sources</a>&nbsp;|&nbsp;
103       <a href="#Win32_64">Win32/64</a>&nbsp;|&nbsp;
104       <a href="#rpms">RPM</a>&nbsp;|&nbsp;
105       <a href="https://sourceforge.net/projects/bacula/files/Bacula%20Public%20Key/Current%20Public%20Key/bacula.pub/download">Public Key</a>&nbsp;|&nbsp;
106       <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>
107      </center>
108      </td>
109    </tr>
110 ';
111
112 my $cat = 'bacula';
113 my $row = 'odd';
114 #use Data::Dumper;
115 #print Data::Dumper::Dumper(\%cats);
116
117 sub print_cat
118 {
119     my ($cat) = @_;
120
121     print '
122    <tr>
123      <td> <br><a name="', $cat, '"></a><font size="+1"><b>', $cat, ':</b></font>
124 <table cellspacing="2">
125 <tr class="title"><th>Name</th><th align="center">', ($cat !~ /rpm/)?'Signature':'', '</th><th>Size</th><th>Date</th><th>Downloads</th></tr>
126 ';
127     foreach my $elt ( sort { $a->{file} cmp $b->{file} }  @{$cats{$cat}})
128     {
129         next if ($elt->{file} =~ /\.sig/); # we skip signature file
130         if ($elt->{vers} eq $version || $elt->{vers} =~ /$depkgs_version/)
131         {
132             print "
133 <tr class=\"$row\">
134  <td><a href='https://sourceforge.net$elt->{dl}'>$elt->{file}</td>
135  <td align=\"center\">", 
136  ($cat !~ /rpm/)?"<a href='https://sourceforge.net/projects/bacula/files/$cat/$elt->{vers}/$elt->{file}.sig/download'>sig":"", 
137  "</td>
138  <td align=\"right\">$elt->{size}</td>
139  <td align=\"center\">$elt->{date}</td>
140  <td align=\"center\">$elt->{downloads}</td>
141 </tr>
142 ";
143         }
144         if ($row eq 'odd') { $row = 'even'; } else { $row = 'odd'; }
145     }
146     print '</table>
147      </td>
148      </tr>';
149 }
150
151 print_cat('bacula');
152 print_cat('Win32_64');
153 print_cat('rpms');
154 print_cat('rpms-contrib-fschwarz');
155 print_cat('rpms-contrib-psheaffer');
156 print_cat('depkgs');
157 print_cat('depkgs-qt');
158
159
160 print '
161 </table>
162 <? require_once("inc/footer.php"); ?>
163 ';