This commit is contained in:
root 2016-04-19 16:04:13 +02:00
commit a8babd7e69

View File

@ -50,6 +50,9 @@ use Cwd 'abs_path';
use Data::Dumper; use Data::Dumper;
$Data::Dumper::Pair = " : "; $Data::Dumper::Pair = " : ";
# for which()
use Env;
# Set up a few variables for use in the script # Set up a few variables for use in the script
my $tunerversion = "1.6.10"; my $tunerversion = "1.6.10";
my ( @adjvars, @generalrec ); my ( @adjvars, @generalrec );
@ -442,19 +445,20 @@ sub os_setup {
} }
sub get_http_cli { sub get_http_cli {
my $httpcli = `which curl`; my $httpcli = which("curl", $PATH);
chomp($httpcli); chomp($httpcli);
if ( defined($httpcli) and -e "$httpcli" ) { if ($httpcli) {
return $httpcli; return $httpcli;
} }
$httpcli = `which wget`; $httpcli = which("wget", $PATH);
chomp($httpcli); chomp($httpcli);
if ( defined($httpcli) and -e "$httpcli" ) { if ($httpcli) {
return $httpcli; return $httpcli;
} }
return ""; return "";
} }
# Checks for updates to MySQLTuner # Checks for updates to MySQLTuner
sub validate_tuner_version { sub validate_tuner_version {
if ( $opt{'checkversion'} eq 0 and $opt{'updateversion'} eq 0 ) { if ( $opt{'checkversion'} eq 0 and $opt{'updateversion'} eq 0 ) {
@ -466,9 +470,8 @@ sub validate_tuner_version {
my $update; my $update;
my $url = my $url =
"https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl"; "https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl";
my $httpcli = `which curl`; my $httpcli = get_http_cli();
chomp($httpcli); if ( $httpcli =~ /curl$/ ) {
if ( 1 != 1 and defined($httpcli) and -e "$httpcli" ) {
debugprint "$httpcli is available."; debugprint "$httpcli is available.";
debugprint debugprint
@ -484,9 +487,7 @@ sub validate_tuner_version {
} }
$httpcli = `which wget`; if ($httpcli =~ /wget$/ ) {
chomp($httpcli);
if ( defined($httpcli) and -e "$httpcli" ) {
debugprint "$httpcli is available."; debugprint "$httpcli is available.";
debugprint debugprint
@ -516,12 +517,11 @@ sub update_tuner_version {
( "mysqltuner.pl", "basic_passwords.txt", "vulnerabilities.csv" ); ( "mysqltuner.pl", "basic_passwords.txt", "vulnerabilities.csv" );
my $totalScripts = scalar(@scripts); my $totalScripts = scalar(@scripts);
my $receivedScripts = 0; my $receivedScripts = 0;
my $httpcli = `which curl`; my $httpcli = get_http_cli();
foreach my $script (@scripts) { foreach my $script (@scripts) {
chomp($httpcli); if ( $httpcli =~ /curl$/ ) {
if ( 1 != 1 and defined($httpcli) and -e "$httpcli" ) {
debugprint "$httpcli is available."; debugprint "$httpcli is available.";
debugprint debugprint
@ -539,33 +539,29 @@ sub update_tuner_version {
debugprint "$script updated: $update"; debugprint "$script updated: $update";
} }
} }
else { elsif ( $httpcli =~ /wget$/ ) {
$httpcli = `which wget`; debugprint "$httpcli is available.";
chomp($httpcli);
if ( defined($httpcli) and -e "$httpcli" ) {
debugprint "$httpcli is available.";
debugprint debugprint
"$httpcli -qe timestamping=off -T 5 -O $script '$url$script'"; "$httpcli -qe timestamping=off -T 5 -O $script '$url$script'";
$update = $update =
`$httpcli -qe timestamping=off -T 5 -O $script '$url$script'`; `$httpcli -qe timestamping=off -T 5 -O $script '$url$script'`;
chomp($update); chomp($update);
if ( -s $script eq 0 ) { if ( -s $script eq 0 ) {
badprint "Couldn't update $script"; badprint "Couldn't update $script";
} }
else { else {
++$receivedScripts; ++$receivedScripts;
debugprint "$script updated: $update"; debugprint "$script updated: $update";
} }
}
} else {
else { debugprint "curl and wget are not available.";
debugprint "curl and wget are not available."; infoprint "Unable to check for the latest MySQLTuner version";
infoprint "Unable to check for the latest MySQLTuner version"; }
}
}
} }
if ( $receivedScripts eq $totalScripts ) { if ( $receivedScripts eq $totalScripts ) {
@ -612,7 +608,7 @@ sub mysql_setup {
$mysqladmincmd = $opt{mysqladmin}; $mysqladmincmd = $opt{mysqladmin};
} }
else { else {
$mysqladmincmd = `which mysqladmin`; $mysqladmincmd = which("mysqladmin", $PATH);
} }
chomp($mysqladmincmd); chomp($mysqladmincmd);
if ( !-e $mysqladmincmd && $opt{mysqladmin} ) { if ( !-e $mysqladmincmd && $opt{mysqladmin} ) {
@ -628,7 +624,7 @@ sub mysql_setup {
$mysqlcmd = $opt{mysqlcmd}; $mysqlcmd = $opt{mysqlcmd};
} }
else { else {
$mysqlcmd = `which mysql`; $mysqlcmd = which("mysql", $PATH);
} }
chomp($mysqlcmd); chomp($mysqlcmd);
if ( !-e $mysqlcmd && $opt{mysqlcmd} ) { if ( !-e $mysqlcmd && $opt{mysqlcmd} ) {
@ -705,7 +701,7 @@ sub mysql_setup {
exit 1; exit 1;
} }
} }
my $svcprop = `which svcprop 2>/dev/null`; my $svcprop = which("svcprop", $PATH);
if ( substr( $svcprop, 0, 1 ) =~ "/" ) { if ( substr( $svcprop, 0, 1 ) =~ "/" ) {
# We are on solaris # We are on solaris
@ -1287,8 +1283,14 @@ sub get_system_info() {
infoprint "Internal IP : " . infocmd_one "hostname -I"; infoprint "Internal IP : " . infocmd_one "hostname -I";
my $httpcli=get_http_cli(); my $httpcli=get_http_cli();
infoprint "HTTP client found: $httpcli" if defined $httpcli; infoprint "HTTP client found: $httpcli" if defined $httpcli;
infoprint "External IP : " if ( $httpcli =~ /curl$/) {
. infocmd_one "$httpcli ipecho.net/plain" if defined ($httpcli); infoprint "External IP : "
. infocmd_one "$httpcli ipecho.net/plain";
}
elsif ( $httpcli =~ /wget$/ ) {
infoprint "External IP : "
. infocmd_one "$httpcli -q -O - ipecho.net/plain";
}
badprint badprint
"External IP : Can't check because of Internet connectivity" unless defined($httpcli); "External IP : Can't check because of Internet connectivity" unless defined($httpcli);
infoprint "Name Servers : " infoprint "Name Servers : "
@ -3903,6 +3905,21 @@ sub dump_result {
} }
} }
sub which {
my $prog_name = shift;
my $path_string = shift;
my @path_array = split /:/, $PATH;
for my $path ( @path_array) {
if ( -x "$path/$prog_name" ) {
return "$path/$prog_name";
}
}
return 0
}
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# BEGIN 'MAIN' # BEGIN 'MAIN'
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------