Commit accd734f authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 361252: checksetup.pl should get confirmation from the user before causing…

Bug 361252: checksetup.pl should get confirmation from the user before causing dataloss in UTF8 conversion - Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit a=myk
parent 850da7d0
...@@ -327,6 +327,28 @@ sub usage_mode { ...@@ -327,6 +327,28 @@ sub usage_mode {
|| Bugzilla::Constants::USAGE_MODE_BROWSER; || Bugzilla::Constants::USAGE_MODE_BROWSER;
} }
sub installation_mode {
my ($class, $newval) = @_;
($class->request_cache->{installation_mode} = $newval) if defined $newval;
return $class->request_cache->{installation_mode}
|| INSTALLATION_MODE_INTERACTIVE;
}
sub installation_answers {
my ($class, $filename) = @_;
if ($filename) {
my $s = new Safe;
$s->rdo($filename);
die "Error reading $filename: $!" if $!;
die "Error evaluating $filename: $@" if $@;
# Now read the param back out from the sandbox
$class->request_cache->{installation_answers} = $s->varglob('answer');
}
return $class->request_cache->{installation_answers} || {};
}
sub switch_to_shadow_db { sub switch_to_shadow_db {
my $class = shift; my $class = shift;
...@@ -570,6 +592,16 @@ usage mode. ...@@ -570,6 +592,16 @@ usage mode.
C<Bugzilla->usage_mode> will return the current state of this flag. C<Bugzilla->usage_mode> will return the current state of this flag.
=item C<installation_mode>
Determines whether or not installation should be silent. See
L<Bugzilla::Constants> for the C<INSTALLATION_MODE> constants.
=item C<installation_answers>
Returns a hashref representing any "answers" file passed to F<checksetup.pl>,
used to automatically answer or skip prompts.
=item C<dbh> =item C<dbh>
The current database handle. See L<DBI>. The current database handle. See L<DBI>.
......
...@@ -100,7 +100,7 @@ sub SetParam { ...@@ -100,7 +100,7 @@ sub SetParam {
sub update_params { sub update_params {
my ($params) = @_; my ($params) = @_;
my $answer = $params->{answer} || {}; my $answer = Bugzilla->installation_answers;
my $param = read_param_file(); my $param = read_param_file();
......
...@@ -127,6 +127,9 @@ use File::Basename; ...@@ -127,6 +127,9 @@ use File::Basename;
ERROR_MODE_DIE ERROR_MODE_DIE
ERROR_MODE_DIE_SOAP_FAULT ERROR_MODE_DIE_SOAP_FAULT
INSTALLATION_MODE_INTERACTIVE
INSTALLATION_MODE_NON_INTERACTIVE
DB_MODULE DB_MODULE
ROOT_USER ROOT_USER
ON_WINDOWS ON_WINDOWS
...@@ -349,6 +352,10 @@ use constant ERROR_MODE_WEBPAGE => 0; ...@@ -349,6 +352,10 @@ use constant ERROR_MODE_WEBPAGE => 0;
use constant ERROR_MODE_DIE => 1; use constant ERROR_MODE_DIE => 1;
use constant ERROR_MODE_DIE_SOAP_FAULT => 2; use constant ERROR_MODE_DIE_SOAP_FAULT => 2;
# The various modes that checksetup.pl can run in.
use constant INSTALLATION_MODE_INTERACTIVE => 0;
use constant INSTALLATION_MODE_NON_INTERACTIVE => 1;
# Data about what we require for different databases. # Data about what we require for different databases.
use constant DB_MODULE => { use constant DB_MODULE => {
'mysql' => {db => 'Bugzilla::DB::Mysql', db_version => '4.1.2', 'mysql' => {db => 'Bugzilla::DB::Mysql', db_version => '4.1.2',
......
...@@ -43,6 +43,7 @@ package Bugzilla::DB::Mysql; ...@@ -43,6 +43,7 @@ package Bugzilla::DB::Mysql;
use strict; use strict;
use Bugzilla::Constants;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Error; use Bugzilla::Error;
...@@ -349,7 +350,7 @@ sub bz_setup_database { ...@@ -349,7 +350,7 @@ sub bz_setup_database {
. "If you would like to cancel, press Ctrl-C now..." . "If you would like to cancel, press Ctrl-C now..."
. " (Waiting 45 seconds...)\n\n"; . " (Waiting 45 seconds...)\n\n";
# Wait 45 seconds for them to respond. # Wait 45 seconds for them to respond.
sleep(45); sleep(45) unless Bugzilla->installation_answers->{NO_PAUSE};
} }
print "Renaming indexes...\n"; print "Renaming indexes...\n";
...@@ -566,9 +567,23 @@ WARNING: We are about to convert your table storage format to UTF8. This ...@@ -566,9 +567,23 @@ WARNING: We are about to convert your table storage format to UTF8. This
If you ever used a version of Bugzilla before 2.22, we STRONGLY If you ever used a version of Bugzilla before 2.22, we STRONGLY
recommend that you stop checksetup.pl NOW and run contrib/recode.pl. recommend that you stop checksetup.pl NOW and run contrib/recode.pl.
Continuing in 60 seconds...
EOT EOT
sleep 60;
if (!Bugzilla->installation_answers->{NO_PAUSE}) {
if (Bugzilla->installation_mode ==
INSTALLATION_MODE_NON_INTERACTIVE)
{
print <<EOT;
Re-run checksetup.pl in interactive mode (without an 'answers' file)
to continue.
EOT
exit;
}
else {
print " Press Enter to continue or Ctrl-C to exit...";
getc;
}
}
print "Converting table storage format to UTF-8. This may take a", print "Converting table storage format to UTF-8. This may take a",
" while.\n"; " while.\n";
......
...@@ -274,7 +274,7 @@ sub create_admin { ...@@ -274,7 +274,7 @@ sub create_admin {
return if $admin_count; return if $admin_count;
my %answer = %{$params->{answer} || {}}; my %answer = %{Bugzilla->installation_answers};
my $login = $answer{'ADMIN_EMAIL'}; my $login = $answer{'ADMIN_EMAIL'};
my $password = $answer{'ADMIN_PASSWORD'}; my $password = $answer{'ADMIN_PASSWORD'};
my $full_name = $answer{'ADMIN_REALNAME'}; my $full_name = $answer{'ADMIN_REALNAME'};
......
...@@ -275,7 +275,7 @@ sub update_localconfig { ...@@ -275,7 +275,7 @@ sub update_localconfig {
my ($params) = @_; my ($params) = @_;
my $output = $params->{output} || 0; my $output = $params->{output} || 0;
my $answer = $params->{answer} || {}; my $answer = Bugzilla->installation_answers;
my $localconfig = read_localconfig('include deprecated'); my $localconfig = read_localconfig('include deprecated');
my @new_vars; my @new_vars;
...@@ -401,7 +401,7 @@ Bugzilla::Install::Localconfig - Functions and variables dealing ...@@ -401,7 +401,7 @@ Bugzilla::Install::Localconfig - Functions and variables dealing
=head1 SYNOPSIS =head1 SYNOPSIS
use Bugzilla::Install::Requirements qw(update_localconfig); use Bugzilla::Install::Requirements qw(update_localconfig);
update_localconfig({ output => 1, answer => \%answer }); update_localconfig({ output => 1 });
=head1 DESCRIPTION =head1 DESCRIPTION
...@@ -453,7 +453,7 @@ Returns: A hashref of the localconfig variables. If an array ...@@ -453,7 +453,7 @@ Returns: A hashref of the localconfig variables. If an array
(and C<OLD_LOCALCONFIG_VARS> if C<$include_deprecated> is (and C<OLD_LOCALCONFIG_VARS> if C<$include_deprecated> is
specified). specified).
=item C<update_localconfig({ output =E<gt> 1, answer =E<gt> \%answer })> =item C<update_localconfig({ output =E<gt> 1 })>
Description: Adds any new variables to localconfig that aren't Description: Adds any new variables to localconfig that aren't
currently defined there. Also optionally prints out currently defined there. Also optionally prints out
......
...@@ -58,25 +58,6 @@ use Bugzilla::Install::Requirements; ...@@ -58,25 +58,6 @@ use Bugzilla::Install::Requirements;
require 5.008001 if ON_WINDOWS; # for CGI 2.93 or higher require 5.008001 if ON_WINDOWS; # for CGI 2.93 or higher
###################################################################### ######################################################################
# Subroutines
######################################################################
sub read_answers_file {
my %hash;
if ($ARGV[0]) {
my $s = new Safe;
$s->rdo($ARGV[0]);
die "Error reading $ARGV[0]: $!" if $!;
die "Error evaluating $ARGV[0]: $@" if $@;
# Now read the param back out from the sandbox
%hash = %{$s->varglob('answer')};
}
return \%hash;
}
######################################################################
# Live Code # Live Code
###################################################################### ######################################################################
...@@ -89,9 +70,8 @@ pod2usage({-verbose => 1, -exitval => 1}) if $switch{'help'}; ...@@ -89,9 +70,8 @@ pod2usage({-verbose => 1, -exitval => 1}) if $switch{'help'};
# Read in the "answers" file if it exists, for running in # Read in the "answers" file if it exists, for running in
# non-interactive mode. # non-interactive mode.
our %answer = %{read_answers_file()}; my $answers_file = $ARGV[0];
my $silent = $answers_file && !$switch{'verbose'};
my $silent = scalar(keys %answer) && !$switch{'verbose'};
display_version_and_os() unless $silent; display_version_and_os() unless $silent;
# Check required --MODULES-- # Check required --MODULES--
...@@ -132,6 +112,8 @@ require Bugzilla::Field; ...@@ -132,6 +112,8 @@ require Bugzilla::Field;
require Bugzilla::Install; require Bugzilla::Install;
Bugzilla->usage_mode(USAGE_MODE_CMDLINE); Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
Bugzilla->installation_mode(INSTALLATION_MODE_NON_INTERACTIVE) if $answers_file;
Bugzilla->installation_answers($answers_file);
# When we're running at the command line, we need to pick the right # When we're running at the command line, we need to pick the right
# language before ever creating a template object. # language before ever creating a template object.
...@@ -142,7 +124,7 @@ $ENV{'HTTP_ACCEPT_LANGUAGE'} ||= setlocale(LC_CTYPE); ...@@ -142,7 +124,7 @@ $ENV{'HTTP_ACCEPT_LANGUAGE'} ||= setlocale(LC_CTYPE);
########################################################################### ###########################################################################
print "Reading " . bz_locations()->{'localconfig'} . "...\n" unless $silent; print "Reading " . bz_locations()->{'localconfig'} . "...\n" unless $silent;
update_localconfig({ output => !$silent, answer => \%answer }); update_localconfig({ output => !$silent });
my $lc_hash = Bugzilla->localconfig; my $lc_hash = Bugzilla->localconfig;
########################################################################### ###########################################################################
...@@ -172,7 +154,7 @@ create_htaccess() if $lc_hash->{'create_htaccess'}; ...@@ -172,7 +154,7 @@ create_htaccess() if $lc_hash->{'create_htaccess'};
# Remove parameters from the params file that no longer exist in Bugzilla, # Remove parameters from the params file that no longer exist in Bugzilla,
# and set the defaults for new ones # and set the defaults for new ones
update_params({ answer => \%answer}); update_params();
########################################################################### ###########################################################################
# Pre-compile --TEMPLATE-- code # Pre-compile --TEMPLATE-- code
...@@ -229,7 +211,7 @@ Bugzilla::Install::update_settings(); ...@@ -229,7 +211,7 @@ Bugzilla::Install::update_settings();
########################################################################### ###########################################################################
Bugzilla::Install::make_admin($switch{'make-admin'}) if $switch{'make-admin'}; Bugzilla::Install::make_admin($switch{'make-admin'}) if $switch{'make-admin'};
Bugzilla::Install::create_admin({ answer => \%answer }); Bugzilla::Install::create_admin();
########################################################################### ###########################################################################
# Create default Product and Classification # Create default Product and Classification
...@@ -471,6 +453,12 @@ The format of that file is as follows: ...@@ -471,6 +453,12 @@ The format of that file is as follows:
$answer{'SMTP_SERVER'} = 'mail.mydomain.net'; $answer{'SMTP_SERVER'} = 'mail.mydomain.net';
$answer{'NO_PAUSE'} = 1
C<NO_PAUSE> means "never stop and prompt the user to hit Enter to continue,
just go ahead and do things, even if they are potentially dangerous."
Don't set this to 1 unless you know what you are doing.
=head1 SEE ALSO =head1 SEE ALSO
=over =over
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment