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