create-package-feed.pl: Generate valid (RFC-822) dates
[privoxy.git] / utils / create-package-feed.pl
index e505086..ede1ee7 100644 (file)
@@ -2,14 +2,16 @@
 #< LICENSE: WTFPL >
 use warnings;
 use strict;
-use Digest::SHA1;
+use Digest::SHA;
 my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
 my @days   = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
 
 #< Config START >
-my $scan_dir   = '/xxxxxxxxxxxxxxxxxxxxxx/sf-download/';
+my $scan_dir = shift(@ARGV)
+    or die "Local package directory not specified (first argument)\n";
+my $save_rss_file = shift(@ARGV)
+    or die "RSS output file path not specified (second argument)\n";
 my $base_dlurl = 'https://www.privoxy.org/sf-download-mirror/';
-my $save_rss_file ='/xxxxxxxxxxxxxxxxxxxxxx/release.xml'; # e.g., release.rss
 my $maxlimit = 1000;
 my $max_advertised_files = 100;
 
@@ -27,7 +29,7 @@ my $wday;
 my $yday;
 my $isdst;
 my $target;
-my $target_sha1;
+my $target_sha256;
 my $target_uri;
 my $target_time;
 my $target_line;
@@ -53,14 +55,14 @@ while (my $fi1 = readdir($D1)) {
             $target = $scan_dir . $fi1 . '/' . $fi2 . '/' . $fi3;
             next if (!-e $target);    # skip if file is not exist
 
-            # Get SHA-1 hash
+            # Get SHA-256 hash
             my $filedata;
             open($filedata, "<", $target)
                 or die "Can't open '$target' to generate checksum $!";
-            my $sha1 = Digest::SHA1->new;
-            $sha1->addfile($filedata);
+            my $sha256 = Digest::SHA->new("SHA-256");
+            $sha256->addfile($filedata);
             close($filedata);
-            $target_sha1 = $sha1->hexdigest;
+            $target_sha256 = $sha256->hexdigest;
 
             # URI and Time
             $target_uri  = $fi1 . '/' . $fi2 . '/' . $fi3;
@@ -72,8 +74,8 @@ while (my $fi1 = readdir($D1)) {
             $target_line .=
                   '<description><![CDATA['
                 . $target_uri
-                . ' (SHA-1: '
-                . $target_sha1
+                . ' (SHA-256: '
+                . $target_sha256
                 . ')]]></description>';
             $target_line .=
                   '<link>'
@@ -86,10 +88,9 @@ while (my $fi1 = readdir($D1)) {
             $target_line .= '<pubDate>';
             ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
                 gmtime($target_time);
-            $target_line .=
-                  "$days[$wday], $mday $months[$mon] "
-                . ($year + 1900)
-                . " $hour:$min:$sec GMT";
+            $target_line .= sprintf("%s, %s %s %d %.2d:%.2d:%.2d GMT",
+                $days[$wday], $mday, $months[$mon], ($year + 1900),
+                $hour, $min, $sec);
             $target_line .= '</pubDate></item>';
 
             # Add it to Array