-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_certs.sh
executable file
·118 lines (106 loc) · 2.08 KB
/
check_certs.sh
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/perl
sub adjust {
my $newLine = $_[0];
my @neg = @{$_[1]};
my @pos = @{$_[2]};
my $found = 0;
my @newneg = ();
foreach my $cline (@neg) {
if ($cline eq $newLine) {
$found = 1;
} else {
push(@newneg ,$cline );
}
}
if (! $found ) {
push(@pos, $newLine);
}
@neg=@newneg;
}
sub removeLine {
my $newLine = $_[0];
my @neg = @{$_[1]};
my $found = 0;
my @newneg = ();
foreach my $cline (@neg) {
if ($found) {
push(@newneg ,$cline );
} elsif ($cline eq $newLine) {
$found = 1;
} else {
push(@newneg ,$cline );
}
}
return @newneg;
}
sub filter {
my @list = @{$_[0]};
my $string = $_[1];
my @filteredList = ();
foreach my $cline (@list) {
if ($cline =~ m/$string/) {
push(@filteredList ,$cline );
}
}
return @filteredList;
}
sub lineExists {
my $newLine = $_[0];
my @neg = @{$_[1]};
foreach my $cline (@neg) {
if ($cline eq $newLine) {
return 1;
}
}
return 0;
}
sub lineExists {
my $newLine = $_[0];
my @neg = @{$_[1]};
foreach my $cline (@neg) {
if ($cline eq $newLine) {
return 1;
}
}
return 0;
}
sub printeach {
my @args = @{$_[0]};
foreach my $arg (@args) {
chomp $arg;
print " $arg\n";
}
}
open my $handle, "git diff certdata.txt|";
my @diff_lines = <$handle>;
close $handle;
my @adds = ();
my @subs = ();
foreach my $line (@diff_lines) {
$type = substr $line,0,1;
$lline = substr $line,1;
if ($type eq "+") {
if (lineExists($lline, \@subs)) {
@subs = removeLine($lline,\@subs);
} else {
push(@adds, $lline);
}
};
if ($type eq "-") {
if (lineExists($lline, \@adds)) {
@adds = removeLine($lline,\@adds);
} else {
push(@subs, $lline);
}
};
}
my @tmp = filter(\@subs, "# Certificate");
if (@tmp) {
print " Removing: \n";
printeach(\@tmp);
}
my @tmp = filter(\@adds, "# Certificate");
if (@tmp) {
print " Adding: \n";
printeach(\@tmp);
}