]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env perl | |
2 | ||
3 | use warnings; | |
4 | use strict; | |
5 | use autodie qw / :all /; | |
6 | use LWP::UserAgent; | |
7 | use File::Basename qw/ fileparse /; | |
8 | use File::Path qw/ rmtree /; | |
9 | ||
10 | sub einfo { | |
11 | printf( "[INFO] >>> %s\n", join( ' ', @_ ) ); | |
12 | } | |
13 | ||
14 | sub 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 | ||
46 | my $script_dir = ( fileparse( __FILE__ ) )[1]; | |
47 | chdir( $script_dir ); | |
48 | ||
49 | my $latest_patch = fetch( 'https://grsecurity.net/latest_test_patch' ); | |
50 | chomp( $latest_patch ); | |
51 | einfo "Latest patch $latest_patch"; | |
52 | ||
53 | my ( $grsec_major_version, $kernel_version, $grsec_patch_version ) = ( $latest_patch =~ m/^grsecurity-([0-9.]+)-([0-9.]+)-([0-9]+)\.patch$/ ); | |
54 | ||
55 | for my $var ( $grsec_major_version, $kernel_version, $grsec_patch_version ) { | |
56 | die "Wrong patch file name?\n" unless defined( $var ) and length $var; | |
57 | } | |
58 | ||
59 | if ( -f "test/$kernel_version/$latest_patch" ) { | |
60 | einfo "Already downloaded."; | |
61 | exit 0; | |
62 | } | |
63 | ||
64 | if ( -d 'tmp' ) { | |
65 | rmtree( 'tmp' ); | |
66 | } | |
67 | mkdir( 'tmp' ); | |
68 | ||
69 | fetch( "https://grsecurity.net/test/$latest_patch", "tmp/$latest_patch" ); | |
70 | fetch( "https://grsecurity.net/test/$latest_patch.sig", "tmp/$latest_patch.sig" ); | |
71 | fetch( 'https://grsecurity.net/changelog-test.txt', 'tmp/changelog-test.txt' ); | |
72 | ||
73 | mkdir( "test/$kernel_version" ) if not ( -d "test/$kernel_version" ); | |
74 | rename( "tmp/$latest_patch", "test/$kernel_version/$latest_patch" ); | |
75 | rename( "tmp/$latest_patch.sig", "test/$kernel_version/$latest_patch.sig" ); | |
76 | rename( 'tmp/changelog-test.txt', 'test/changelog-test.txt' ); | |
77 | ||
78 | einfo 'git add ..,'; | |
79 | system( | |
80 | "git", "add", | |
81 | "test/$kernel_version/$latest_patch", | |
82 | "test/$kernel_version/$latest_patch.sig", | |
83 | 'test/changelog-test.txt' | |
84 | ); | |
85 | ||
86 | einfo 'git commit ...'; | |
87 | system( | |
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 | ||
94 | einfo 'git push ...'; | |
95 | system("git", "push"); |