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(my $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(my $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(my $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 open($filedata, "<", $target)
59 or die "Can't open '$target' to generate checksum $!";
60 my $sha1 = Digest::SHA1->new;
61 $sha1->addfile($filedata);
63 $target_sha1 = $sha1->hexdigest;
66 $target_uri = $fi1 . '/' . $fi2 . '/' . $fi3;
67 $target_time = (stat $target)[9];
71 '<item><title><![CDATA[' . $target_uri . ']]></title>';
73 '<description><![CDATA['
77 . ')]]></description>';
86 $target_line .= '<pubDate>';
87 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
90 "$days[$wday], $mday $months[$mon] "
92 . " $hour:$min:$sec GMT";
93 $target_line .= '</pubDate></item>';
96 $Array[$i] = ([$target_time, $target_line]);
98 die "maxlimit $maxlimit reached!" unless ($i < $maxlimit);
101 ## end listing /OS/Version/FILE
109 # Result = Full XML Codes
111 '<?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>';
112 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = gmtime();
114 "$days[$wday], $mday $months[$mon] "
116 . " $hour:$min:$sec GMT";
117 $result .= '</pubDate>';
120 my @resArray = sort { @$a[0] <=> @$b[0] } @Array;
122 while ($max_advertised_files-- > 0 && $i >= 0) {
123 $result .= $resArray[$i][1];
126 $result .= '</channel></rss>';
129 open(my $XMLF, ">", $save_rss_file) or die "Failed to write XML file";