Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Added make_sandbox_from_url: sandbox from web
Browse files Browse the repository at this point in the history
usage:
     make_sandbox_from_url 5.7
     or
     make_sandbox_from_url {5.6 | 5.5 | 5.1 | 5.0 }

- Fixed a warning about negative length of options (only fires in recent versions of Perl)
- Cleaned up test execution for environments where it can't run properly.
  • Loading branch information
datacharmer committed Jul 10, 2016
1 parent 2405cf1 commit 68e6a97
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
3.1.09 08-Jul-2016
- Added make_sandbox_from_url, which installs a sandbox from the web
- Fixed a warning about negative length of options (only fires in recent
versions of Perl)
- Cleaned up test execution for environments where it can't run properly.
3.1.08 04-Jun-2016
- Fixed major issue with XPlugin installation. The grants script was
removing the account created by the X-plugin. Now this account is
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bin/make_replication_sandbox
bin/make_sandbox
bin/make_sandbox_from_installed
bin/make_sandbox_from_source
bin/make_sandbox_from_url
bin/msandbox
bin/msb
bin/sbtool
Expand Down
170 changes: 170 additions & 0 deletions bin/make_sandbox_from_url
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#!/usr/bin/perl
# make_sandbox_from_installed
# The MySQL Sandbox
# Copyright (C) 2006-2016 Giuseppe Maxia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

use strict;
use warnings;
use MySQL::Sandbox qw(runs_as_root exists_in_path greater_version);
my $repository=$ENV{SANDBOX_REPO} || 'http://github.com/datacharmer/mysql-docker-minimal/blob/master/dbdata';
my $sandbox_binary=$ENV{SANDBOX_BINARY} || "$ENV{HOME}/opt/mysql";
my $pound_line = '#' x 80;
my %supported_versions =
(
'5.0' => ['5.0.96'],
'5.1' => ['5.1.72'],
'5.5' => ['5.5.50'],
'5.6' => ['5.6.31'],
'5.7' => ['5.7.13']
);


runs_as_root();
# ---------------------------------------------------------------------------------
# main
# ---------------------------------------------------------------------------------

my $remote_version = shift
or get_help("version needed");
if (exists $supported_versions{$remote_version})
{
$remote_version = get_latest($remote_version);
}
if ($remote_version =~ /^(-h|--help)$/)
{
get_help();
}
unless ($^O =~ /linux/i)
{
get_help("This operating system ($^O) is not supported");
}



my $download_file="$repository/$remote_version.tar.gz";

my $wget = exists_in_path ('wget');
unless ($wget )
{
get_help( 'wget was not found in PATH' );
}

if ( ! -d $sandbox_binary )
{
system "mkdir -p $sandbox_binary";
if ($?)
{
die "Can't create $sandbox_binary ($!)\n";
}
}

if ( ! -d $sandbox_binary )
{
get_help("Unable to use or create $sandbox_binary")
}

chdir $sandbox_binary;

if ( -d $remote_version)
{
get_help( "\n$pound_line\n"
. "### Version $remote_version already exists in $sandbox_binary\n"
. "### Run 'make_sandbox $remote_version' to use it\n"
. $pound_line
);
}

my $local_file = "$remote_version.tar.gz";
print "wget -O $local_file '$download_file?raw=true' \n";
system "wget -O $local_file '$download_file?raw=true' ";
if ($?)
{
die "Error downloading $download_file\n";
}

if ( ! -f $local_file)
{
die "Error downloading $download_file. Can't find '$local_file'\n";
}

system "tar -xzf $local_file";
if ($?)
{
die "Error extracting from $local_file\n";
}

if ( ! -d $remote_version)
{
die "Directory $remote_version was not created\n";
}

$ENV{SANDBOX_BINARY} = $sandbox_binary;
$ENV{PWD} = $sandbox_binary;

exec "make_sandbox $remote_version @ARGV";

# ---------------------------------------------------------------------------------
# Functions
# ---------------------------------------------------------------------------------
sub get_help
{
my ($msg) = @_;

print MySQL::Sandbox::credits();
if ($msg)
{
print "### $msg\n";
}
print<<END_HELP1;
This script tries to create a sandbox using binaries downloaded from the web.
The success of this scripts depends on good connectivity
and availability of downloading tools.
##########################
# IT ONLY WORKS ON LINUX
##########################
The repository of available binarie is at $repository .
Supported:
END_HELP1

for my $major (sort keys %supported_versions )
{
print "# $major -> [ @{ [ @{$supported_versions{$major}} ]} ] \n";
}

print<<END_HELP2;
The binaries are imported into $sandbox_binary .
make_sandbox_from_url X.X.XX [options]
where X.X.XX is the version number.
You can then pass any options accepted by make_sandbox.
END_HELP2

if ($msg)
{
exit 1;
}
else
{
exit 0;
}
}
sub get_latest
{
my ($wanted) = @_;
my @versions = @{ $supported_versions{$wanted}};
return $versions[-1];
}
11 changes: 8 additions & 3 deletions lib/MySQL/Sandbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ our @EXPORT_OK= qw( is_port_open
split_version
) ;

our $VERSION=q{3.1.08};
our $VERSION=q{3.1.09};
our $DEBUG;

BEGIN {
Expand Down Expand Up @@ -164,7 +164,12 @@ sub get_help {
$long =~ s/ = s \@? / = name/x;
$long =~ s/ = i / = number/x;
$param_str .= q{--} . $long;
$param_str .= (q{ } x (40 - length($param_str)) );
my $lparam = 40 - length($param_str);
if ($lparam < 0)
{
$lparam = 0;
}
$param_str .= (q{ } x $lparam );
my $text_items = $self->{parse_options}->{$op}{help};
for my $titem (@{$text_items}) {
$HELP_MSG .= $param_str . $titem . "\n";
Expand Down Expand Up @@ -712,7 +717,7 @@ sub exists_in_path {
my @path_directories = split /:/, $ENV{PATH}; ## no critic
for my $dir (@path_directories) {
if ( -x "$dir/$cmd") {
return 1;
return "$dir/$cmd";
}
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/MySQL/Sandbox/Recipes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package MySQL::Sandbox::Recipes;
use strict;
use warnings;

our $VERSION=q{3.1.08};
our $VERSION=q{3.1.09};

1;
__END__
Expand Down
2 changes: 1 addition & 1 deletion lib/MySQL/Sandbox/Scripts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ our @EXPORT_OK = qw(
);
our @EXPORT = @EXPORT_OK;

our $VERSION=q{3.1.08};
our $VERSION=q{3.1.09};

our @MANIFEST = (
'clear.sh',
Expand Down
2 changes: 1 addition & 1 deletion t/02_test_binaries.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BEGIN {
use strict;
use warnings;
use lib './t';
use Test_Helper;
#use Test_Helper;
use Test::More;

BEGIN {
Expand Down
5 changes: 5 additions & 0 deletions t/Test_Helper.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ BEGIN {
if ($^O =~ /^(?:mswin|win)/i) {
skip_all ('This module is not for Windows');
}
my $opt_mysql= $ENV{SANDBOX_BINARY} || "$ENV{HOME}/opt/mysql";
unless ( -d -d $opt_mysql)
{
skip_all ("This test module requires tarballs extracted in $ENV{HOME}/opt/bin");
}
use MySQL::Sandbox qw/split_version/;
$ENV{TEST_SANDBOX_HOME}="$ENV{PWD}/t/test_sb";
$ENV{PERL5LIB}="$ENV{PWD}/lib";
Expand Down

0 comments on commit 68e6a97

Please sign in to comment.