summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/just_fetch.pl')
-rwxr-xr-xscripts/just_fetch.pl107
1 files changed, 107 insertions, 0 deletions
diff --git a/scripts/just_fetch.pl b/scripts/just_fetch.pl
new file mode 100755
index 0000000..bc9f921
--- /dev/null
+++ b/scripts/just_fetch.pl
@@ -0,0 +1,107 @@
+#!/usr/bin/perl
+
+use strict ;
+use LWP::Simple ; ;
+use HTML::LinkExtor ;
+
+my $upstream_url = "http://grsecurity.net/test.php" ;
+
+my $file_pattern = "grsecurity-2.2.2-";
+my @allowed_suffixes = ( ".patch", ".patch.sig" ) ;
+
+my %currently_available = () ;
+
+
+sub sane
+{
+ my ( $name ) = @_ ;
+
+ return 0 if $name eq "" ;
+ return 0 if $name =~ / / ;
+
+ my $got_suffix = 0 ;
+ foreach my $suffix ( @allowed_suffixes )
+ {
+ $got_suffix = 1 if $name =~ /$suffix$/ ;
+ }
+
+ return $got_suffix ;
+}
+
+
+sub get_currently_available
+{
+ my $parser ;
+ my @links ;
+
+ $parser = HTML::LinkExtor->new( undef, $upstream_url ) ;
+ $parser->parse( get( $upstream_url ) )->eof ;
+
+ @links = $parser->links ;
+
+ foreach my $ref ( @links )
+ {
+ my $file_url = ${$ref}[2] ;
+ my $file_name = $file_url ;
+ $file_name =~ s/^.*\/(.*)$/$1/ ;
+
+ next unless sane( $file_name ) ;
+
+ $currently_available{ $file_name } = $file_url ;
+ }
+}
+
+
+sub download_newly_available
+{
+ my $downloads = "" ;
+
+ foreach my $file_name ( sort keys %currently_available )
+ {
+ next unless $file_name =~ /$file_pattern/ ;
+ print "\tDownloading $file_name ... " ;
+ my $file_url = $currently_available{ $file_name } ;
+ if ( getstore( $file_url, $file_name ) )
+ {
+ print "OK\n" ;
+ $downloads .= "\t$file_name\n" ;
+ }
+ else
+ {
+ print "FAIL\n" ;
+ }
+ }
+
+ return $downloads ;
+}
+
+
+sub print_successful_downloads
+{
+ my ( $downloads ) = @_ ;
+
+ if( $downloads ne "" )
+ {
+ print "\n\nSuccessfully downloaded files from upstream:\n\n" ;
+ print $downloads ;
+ print "\n\n" ;
+ }
+ else
+ {
+ print "\n\nNo files downloaded from upstream --- nothing to report.\n\n" ;
+ print "\n\n" ;
+ }
+}
+
+
+sub main
+{
+ get_currently_available() ;
+ my $downloads = download_newly_available() ;
+
+ print_successful_downloads( $downloads ) ;
+}
+
+main() ;
+
+