Debian Codegraph @

bin/make_sandbox_from_installed

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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/lib64/libmysqlclient*")
98 or glob( "$prefix/lib/i386-linux-gnu/libmysqlclient*")
99 or glob( "$prefix/lib/x86_64-linux-gnu/libmysqlclient*") ) {
100 $found_libraries =1;
101 }
102 }
103
104 unless ($found_mysqld) {
105 die "can't find mysqld in (@prefixes)\n";
106 }
107 unless ($found_install_db) {
108 die "can't find mysql_install_db in (@prefixes)\n";
109 }
110 unless ($found_libraries) {
111 die "can't find mysql libraries in (@prefixes)\n";
112 }
113
114 for my $bin ( @binaries ) {
115 my $found_prefix = undef;
116 for my $prefix (@prefixes) {
117 if ($bin->{files} =~ /\*/ ) {
118 my @files = glob("$prefix/$bin->{from}/$bin->{files}");
119 if (@files) {
120 $found_prefix = $prefix;
121 last;
122 }
123 }
124 else {
125 if ( -e "$prefix/$bin->{from}/$bin->{files}") {
126 $found_prefix = $prefix;
127 last;
128 }
129 }
130 }
131 unless ( $found_prefix) {
132 if ($bin->{optional}) {
133 next;
134 }
135 die "can't find $bin->{from}/$bin->{files} under (@prefixes) \n";
136 }
137 push @commands, sprintf("ln -s %s/%s/%s %s/%s/%s",
138 $found_prefix,
139 $bin->{from},
140 $bin->{files},
141 $current_dir,
142 $new_version,
143 $bin->{to}
144 );
145 }
146
147 unless (grep { /share/ } @commands) {
148 if ( -d "/usr/local/mysql/share" ) {
149 push @commands, "ln -s /usr/local/mysql/share/* $current_dir/$new_version/share";
150 }
151 }
152
153 #use Data::Dumper;
154 #print Dumper \@commands;
155 #exit;
156 mkdir $new_version
157 or die "can't create $new_version ($!)\n";
158
159 chdir $new_version;
160 for my $dir (qw(bin lib share)) {
161 mkdir $dir
162 or die "can't create $new_version/$dir\n";
163 }
164
165 for my $command (@commands) {
166 system $command;
167 if ($?) {
168 die "error creating symbolic link ($command) \n";
169 }
170 }
171
172 $ENV{SANDBOX_BINARY} = $current_dir;
173 system "make_sandbox $new_version -- @ARGV";