diff --git a/scripts/mysql_install_db.pl.in b/scripts/mysql_install_db.pl.in index 440a977..7d068fc 100644 --- a/scripts/mysql_install_db.pl.in +++ b/scripts/mysql_install_db.pl.in @@ -34,13 +34,35 @@ # ############################################################################## -use Fcntl; -use File::Basename; -use File::Copy; -use Getopt::Long; -use Sys::Hostname; -use Data::Dumper; use strict; +use warnings; + +############################################################################## +# Check if all needed modules are available, exit if something is missing. +############################################################################## + +BEGIN { + my @req_mods = ('Fcntl', 'File::Basename', 'File::Copy', 'Getopt::Long', + 'Sys::Hostname', 'Data::Dumper'); + my @missing_mods; + my $req; + foreach $req (@req_mods) { + eval 'require ' . $req; + if ($@) { + push(@missing_mods, $req); + } else { + $req->import(); + } + } + # this avoids the confusing "BEGIN failed--compilation aborted" message + local $SIG{__DIE__} = sub {warn @_; exit 1}; + + if (@missing_mods) { + my $msg = "FATAL ERROR: please install the following Perl modules " . + "before executing $0:\n" . join("\n",@missing_mods)."\n"; + die $msg; + } +} Getopt::Long::Configure("pass_through"); @@ -75,6 +97,8 @@ Usage: $0 [OPTIONS] --help Display this help and exit. --ldata=path The path to the MySQL data directory. Same as --datadir. --no-defaults Don't read default options from any option file. + --keep-my-cnf Don't try to create my.cnf based on template. + Useful for systems with working, updated my.cnf. EOF1 if ( $^O !~ m/^(MSWin32|cygwin)$/ ) { print <{srcdir} and $opt->{basedir} ) { error($opt,"Specify either --basedir or --srcdir, not both"); } +if ( $opt->{rpm} || $opt->{'keep-my-cnf'} ) +{ + $keep_my_cnf = 1; +} if ( $opt->{srcdir} ) { $opt->{builddir} = $opt->{srcdir} unless $opt->{builddir}; @@ -425,13 +462,18 @@ my $config_file; my $copy_cfg_file; # ---------------------------------------------------------------------- -# This will be the default config file +# This will be the default config file (unless creation is unwanted) # ---------------------------------------------------------------------- $config_file= "$basedir/my.cnf"; my $cfg_template= find_in_basedir($opt,"file","my-default.cnf", "share","share/mysql","support-files"); +# Distros might move files +if ((! -r $cfg_template) && (-r "@pkgdatadir@/my-default.cnf")) { + $cfg_template = "@pkgdatadir@/my-default.cnf"; +} + -e $cfg_template or cannot_find_file("my-default.cnf"); $copy_cfg_file= $config_file; @@ -441,22 +483,21 @@ if (-e $copy_cfg_file) $copy_cfg_file =~ s/my.cnf/my-new.cnf/; # Too early to print warning here, the user may not notice } -open (TEMPL, $cfg_template) or error($opt, "Could not open config template $cfg_template"); -if (open (CFG, "> $copy_cfg_file")) -{ - while () - { - # Remove lines beginning with # *** which are template comments - print CFG $_ unless /^# \*\*\*/; + +if ( ! $keep_my_cnf ) { + open (TEMPL, $cfg_template) or error($opt, "Could not open config template $cfg_template"); + if (open (CFG, "> $copy_cfg_file")) { + while () { + # Remove lines beginning with # *** which are template comments + print CFG $_ unless /^# \*\*\*/; + } + close CFG; + } else { + warning($opt,"Could not write to config file $copy_cfg_file: $!"); + $failed_write_cfg= 1; } - close CFG; + close TEMPL; } -else -{ - warning($opt,"Could not write to config file $copy_cfg_file: $!"); - $failed_write_cfg= 1; -} -close TEMPL; # ---------------------------------------------------------------------- # Now we can get arguments from the groups [mysqld] and [mysql_install_db] @@ -619,7 +660,7 @@ if ( $opt->{'skip-name-resolve'} and $resolved and $resolved =~ /\s/ ) } # ---------------------------------------------------------------------- -# Create database directories mysql & test +# Create database directory mysql # ---------------------------------------------------------------------- # FIXME The shell variant uses "mkdir -p": @@ -652,7 +693,7 @@ if ($opt_user) } } -foreach my $dir ( $opt->{ldata}, "$opt->{ldata}/mysql", "$opt->{ldata}/test" ) +foreach my $dir ( $opt->{ldata}, "$opt->{ldata}/mysql") { mkdir($dir, 0700) unless -d $dir; if ($opt_user and -w "/") @@ -846,7 +887,13 @@ if ( open(PIPE, "| $mysqld_install_cmd_line") ) "", "Support MySQL by buying support/licenses at http://shop.mysql.com"); - if ($copy_cfg_file eq $config_file and !$failed_write_cfg) + if ($keep_my_cnf) + { + report($opt, + "Note: new default config file not created.", + "Please make sure your config file is current"); + } + elsif ($copy_cfg_file eq $config_file and !$failed_write_cfg) { report($opt, "New default config file was created as $config_file and",