This file is indexed.

/usr/bin/make_sandbox_from_source is in mysql-sandbox 3.1.04-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/perl
# make_sandbox_from_source
#    The MySQL Sandbox
#    Copyright (C) 2006-2015 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);

runs_as_root();

my $msb = MySQL::Sandbox->new();

my $source_directory = shift
    or get_help('source directory missing');

my $sandbox_type = shift
    or get_help('sandbox_type missing');

my %sandbox_apps = (
    single      => 'make_sandbox',
    replication => 'make_replication_sandbox',
    circular    => 'make_replication_sandbox',
    multiple    => 'make_multiple_sandbox',
);

unless ( -d $source_directory) {
    die "<$source_directory> is not a directory\n";
}

$source_directory =~ s{/$}{};

unless ( -x "$source_directory/scripts/make_binary_distribution") {
    die "can't find executable script 'make_binary_distribution'\n";
}

unless ( -x "$source_directory/sql/mysqld") {
    die "Can't find executable mysqld. Sources don't seem to have been compiled.\n";
}

unless ($sandbox_apps{$sandbox_type}) {
    get_help("unsupported sandbox type ($sandbox_type)");
}

chdir $source_directory 
    or die "can't change path to <$source_directory>\n";

my $source_version = get_source_version();

my $old_tarball = last_tarball();

my $new_tarball;

if ( $old_tarball ) {
    my @tgz = file_age($old_tarball);
    my @mysqld = file_age("./sql/mysqld");    
    my @dir = file_age($source_version) ;
    unless (@dir) {
        @dir = ('---', 0);
    }
    if (($mysqld[1] > $tgz[1]) or ($mysqld[1] > $dir[1])) {
        print " new build. The tarball needs to be redone\n";
        $new_tarball = build_tarball();        
        # removing the directory
        if ( -d $source_version ) {
            remove_source_dir($source_version);
        }
    }
    elsif ($tgz[1] > $dir[1])  {
        print "tarball newer than the version directory\n";
        # removing the directory
        if ( ( -d $source_version) && (( $tgz[1] - $dir[1] ) > 60 )) {
            remove_source_dir($source_version);
        }
        $new_tarball = $old_tarball;
    }
    elsif ( $dir[1] >= $tgz[1] ) {
        print "tarball older than directory\n";
        # Nothing to be done
        $new_tarball = $source_version;
    }
    else {
        print "dir @dir\n";
        print "mysqld @mysqld\n";
        print "tgz @tgz\n";
        die "unhandled \n";
    }
}
else {
    print "no old tarball found\n";
    $new_tarball = build_tarball();
}


my $options = '';
if ( $sandbox_type eq 'circular') {
    $options = '--topology=circular';
}

system "$sandbox_apps{$sandbox_type} $source_directory/$new_tarball $options  @ARGV"; 

#
#  functions
#

sub build_tarball {
    my $result = system "./scripts/make_binary_distribution";

    if ($result or $? ) {
        die "error creating binary tarball. ($result - $? - $! )";
    }

    my $tarball = last_tarball()
        or die "can't find a tarball\n";
    return $tarball;
}

sub get_source_version {
    #
    # Parses 'Makefile' for server version.
    #
    # 'Makefile' exists only after the server is compiled
    # but this is just as well in our case, since we only
    # need to run this script after the server is fully built.
    # This method should be more robust than parsing 
    # configure.in
    #

    my $version;
    if ( -f 'VERSION' )
    {
        open my $VFH, q{<}, 'VERSION'
            or die "can't open VERSION\n";
        while (my $line = <$VFH>)
        {
            if ($line =~ /MYSQL_VERSION_(?:MAJOR|MINOR|PATCH)=(\d+)/)
            {
                if (defined $version)
                {
                    $version .= '.';
                }
                else
                {
                    $version = '';
                }
                $version .= $1;
            }
        }
        unless ($version =~ /\d+\.\d+\.\d+/)
        {
            die "could not find a version number in VERSION ($version)\n";
        }
        return $version;
    }
    else
    {
        print "# There is no VERSION file in this directory.\n# Now trying with Makefile\n" if $MySQL::Sandbox::DEBUG;
    }


    open my $MAKEFILE, q{<}, 'Makefile'
        or die "can't find Makefile\n";
    while (my $line = <$MAKEFILE>) {
        if ($line =~ /
               ^                      # start of line
               \s*                    # optional whitespace
               MYSQL_NO_DASH_VERSION  # literal 
               \s*                    # optional whitespace
               =                      # equals sign
               \s*                    # optional whitespace
               (\d\.\d.\d+)           # capture the version
               \s*                    # optional whitespace
               $                      # end of line
               /x) {
            $version = $1;
            last;
        }
    }
    close $MAKEFILE;
    if ($version) {
        return $version;
    }
    else {
        die "can't find a version in Makefile\n";
    }
}


#sub get_source_version {
#    open my $CONFIG, q{<}, 'configure.in'
#        or die "can't find configure.in\n";
#    my $version;
#    while (my $line = <$CONFIG>) {
#        if ($line =~ /
#                    (?:AM_INIT_AUTOMAKE
#                    |
#                    AC_INIT)        # either of these macros
#                    \D+             # followed by one or more non digit
#                    (?:(?i)mysql)   # followed by "mysql" in any case
#                    \D+             # followed by one or more non digit
#                    (\d\.\d.\d+)    # capture the version
#                    /x) {
#            $version = $1;
#            last;
#        }
#    }
#    close $CONFIG;
#    if ($version) {
#        return $version;
#    }
#    else {
#        die "can't find a version in configure.in\n";
#    }
#}

sub last_tarball {
    my %files = map {file_age($_)} 
        grep {$_ !~  /^mysql-\d\.\d\.\d+\.tar\.gz$/}  
            glob("*.tar.gz");
    return unless keys %files;
    return (sort { $files{$b} <=> $files{$a} } keys %files)[0];
}

sub file_age {
    my ($filename) = @_; 
    return unless -e $filename;
    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
        $atime,$mtime,$ctime,$blksize,$blocks) = stat($filename);
    return ($filename, $atime);
}


sub get_help{
    my ($msg) = @_;
    print $msb->credits(), "\n";
    if ($msg) {
        print "*** $msg\n";
    }
    print <<END_HELP;
Syntax: $0 source_directory sandbox_type [options]

    source directory is where you have successfully
        run ./configure && make

    sandbox_type is one of 
        single
        replication
        circular
        multiple

    options is anything that is needed by the sandbox
        application of your choice

END_HELP
exit 1;
}

sub remove_source_dir {
    my ($dir) = @_;
    system ("rm -rf $dir"); 
}

__END__