6 my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
7 my @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
10 my $scan_dir = '/xxxxxxxxxxxxxxxxxxxxxx/sf-download/';
11 my $base_dlurl = 'https://www.privoxy.org/sf-download-mirror/';
12 my $save_rss_file ='/xxxxxxxxxxxxxxxxxxxxxx/release.xml'; # e.g., release.rss
14 my $max_advertised_files = 100;
36 # 1st & 2nd directory should NOT contain ANY 'FILES'. (expecting only 'Directory')
38 opendir(D1, $scan_dir) or die "Can't open 1st directory! /";
39 while (my $fi1 = readdir(D1)) {
40 next if ($fi1 =~ m/^\./);
42 next if ($fi1 eq 'OldFiles' or $fi1 eq 'pkgsrc');
43 opendir(D2, $scan_dir . $fi1 . '/')
44 or die "Can't open 2nd directory! /$fi1";
45 while (my $fi2 = readdir(D2)) {
46 next if ($fi2 =~ m/^\./);
48 ## start listing /OS/Version/FILE
49 opendir(D3, $scan_dir . $fi1 . '/' . $fi2 . '/')
50 or die "Can't open 3rd directory! /$fi1/$fi2";
51 while (my $fi3 = readdir(D3)) {
52 next if ($fi3 =~ m/^\./);
53 $target = $scan_dir . $fi1 . '/' . $fi2 . '/' . $fi3;
54 next if (!-e $target); # skip if file is not exist
58 unless (open $filedata, $target) { next; }
59 my $sha1 = Digest::SHA1->new;
60 $sha1->addfile($filedata);
62 $target_sha1 = $sha1->hexdigest;
65 $target_uri = $fi1 . '/' . $fi2 . '/' . $fi3;
66 $target_time = (stat $target)[9];
70 '<item><title><![CDATA[' . $target_uri . ']]></title>';
72 '<description><![CDATA['
76 . ')]]></description>';
85 $target_line .= '<pubDate>';
86 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
89 "$days[$wday], $mday $months[$mon] "
91 . " $hour:$min:$sec GMT";
92 $target_line .= '</pubDate></item>';
95 $Array[$i] = ([$target_time, $target_line]);
97 die "maxlimit $maxlimit reached!" unless ($i < $maxlimit);
100 ## end listing /OS/Version/FILE
108 # Result = Full XML Codes
110 '<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel><title>Privoxy Releases</title><link>https://www.privoxy.org/announce.txt</link><description><![CDATA[Privoxy Releases RSS feed]]></description><pubDate>';
111 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = gmtime();
113 "$days[$wday], $mday $months[$mon] "
115 . " $hour:$min:$sec GMT";
116 $result .= '</pubDate>';
119 my @resArray = sort { @$a[0] <=> @$b[0] } @Array;
121 while ($max_advertised_files-- > 0 && $i >= 0) {
122 $result .= $resArray[$i][1];
125 $result .= '</channel></rss>';
128 open(XMLF, "> $save_rss_file") or die "Failed to write XML file";