-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathupgrade-patches.pl
More file actions
executable file
·51 lines (40 loc) · 1.36 KB
/
upgrade-patches.pl
File metadata and controls
executable file
·51 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env perl
use strict;
use warnings;
my $ver = shift or usage();
my $newver = shift or usage();
my $newdir = "patches/nginx/$newver";
system("mkdir -p $newdir") == 0 or die "failed to create directory $newdir: $!\n";
my @files = `find patches/nginx/$ver -name '*.patch'`;
for my $file (@files) {
chomp $file;
next unless $file =~ m{^patches/nginx/(?:$ver|$newver)/nginx-(?:$ver|$newver)-};
(my $newfile = $file) =~ s{nginx/$ver/}{nginx/$newver/}g;
$newfile =~ s/nginx-$ver-/nginx-$newver-/g;
if ($newfile ne $file && !-f $newfile) {
my $cmd = "cp $file $newfile";
system($cmd) == 0
or die "failed run command $cmd.\n";
$cmd = "git add $newfile";
system($cmd) == 0
or die "failed run command $cmd.\n";
}
my $cmd = "sed -i 's/\Q$ver\E/$newver/g' $newfile";
system($cmd) == 0
or die "failed to run command $cmd.\n";
my $oldver_int = version_to_int($ver);
my $newver_int = version_to_int($newver);
warn "$oldver_int => $newver_int\n";
$cmd = "sed -i 's/$oldver_int/$newver_int/g' $newfile";
system($cmd) == 0
or die "failed to run command $cmd.\n";
print "$file => $newfile\n";
}
sub usage {
die "Usage: $0 <old-version> <new-version>\n";
}
sub version_to_int {
my $ver = shift;
$ver =~ s/\.(\d+)/sprintf("%03d", $1)/eg;
$ver
}