Auto commit, grsecurity-3.1-4.9.13-201703052141.patch added.
[thirdparty/grsecurity-scrape.git] / scrape.pl
CommitLineData
3fb94683 1#!/usr/bin/env perl
6ed33715
PK
2
3use warnings;
4use strict;
3fb94683
KP
5use autodie qw / :all /;
6use LWP::UserAgent;
7use File::Basename qw/ fileparse /;
8use File::Path qw/ rmtree /;
9
10sub einfo {
11 printf( "[INFO] >>> %s\n", join( ' ', @_ ) );
12}
13
14sub fetch {
15 my ( $url, $save_to ) = @_;
16
17 my $ua = LWP::UserAgent->new;
18
19 einfo( "Fetching $url ..." );
20
21 my $response = $ua->get( $url, 'Accept-Encoding' => 'gzip' );
22
23 if ( $response->is_success ) {
24 if ( $save_to ) {
25 open( my $file, '>', $save_to );
26
27 my $content = $response->decoded_content;
28
29 if ( utf8::is_utf8( $content ) ) {
30 binmode( $file,':utf8' );
31 } else {
32 binmode( $file,':raw' );
33 }
34
35 print $file $content;
36 close( $file );
37 return 1;
38 } else {
39 return $response->decoded_content;
40 }
41 } else {
42 die "Fetch failed.\n";
43 }
44}
45
46my $script_dir = ( fileparse( __FILE__ ) )[1];
47chdir( $script_dir );
48
49my $latest_patch = fetch( 'https://grsecurity.net/latest_test_patch' );
50chomp( $latest_patch );
51einfo "Latest patch $latest_patch";
52
53my ( $grsec_major_version, $kernel_version, $grsec_patch_version ) = ( $latest_patch =~ m/^grsecurity-([0-9.]+)-([0-9.]+)-([0-9]+)\.patch$/ );
54
55for my $var ( $grsec_major_version, $kernel_version, $grsec_patch_version ) {
56 die "Wrong patch file name?\n" unless defined( $var ) and length $var;
6ed33715 57}
3fb94683
KP
58
59if ( -f "test/$kernel_version/$latest_patch" ) {
60 einfo "Already downloaded.";
61 exit 0;
6ed33715
PK
62}
63
3fb94683
KP
64if ( -d 'tmp' ) {
65 rmtree( 'tmp' );
66}
67mkdir( 'tmp' );
68
69fetch( "https://grsecurity.net/test/$latest_patch", "tmp/$latest_patch" );
70fetch( "https://grsecurity.net/test/$latest_patch.sig", "tmp/$latest_patch.sig" );
71fetch( 'https://grsecurity.net/changelog-test.txt', 'tmp/changelog-test.txt' );
72
73mkdir( "test/$kernel_version" ) if not ( -d "test/$kernel_version" );
74rename( "tmp/$latest_patch", "test/$kernel_version/$latest_patch" );
75rename( "tmp/$latest_patch.sig", "test/$kernel_version/$latest_patch.sig" );
76rename( 'tmp/changelog-test.txt', 'test/changelog-test.txt' );
77
78einfo 'git add ..,';
79system(
80 "git", "add",
81 "test/$kernel_version/$latest_patch",
82 "test/$kernel_version/$latest_patch.sig",
83 'test/changelog-test.txt'
84);
85
86einfo 'git commit ...';
87system(
88 "git", "commit", "-m", "Auto commit, $latest_patch added.",
89 "test/$kernel_version/$latest_patch",
90 "test/$kernel_version/$latest_patch.sig",
91 'test/changelog-test.txt'
92);
93
94einfo 'git push ...';
10163284 95system("git", "push");