2 # -*- Mode: perl; indent-tabs-mode: nil -*-
4 # The contents of this file are subject to the Mozilla Public
5 # License Version 1.1 (the "License"); you may not use this file
6 # except in compliance with the License. You may obtain a copy of
7 # the License at http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS
10 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 # implied. See the License for the specific language governing
12 # rights and limitations under the License.
14 # The Original Code is mozilla.org code.
16 # The Initial Developer of the Original Code is Holger
17 # Schurig. Portions created by Holger Schurig are
18 # Copyright (C) 1999 Holger Schurig. All
21 # Contributor(s): Holger Schurig <holgerschurig@nikocity.de>
22 # Terry Weissman <terry@mozilla.org>
23 # Dan Mosedale <dmose@mozilla.org>
24 # Dave Miller <justdave@syndicomm.com>
25 # Zach Lipton <zach@zachlipton.com>
26 # Jacob Steenhagen <jake@bugzilla.org>
27 # Bradley Baetz <bbaetz@student.usyd.edu.au>
28 # Tobias Burnus <burnus@net-b.de>
29 # Shane H. W. Travis <travis@sedsystems.ca>
30 # Gervase Markham <gerv@gerv.net>
31 # Erik Stambaugh <erik@dasbistro.com>
32 # Dave Lawrence <dkl@redhat.com>
33 # Max Kanat-Alexander <mkanat@bugzilla.org>
34 # Joel Peshkin <bugreport@peshkin.net>
35 # Lance Larsh <lance.larsh@oracle.com>
36 # A. Karl Kornel <karl@kornel.name>
37 # Marc Schumann <wurblzap@gmail.com>
39 # This file has detailed POD docs, do "perldoc checksetup.pl" to see them.
41 ######################################################################
43 ######################################################################
48 use Getopt
::Long
qw(:config bundling);
52 BEGIN { chdir dirname
($0); }
54 use Bugzilla
::Constants
;
55 use Bugzilla
::Install
::Requirements
;
56 use Bugzilla
::Install
::Util
qw(install_string get_version_and_os get_console_locale);
58 ######################################################################
60 ######################################################################
62 # When we're running at the command line, we need to pick the right
63 # language before ever displaying any string.
64 $ENV{'HTTP_ACCEPT_LANGUAGE'} ||= get_console_locale
();
67 GetOptions
(\
%switch, 'help|h|?', 'check-modules', 'no-templates|t',
68 'verbose|v|no-silent', 'make-admin=s',
69 'reset-password=s', 'version|V');
71 # Print the help message if that switch was selected.
72 pod2usage
({-verbose
=> 1, -exitval
=> 1}) if $switch{'help'};
74 # Read in the "answers" file if it exists, for running in
75 # non-interactive mode.
76 my $answers_file = $ARGV[0];
77 my $silent = $answers_file && !$switch{'verbose'};
79 print(install_string
('header', get_version_and_os
()) . "\n") unless $silent;
80 exit if $switch{'version'};
81 # Check required --MODULES--
82 my $module_results = check_requirements
(!$silent);
83 Bugzilla
::Install
::Requirements
::print_module_instructions
(
84 $module_results, !$silent);
85 exit if !$module_results->{pass
};
86 # Break out if checking the modules is all we have been asked to do.
87 exit if $switch{'check-modules'};
89 ###########################################################################
90 # Load Bugzilla Modules
91 ###########################################################################
93 # It's never safe to "use" a Bugzilla module in checksetup. If a module
94 # prerequisite is missing, and you "use" a module that requires it,
95 # then instead of our nice normal checksetup message, the user would
96 # get a cryptic perl error about the missing module.
98 # We need $::ENV{'PATH'} to remain defined.
99 my $env = $::ENV
{'PATH'};
101 $::ENV
{'PATH'} = $env;
103 require Bugzilla
::Config
;
104 import Bugzilla
::Config
qw(:admin);
106 require Bugzilla
::Install
::Localconfig
;
107 import Bugzilla
::Install
::Localconfig
qw(update_localconfig);
109 require Bugzilla
::Install
::Filesystem
;
110 import Bugzilla
::Install
::Filesystem
qw(update_filesystem create_htaccess
111 fix_all_file_permissions);
112 require Bugzilla
::Install
::DB
;
113 require Bugzilla
::DB
;
114 require Bugzilla
::Template
;
115 require Bugzilla
::Field
;
116 require Bugzilla
::Install
;
118 Bugzilla
->usage_mode(USAGE_MODE_CMDLINE
);
119 Bugzilla
->installation_mode(INSTALLATION_MODE_NON_INTERACTIVE
) if $answers_file;
120 Bugzilla
->installation_answers($answers_file);
122 ###########################################################################
123 # Check and update --LOCAL-- configuration
124 ###########################################################################
126 print "Reading " . bz_locations
()->{'localconfig'} . "...\n" unless $silent;
127 update_localconfig
({ output
=> !$silent });
128 my $lc_hash = Bugzilla
->localconfig;
130 ###########################################################################
131 # Check --DATABASE-- setup
132 ###########################################################################
134 # At this point, localconfig is defined and is readable. So we know
135 # everything we need to create the DB. We have to create it early,
136 # because some data required to populate data/params is stored in the DB.
138 Bugzilla
::DB
::bz_check_requirements
(!$silent);
139 Bugzilla
::DB
::bz_create_database
() if $lc_hash->{'db_check'};
141 # now get a handle to the database:
142 my $dbh = Bugzilla
->dbh;
143 # Create the tables, and do any database-specific schema changes.
144 $dbh->bz_setup_database();
145 # Populate the tables that hold the values for the <select> fields.
146 $dbh->bz_populate_enum_tables();
148 ###########################################################################
149 # Check --DATA-- directory
150 ###########################################################################
152 update_filesystem
({ index_html
=> $lc_hash->{'index_html'} });
153 create_htaccess
() if $lc_hash->{'create_htaccess'};
155 # Remove parameters from the params file that no longer exist in Bugzilla,
156 # and set the defaults for new ones
157 my %old_params = update_params
();
159 ###########################################################################
160 # Pre-compile --TEMPLATE-- code
161 ###########################################################################
163 Bugzilla
::Template
::precompile_templates
(!$silent)
164 unless $switch{'no-templates'};
166 ###########################################################################
167 # Set proper rights (--CHMOD--)
168 ###########################################################################
170 fix_all_file_permissions
(!$silent);
172 ###########################################################################
173 # Check GraphViz setup
174 ###########################################################################
176 # If we are using a local 'dot' binary, verify the specified binary exists
177 # and that the generated images are accessible.
178 check_graphviz
(!$silent) if Bugzilla
->params->{'webdotbase'};
180 ###########################################################################
181 # Changes to the fielddefs --TABLE--
182 ###########################################################################
184 # Using Bugzilla::Field's create() or update() depends on the
185 # fielddefs table having a modern definition. So, we have to make
186 # these particular schema changes before we make any other schema changes.
187 Bugzilla
::Install
::DB
::update_fielddefs_definition
();
189 Bugzilla
::Field
::populate_field_definitions
();
191 ###########################################################################
192 # Update the tables to the current definition --TABLE--
193 ###########################################################################
195 Bugzilla
::Install
::DB
::update_table_definitions
(\
%old_params);
197 ###########################################################################
198 # Bugzilla uses --GROUPS-- to assign various rights to its users.
199 ###########################################################################
201 Bugzilla
::Install
::update_system_groups
();
203 ###########################################################################
204 # Create --SETTINGS-- users can adjust
205 ###########################################################################
207 Bugzilla
::Install
::update_settings
();
209 ###########################################################################
210 # Create Administrator --ADMIN--
211 ###########################################################################
213 Bugzilla
::Install
::make_admin
($switch{'make-admin'}) if $switch{'make-admin'};
214 Bugzilla
::Install
::create_admin
();
216 Bugzilla
::Install
::reset_password
($switch{'reset-password'})
217 if $switch{'reset-password'};
219 ###########################################################################
220 # Create default Product and Classification
221 ###########################################################################
223 Bugzilla
::Install
::create_default_product
();
225 Bugzilla
::Hook
::process
('install-before_final_checks', {'silent' => $silent });
227 ###########################################################################
229 ###########################################################################
231 # Check if the default parameter for urlbase is still set, and if so, give
232 # notification that they should go and visit editparams.cgi
233 if (Bugzilla
->params->{'urlbase'} eq '') {
234 print "\n" . Bugzilla
::Install
::get_text
('install_urlbase_default') . "\n"
242 checksetup.pl - A do-it-all upgrade and installation script for Bugzilla.
246 ./checksetup.pl [--help|--check-modules|--version]
247 ./checksetup.pl [SCRIPT [--verbose]] [--no-templates|-t]
248 [--make-admin=user@domain.com]
249 [--reset-password=user@domain.com]
257 Name of script to drive non-interactive mode. This script should
258 define an C<%answer> hash whose keys are variable names and the
259 values answers to all the questions checksetup.pl asks. For details
260 on the format of this script, do C<perldoc checksetup.pl> and look for
261 the L</"RUNNING CHECKSETUP NON-INTERACTIVELY"> section.
265 Display this help text
267 =item B<--check-modules>
269 Only check for correct module dependencies and quit afterward.
271 =item B<--make-admin>=username@domain.com
273 Makes the specified user into a Bugzilla administrator. This is
274 in case you accidentally lock yourself out of the Bugzilla administrative
277 =item B<--reset-password>=user@domain.com
279 Resets the specified user's password. checksetup.pl will prompt you to
280 enter a new password for the user.
282 =item B<--no-templates> (B<-t>)
284 Don't compile the templates at all. Existing compiled templates will
285 remain; missing compiled templates will not be created. (Used primarily
286 by developers to speed up checksetup.) Use this switch at your own risk.
290 Output results of SCRIPT being processed.
294 Display the version of Bugzilla, Perl, and some info about the
295 system that Bugzilla is being installed on, and then exit.
303 F<checksetup.pl> is a script that is supposed to run during
304 installation time and also after every upgrade.
306 The goal of this script is to make the installation even easier.
307 It does this by doing things for you as well as testing for problems
310 You can run the script whenever you like. You MUST run it after
311 you update Bugzilla, because it will then update your SQL table
312 definitions to resync them with the code.
314 You can see all the details of what the script does at
315 L</How Checksetup Works>.
317 =head1 MODIFYING CHECKSETUP
319 There should be no need for Bugzilla Administrators to modify
320 this script; all user-configurable stuff has been moved
321 into a local configuration file called F<localconfig>. When that file
322 in changed and F<checksetup.pl> is run, then the user's changes
323 will be reflected back into the database.
325 However, developers often need to modify the installation process.
326 This section explains how F<checksetup.pl> works, so that you
327 know the right part to modify.
329 =head2 How Checksetup Works
331 F<checksetup.pl> runs through several stages during installation:
337 Checks if the required and optional perl modules are installed,
338 using L<Bugzilla::Install::Requirements/check_requirements>.
342 Creates or updates the F<localconfig> file, using
343 L<Bugzilla::Install::Localconfig/update_localconfig>.
347 Checks the DBD and database version, using
348 L<Bugzilla::DB/bz_check_requirements>.
352 Creates the Bugzilla database if it doesn't exist, using
353 L<Bugzilla::DB/bz_create_database>.
357 Creates all of the tables in the Bugzilla database, using
358 L<Bugzilla::DB/bz_setup_database>.
360 Note that all the table definitions are stored in
361 L<Bugzilla::DB::Schema/ABSTRACT_SCHEMA>.
365 Puts the values into the enum tables (like C<resolution>, C<bug_status>,
366 etc.) using L<Bugzilla::DB/bz_populate_enum_tables>.
370 Creates any files that Bugzilla needs but doesn't ship with, using
371 L<Bugzilla::Install::Filesystem/update_filesystem>.
375 Creates the F<.htaccess> files if you haven't specified not to
376 in F<localconfig>. It does this with
377 L<Bugzilla::Install::Filesystem/create_htaccess>.
381 Updates the system parameters (stored in F<data/params>), using
382 L<Bugzilla::Config/update_params>.
386 Pre-compiles all templates, to improve the speed of Bugzilla.
387 It uses L<Bugzilla::Template/precompile_templates> to do this.
391 Fixes all file permissions to be secure. It does this differently depending
392 on whether or not you've specified C<$webservergroup> in F<localconfig>.
394 The function that does this is
395 L<Bugzilla::Install::Filesystem/fix_all_file_permissions>.
399 Populates the C<fielddefs> table, using
400 L<Bugzilla::Field/populate_field_definitions>.
404 This is the major part of checksetup--updating the table definitions
405 from one version of Bugzilla to another.
407 The code for this is in L<Bugzilla::Install::DB/update_table_definitions>.
411 Creates the system groups--the ones like C<editbugs>, C<admin>, and so on.
412 This is L<Bugzilla::Install/update_system_groups>.
416 Creates all of the user-adjustable preferences that appear on the
417 "General Preferences" screen. This is L<Bugzilla::Install/update_settings>.
421 Creates an administrator, if one doesn't already exist, using
422 L<Bugzilla::Install/create_admin>.
424 We also can make somebody an admin at this step, if the user specified
425 the C<--make-admin> switch.
429 Creates the default Classification, Product, and Component, using
430 L<Bugzilla::Install/create_default_product>.
434 =head2 Modifying the Database
436 Sometimes you'll want to modify the database. In fact, that's mostly
437 what checksetup does, is upgrade old Bugzilla databases to the modern
440 If you'd like to know how to make changes to the datbase, see
441 the information in the Bugzilla Developer's Guide, at:
442 L<http://www.bugzilla.org/docs/developer.html#sql-schema>
444 Also see L<Bugzilla::DB/"Schema Modification Methods"> and
445 L<Bugzilla::DB/"Schema Information Methods">.
447 =head1 RUNNING CHECKSETUP NON-INTERACTIVELY
449 To operate checksetup non-interactively, run it with a single argument
450 specifying a filename that contains the information usually obtained by
451 prompting the user or by editing localconfig.
453 The format of that file is as follows:
455 $answer{'db_host'} = 'localhost';
456 $answer{'db_driver'} = 'mydbdriver';
457 $answer{'db_port'} = 0;
458 $answer{'db_name'} = 'mydbname';
459 $answer{'db_user'} = 'mydbuser';
460 $answer{'db_pass'} = 'mydbpass';
462 $answer{'urlbase'} = 'http://bugzilla.mydomain.com/';
464 (Any localconfig variable or parameter can be specified as above.)
466 $answer{'ADMIN_EMAIL'} = 'myadmin@mydomain.net';
467 $answer{'ADMIN_PASSWORD'} = 'fooey';
468 $answer{'ADMIN_REALNAME'} = 'Joel Peshkin';
470 $answer{'SMTP_SERVER'} = 'mail.mydomain.net';
472 $answer{'NO_PAUSE'} = 1
474 C<NO_PAUSE> means "never stop and prompt the user to hit Enter to continue,
475 just go ahead and do things, even if they are potentially dangerous."
476 Don't set this to 1 unless you know what you are doing.
484 L<Bugzilla::Install::Requirements>
488 L<Bugzilla::Install::Localconfig>
492 L<Bugzilla::Install::Filesystem>
496 L<Bugzilla::Install::DB>
504 L<Bugzilla::Config/update_params>
508 L<Bugzilla::DB/CONNECTION>