Adding version check features

Issue #33 #95: checkversion option is now available
This commit is contained in:
Jean-Marie RENOUARD 2015-08-25 16:15:54 +02:00
parent 504aee51a6
commit 2d02c583e3

View file

@ -1,5 +1,5 @@
#!/usr/bin/env perl #!/usr/bin/env perl
# mysqltuner.pl - Version 1.5.1 # mysqltuner.pl - Version 1.5.2
# High Performance MySQL Tuning Script # High Performance MySQL Tuning Script
# Copyright (C) 2006-2015 Major Hayden - major@mhtx.net # Copyright (C) 2006-2015 Major Hayden - major@mhtx.net
# #
@ -45,7 +45,7 @@ use Cwd 'abs_path';
use Data::Dumper qw/Dumper/; use Data::Dumper qw/Dumper/;
# Set up a few variables for use in the script # Set up a few variables for use in the script
my $tunerversion = "1.5.1"; my $tunerversion = "1.5.2";
my ( @adjvars, @generalrec ); my ( @adjvars, @generalrec );
# Set defaults # Set defaults
@ -347,6 +347,58 @@ sub os_setup {
} }
# Checks for updates to MySQLTuner
sub validate_tuner_version {
if ($opt{checkversion} eq 0) {
infoprint "Skipped version check for MySQLTuner script\n";
return;
}
my $update;
my $url = "https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl";
my $httpcli=`which curl`;
chomp($httpcli);
if ( 1 != 1 and defined($httpcli) and -e "$httpcli" ) {
debugprint "$httpcli is available.";
debugprint "$httpcli --connect-timeout 5 -silent '$url' 2>/dev/null | grep 'my \$tunerversion'| cut -d\\\" -f2";
$update = `$httpcli --connect-timeout 5 -silent '$url' 2>/dev/null | grep 'my \$tunerversion'| cut -d\\\" -f2`;
chomp($update);
debugprint "VERSION: $update";
compare_tuner_version($update);
return;
}
$httpcli=`which wget`;
chomp($httpcli);
if ( defined($httpcli) and -e "$httpcli" ) {
debugprint "$httpcli is available.";
debugprint "$httpcli -e timestamping=off -T 5 -O - '$url' 2>$devnull| grep 'my \$tunerversion'| cut -d\\\" -f2";
$update = `$httpcli -e timestamping=off -T 5 -O - '$url' 2>$devnull| grep 'my \$tunerversion'| cut -d\\\" -f2`;
chomp($update);
compare_tuner_version($update);
return;
}
debugprint "curl and wget are not avalaible.";
infoprint "Unable to check for the latest MySQLTuner version";
}
sub compare_tuner_version {
my $remoteversion=shift;
debugprint "Remote data: $remoteversion";
#exit 0;
if ($remoteversion ne $tunerversion) {
badprint "There is a new version of MySQLTuner available ($remoteversion)";
return;
}
goodprint "You have the latest version of MySQLTuner($tunerversion)";
return;
}
# Checks to see if a MySQL login is possible # Checks to see if a MySQL login is possible
my ( $mysqllogin, $doremote, $remotestring, $mysqlcmd, $mysqladmincmd ); my ( $mysqllogin, $doremote, $remotestring, $mysqlcmd, $mysqladmincmd );
@ -2671,7 +2723,8 @@ sub dump_result {
# BEGIN 'MAIN' # BEGIN 'MAIN'
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
headerprint # Header Print headerprint # Header Print
mysql_setup; # Gotta login first validate_tuner_version; # Check last version
mysql_setup; # Gotta login first
os_setup; # Set up some OS variables os_setup; # Set up some OS variables
get_all_vars; # Toss variables/status into hashes get_all_vars; # Toss variables/status into hashes
get_tuning_info; # Get information about the tuning connexion get_tuning_info; # Get information about the tuning connexion
@ -2702,7 +2755,7 @@ __END__
=head1 NAME =head1 NAME
MySQLTuner 1.5.1 - MySQL High Performance Tuning Script MySQLTuner 1.5.2 - MySQL High Performance Tuning Script
=head1 IMPORTANT USAGE GUIDELINES =head1 IMPORTANT USAGE GUIDELINES