-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathsystemtap-setup.pl
103 lines (89 loc) · 2.09 KB
/
systemtap-setup.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
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
#!/usr/bin/env perl
#
use strict;
use Term::ANSIColor;
#use Smart::Comments;
my $user = `whoami`;
chomp($user);
### $user
my $password;
### $password
if( $> != '0') {
#&noecho();
#print "password for $user: ";
#$password = <>;
#&echo();
#
#`sudo -s << "EOF" $password EOF perl $0;`;
#print "\n$password\n";
&myprint("Must be root to run this script.");
exit;
}
&main();
sub main {
my $uname = `uname -r`;
chomp($uname);
my $error = 0;
my @softlist = ('systemtap',
'systemtap-runtime',
'kernel-debuginfo',
'kernel-debuginfo-common',
'kernel-devel');
foreach my $soft (@softlist) {
if($soft =~ /kernel/) {
$soft .= "-$uname";
if(&install($soft) != 0) {
$error = 1;
}
} else {
if(&install($soft) != 0) {
$error = 1;
}
}
}
if($error) {
&myprint("Systemtap setup unsuccessful.\n");
} else {
&yesinstall("Systamtap setup successful.\n");
}
}
sub noecho {
print `stty -echo`
}
sub echo {
print `stty sane`
}
sub install {
my $soft = shift;
### $soft
my $result;
$result = `yum install -y $soft 2>&1`;
if($result =~ "already installed" or $result =~ "Installed:"
or $result =~ "Updated:" or $result =~ "already"
or $result =~ "newly installed") {
print color("blue");
print("+++The $soft installed successful.\n\n");
print color("reset");
$result = 0;
} elsif ($result =~ "No package $soft available") {
&myprint("Check the name of software: $soft\n");
$result = 1;
} elsif ($result =~ "need to be root") {
&myprint("Need to be root to install $soft.\n");
$result = 1;
}else {
&myprint("$result\n");
$result = 0;
}
return $result;
}
sub myprint {
print color("red");
print("@_ \n");
print color("reset");
}
sub yesinstall {
print color("green");
print("@_ \n");
print color("reset");
}