-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkir.pl
60 lines (58 loc) · 1.7 KB
/
kir.pl
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
#!/usr/bin/perl -w
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright: 2012-2013 by Matteo Pasotti <[email protected]>
use strict;
use warnings;
use diagnostics;
use Getopt::Long;
my $PKG_REMOVER="/usr/sbin/urpme";
my $KRNLTOKEEP=3;
my $force=0;
#my $PKG_REMOVER="echo";
my $result = GetOptions ("kernelstokeep=i" => \$KRNLTOKEEP, # numeric
"pkgremover=s" => \$PKG_REMOVER, # string
"force" => \$force); # flag
my @commandlist;
my @lista=`rpm -qa kernel-\{server,desktop\}* | egrep -v 'devel|latest'`;
@lista=sort @lista;
my $count=scalar @lista;
my $current=0;
if($count>$KRNLTOKEEP){
print "SUMMARY OF THE KERNELS (".($count-$KRNLTOKEEP)."/$count) THAT WILL BE REMOVED:\n";
for(@lista){
if($current<($count-$KRNLTOKEEP)){
chomp $_;
print "$_\n";
my @args = ("/usr/bin/env", $PKG_REMOVER, "--auto", $_);
push @commandlist, [ @args ];
}
$current++;
}
}else{
exit(2);
}
$current=0;
print "Are you sure?\n";
my $char=<STDIN>;
chomp $char;
if(lc($char) eq 'y'){
for my $aref (@commandlist){
print "Removing ".@$aref[2]."...\n";
system(@$aref);
}
}elsif(lc($char) eq 'n'){
exit(0);
}
exit(1);