-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_mysql_pkg.pl
445 lines (302 loc) · 10.5 KB
/
make_mysql_pkg.pl
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
#!/usr/bin/perl -w
#
#
# make_mysql_pkg.pl
#
# This script creates a Mac OS X installation package
# of MySQL for Apple's Installer application.
#
# To use it:
#
# 1.) Unpack the mysql source tarball and cd into the directory
# 2.) execute this script
#
#
# Written by Marc Liyanage (http://www.entropy.ch)
# Updated by Colin Charles (http://bytebot.net/)
#
# History:
#
# When Who What
# ------------------------------------------------------------------
# 2001-09-16 Marc Liyanage First version
# 2001-11-18 Marc Liyanage Improved configure directory options
# 2010-03-04 Colin Charles Make it ready for MariaDB
use strict;
use DirHandle;
my $data = {};
$data->{PREFIX_DIR} = "/usr/local/mysql";
$data->{CONFIG} = join(" ",
"--prefix=$data->{PREFIX_DIR}",
"--localstatedir=$data->{PREFIX_DIR}/data",
"--libdir=$data->{PREFIX_DIR}/lib",
"--includedir=$data->{PREFIX_DIR}/include",
"--with-named-z-libs=/usr/local/libz.a",
"--with-innodb",
"--with-server-suffix='-mariadb'",
"--with-comment='http://www.mariadb.com/download'",
"--with-mysqld-user=mysql",
"--enable-assembler",
"CFLAGS=\"-DHAVE_BROKEN_REALPATH -lncurses\"",
);
prepare($data);
configure_source($data);
make($data);
make_binary_distribution($data);
create_pax_root($data);
create_package($data);
cleanup($data);
print "Package $data->{PACKAGE_TARBALL_FILENAME} created\n";
# Subroutines follow here...
# Prepares data in the global $data hash, like version numbers,
# directory names etc. Also makes sure that no old stuff
# is in our way.
#
sub prepare {
my ($data) = @_;
# Keep the current wd for reference
#
$data->{OLDWD} = `pwd`;
chomp($data->{OLDWD});
# Look for configure script
#
unless (-f "configure") {
abort($data, "Unable to find 'configure', make sure you're in the MySQL source toplevel directory!");
}
# Try to find version number there
#
my $mysql_version_h = `cat configure`;
($data->{VERSION}) = $mysql_version_h =~ /^VERSION=(.+?)$/m;
unless ($data->{VERSION} =~ /\d+/) {
abort($data, "Unable to find MySQL version number!");
}
debug($data, "found MySQL version number $data->{VERSION}");
# PAXROOT_DIR is where we will build our own little
# fake /usr/local directory. Make sure it doesn't exist,
# then try to create it.
#
$data->{PAXROOT_DIR} = "/tmp/mysql-$data->{VERSION}-paxroot";
if (-e $data->{PAXROOT_DIR}) {
abort($data, "$data->{PAXROOT_DIR} exists, please remove first");
}
if (system("mkdir $data->{PAXROOT_DIR}")) {
abort($data, "Unable to mkdir $data->{PAXROOT_DIR}, please make sure you have the right permissions!");
}
# PACKAGE_DIR is where we will build the package directory
# hierarchy, according to the standard .pkg layout.
#
$data->{PACKAGE_NAME} = "mysql-$data->{VERSION}.pkg";
$data->{PACKAGE_DIR} = "/tmp/$data->{PACKAGE_NAME}";
if (-e $data->{PACKAGE_DIR}) {
abort($data, "$data->{PACKAGE_DIR} exists, please remove first");
}
if (system("mkdir $data->{PACKAGE_DIR}")) {
abort($data, "Unable to mkdir $data->{PACKAGE_DIR}, please make sure you have the right permissions!");
}
}
# Configure the MySQL source with our options
#
sub configure_source {
my ($data) = @_;
if (system("./configure $data->{CONFIG}")) {
abort($data, "Unable to configure!");
}
}
# Build the software
#
sub make {
my ($data) = @_;
if (system("make")) {
abort($data, "Unable to make!");
}
}
# We don't ever install the software, but instead we use an
# included script to create a binary distribution
# tarball.
#
sub make_binary_distribution {
my ($data) = @_;
if (system("./scripts/make_binary_distribution > make_binary_distribution.out")) {
abort($data, "Unable to make_binary_distribution!");
}
my @output = `cat make_binary_distribution.out`;
my $last_line = $output[-1];
unlink("make_binary_distribution.out");
my ($tarball_filename, $tarball_directory) = $last_line =~ /^((.+)\.tar\.gz) created/i;
unless ($tarball_filename and -f $tarball_filename) {
abort($data, "Unable determine the output filename of scripts/make_binary_distribution!");
}
$data->{BINARY_TARBALL_FILENAME} = $tarball_filename;
$data->{BINARY_TARBALL_DIRECTORY} = $tarball_directory;
}
# Now we build a fake /usr/local directory hierarchy.
# This will be fed to the pax tool to create the archive.
#
sub create_pax_root {
my ($data) = @_;
# Go there and try to extract the binary distribution
# tarball which we created in the previous step.
#
chdir($data->{PAXROOT_DIR});
my $tarfile = "$data->{OLDWD}/$data->{BINARY_TARBALL_FILENAME}";
if (system("tar -xzf $tarfile")) {
abort($data, "Unable to extract $tarfile inside $data->{PAXROOT_DIR}");
}
# Rename it to what we want it to be in the
# installed /usr/local directory later on, i.e.
# mysql-<version>. Then create a symlink from
# mysql to mysql-<version>
#
rename($data->{BINARY_TARBALL_DIRECTORY}, "mysql-$data->{VERSION}");
symlink("mysql-$data->{VERSION}", "mysql");
# We create a bunch of symlinks in /usr/local/bin and
# /usr/local/share/man so that the end-user will not
# have to adjust PATH and MANPATH to include the
# /usr/local/mysql/bin and man directories.
#
system("mkdir -p $_") foreach qw(bin share/man);
# First create the symlinks in the bin directory
#
# 2001-02-13: we no longer use symlinks for the binaries, we
# use small dummy scripts instead because the
# mysql scripts do a lot of guesswork with their
# own path and that will not work when called via the symlink
#
# symlink("../mysql/bin/$_", "$_") foreach (grep {$_ !~ /^\.+$/} DirHandle->new("../mysql/bin")->read());
chdir("bin");
foreach my $command (grep {$_ !~ /^\.+$/} DirHandle->new("../mysql/bin")->read()) {
my $scriptcode = qq+#!/bin/sh\n# Part of the entropy.ch mysql package\ncd /usr/local/mysql/\nexec ./bin/$command "\$\@"\n+;
open(SCRIPTFILE, ">$command") or die "Unable to write open $command\n";
print SCRIPTFILE $scriptcode;
close(SCRIPTFILE);
chmod(0755, $command);
}
# Now include the man pages. Two problems here:
# 1.) the make_binary_distribution script does not seem
# to include the man pages, so we have to copy them over
# now. [outdated, was fixed by MySQL!]
# 2.) The man pages could be in different sections, so
# we have to recursively copy *and* symlink them.
#
# First find out what's there in the source distribution.
# Store the names of the manpages in anonymous
# arrays which in turn will be stored in a hash, using
# the section numbers as hash keys.
#
chdir("$data->{PAXROOT_DIR}/mysql");
my %man_sections;
foreach my $manpage (grep {$_ =~ /^.+\.(\d+)$/} DirHandle->new("man")->read()) {
my ($section) = $manpage =~ /\.(\d+)$/;
$man_sections{$section} ||= [];
push @{$man_sections{$section}}, "$manpage";
}
# Now iterate through the sections and man pages,
# and copy/symlink the man pages
#
chdir("$data->{PAXROOT_DIR}/share/man/");
foreach my $section (keys(%man_sections)) {
system("mkdir -p man$section");
chdir("man$section");
foreach my $manpage (@{$man_sections{$section}}) {
symlink("../../../mysql/man/$manpage", $manpage)
}
chdir("..");
}
}
# Take the pax root directory, create a few auxiliary
# files and then pack everything up into a tarball
#
sub create_package {
my ($data) = @_;
# Create the resources directory in which all
# interesting files for this package will be stored
#
$data->{PKG_RESOURCES_DIR} = "$data->{PACKAGE_DIR}/Contents/Resources";
if (system("mkdir -p $data->{PKG_RESOURCES_DIR}")) {
abort("Unable to create package resources dir $data->{PKG_RESOURCES_DIR}");
}
# Create the big archive with all the files using
# the pax tool
#
chdir($data->{PAXROOT_DIR});
if(system("pax -w . | gzip -c > $data->{PKG_RESOURCES_DIR}/mysql-$data->{VERSION}.pax.gz")) {
abort("Unable to create package pax file");
}
# Create the "Bill Of Materials" (bom) file.
#
if(system("mkbom . $data->{PKG_RESOURCES_DIR}/mysql-$data->{VERSION}.bom")) {
abort("Unable to create package bom file");
}
# Create the ".sizes" file with some information about the package
#
my $size_uncompressed = `du -sk $data->{PAXROOT_DIR} | cut -f 1`;
chomp($size_uncompressed);
my $size_compressed = `du -sk $data->{PACKAGE_DIR} | cut -f 1`;
chomp($size_compressed);
my $numfiles = `find /tmp/mysql-$data->{VERSION}-paxroot | wc -l`;
$numfiles--;
open(SIZESFILE, ">$data->{PKG_RESOURCES_DIR}/mysql-$data->{VERSION}.sizes") or abort("Unable to write open sizes file $data->{PKG_RESOURCES_DIR}/mysql-$data->{VERSION}.sizes");
print SIZESFILE "NumFiles $numfiles\n";
print SIZESFILE "InstalledSize $size_uncompressed\n";
print SIZESFILE "CompressedSize $size_compressed\n";
close(SIZESFILE);
# Create the ".info" file with more information abou the package.
#
open(INFOFILE, ">$data->{PKG_RESOURCES_DIR}/mysql-$data->{VERSION}.info") or abort("Unable to write open sizes file $data->{PKG_RESOURCES_DIR}/mysql-$data->{VERSION}.info");
my $infodata = join("", <DATA>);
$infodata =~ s/<%(.+?)%>/$data->{$1}/eg;
abort("Unable to get info file data from __DATA__!") unless ($infodata =~ /\w+/);
print INFOFILE $infodata;
close(INFOFILE);
# Finally, create the .tar.gz file for the package,
# this is our end result
#
chdir($data->{PACKAGE_DIR});
chdir("..");
$data->{PACKAGE_TARBALL_FILENAME} = "$data->{PACKAGE_NAME}.tar.gz";
if(system("tar -czf $data->{OLDWD}/$data->{PACKAGE_TARBALL_FILENAME} $data->{PACKAGE_NAME}")) {
abort("Unable to create package tar file $data->{OLDWD}/$data->{PACKAGE_TARBALL_FILENAME}");
}
}
# Abort with an error message
#
sub abort {
my ($data, $errormessage) = @_;
my ($caller) = (caller(1))[3];
$caller =~ s/^main:://;
print "*** Error: $caller(): $errormessage\n";
exit 1;
}
# Output informative messages
#
sub debug {
my ($data, $message) = @_;
my ($caller) = (caller(1))[3];
$caller =~ s/^main:://;
print "*** Info: $caller(): $message\n";
}
# Remove temporary items
#
sub cleanup {
my ($data) = @_;
chdir($data->{OLDWD});
system("rm -rf $data->{PACKAGE_DIR}");
system("rm -rf $data->{PAXROOT_DIR}");
system("rm $data->{BINARY_TARBALL_FILENAME}");
}
__DATA__
Title MariaDB
Version <%VERSION%>
Description The MariaDB database is a new branch of the MySQL database which includes all major open source storage engines, myriad bug fixes, and many community patches. Find out more at http://www.mariadb.com/.
DefaultLocation /usr/local
Diskname (null)
DeleteWarning
NeedsAuthorization YES
DisableStop NO
UseUserMask NO
Application NO
Relocatable NO
Required NO
InstallOnly NO
RequiresReboot NO
InstallFat NO