Debian Codegraph @

bin/make_sandbox_from_installed

raw ◀ ▶
1 Debian patch touch this file
1 #!/usr/bin/perl
2 # make_sandbox_from_installed
3 # The MySQL Sandbox
4 # Copyright (C) 2006-2018 Giuseppe Maxia
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 use strict;
19 use warnings;
20 use MySQL::Sandbox qw(runs_as_root);
21
22 runs_as_root();
23
24 my $new_version = shift
25 or die "version needed\n";
26 if ($new_version =~ /^(-h|--help)$/) {
27 print MySQL::Sandbox::credits();
28 print<<END_HELP;
29
30 This script tries to create a sandbox using already installed binaries.
31 Since these binaries can be in several different places, the script
32 creates a container with symbolic links, where the binaries
33 (their links, actually) are arranged as MySQL Sandbox expects them to be.
34
35 To use this version, change directory to a place where you want to
36 store this symbolic links container, and invoke
37
38 make_sandbox_from_installed X.X.XX [options]
39
40 where X.X.XX is the version number.
41 You can then pass any options accepted by make_sandbox.
42 END_HELP
43
44 exit(1);
45
46 }
47
48 $new_version =~ /^\d+\.\d+\.\d+$/
49 or die "invalid version format (required #.#.##)\n";
50
51 my $current_dir = $ENV{PWD};
52
53 if ( -d $new_version) {
54 die "directory $new_version already exists. Choose another name or location\n"
55 }
56
57 my @binaries = (
58 {files => 'my*', from => 'bin/', to => 'bin'},
59 {files => 'resolveip', from => 'bin/', to => 'bin'},
60 {files => 'mysql_install_db', from => 'scripts/', to => 'bin', optional => 1},
61 {files => 'mysql*', from => 'lib64/', to => 'lib', optional => 1},
62 {files => 'mysql*', from => 'lib/', to => 'lib', optional => 1},
63 {files => 'mysql*', from => 'libexec/', to => 'bin', optional =>1},
64 {files => 'mysql*', from => 'sbin/', to => 'bin', optional =>1},
65 {files => 'mysql/', from => 'share/', to => 'share', optional =>1},
66 );
67
68 my @commands;
69 my @prefixes = (
70 '/usr',
71 '/usr/local',
72 '/usr/local/mysql',
73 );
74
75 my $found_mysqld = 0;
76 my $found_install_db = 0;
77 my $found_libraries = 0;
78
79 for my $prefix (@prefixes) {
80 if (
81 (-x "$prefix/bin/mysqld")
82 or (-x "$prefix/libexec/mysqld")
83 or (-x "$prefix/sbin/mysqld")
84 )
85 {
86 $found_mysqld =1;
87 }
88 if (
89 (-x "$prefix/bin/mysql_install_db")
90 or (-x "$prefix/scripts/mysql_install_db")
91 )
92 {
93 $found_install_db =1;
94 }
95 if ( glob("$prefix/lib/mysql/libmysqlclient*")
96 or glob( "$prefix/lib/libmysqlclient*")
•97 or glob( "$prefix/lib/*/libmysqlclient*")
98 or glob( "$prefix/lib64/libmysqlclient*") ) {
99 $found_libraries =1;
100 }
101 }
102
103 unless ($found_mysqld) {
104 die "can't find mysqld in (@prefixes)\n";
105 }
106 unless ($found_install_db) {
107 die "can't find mysql_install_db in (@prefixes)\n";
108 }
109 unless ($found_libraries) {
110 die "can't find mysql libraries in (@prefixes)\n";
111 }
112
113 for my $bin ( @binaries ) {
114 my $found_prefix = undef;
115 for my $prefix (@prefixes) {
116 if ($bin->{files} =~ /\*/ ) {
117 my @files = glob("$prefix/$bin->{from}/$bin->{files}");
118 if (@files) {
119 $found_prefix = $prefix;
120 last;
121 }
122 }
123 else {
124 if ( -e "$prefix/$bin->{from}/$bin->{files}") {
125 $found_prefix = $prefix;
126 last;
127 }
128 }
129 }
130 unless ( $found_prefix) {
131 if ($bin->{optional}) {
132 next;
133 }
134 die "can't find $bin->{from}/$bin->{files} under (@prefixes) \n";
135 }
136 push @commands, sprintf("ln -s %s/%s/%s %s/%s/%s",
137 $found_prefix,
138 $bin->{from},
139 $bin->{files},
140 $current_dir,
141 $new_version,
142 $bin->{to}
143 );
144 }
145
146 unless (grep { /share/ } @commands) {
147 if ( -d "/usr/local/mysql/share" ) {
148 push @commands, "ln -s /usr/local/mysql/share/* $current_dir/$new_version/share";
149 }
150 }
151
152 #use Data::Dumper;
153 #print Dumper \@commands;
154 #exit;
155 mkdir $new_version
156 or die "can't create $new_version ($!)\n";
157
158 chdir $new_version;
159 for my $dir (qw(bin lib share)) {
160 mkdir $dir
161 or die "can't create $new_version/$dir\n";
162 }
163
164 for my $command (@commands) {
165 system $command;
166 if ($?) {
167 die "error creating symbolic link ($command) \n";
168 }
169 }
170
171 $ENV{SANDBOX_BINARY} = $current_dir;
172 system "make_sandbox $new_version -- @ARGV";