Rubber-stamped by Brady Eidson.
[webbrowser.git] / BugsSite / install-module.pl
blob918323e75c4bfa30a11cfc94dcd118bd15fd804c
1 #!/usr/bin/env perl -w
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 the Bugzilla Bug Tracking System.
16 # The Initial Developer of the Original Code is Everything Solved, Inc.
17 # Portions created by Everything Solved are Copyright (C) 2007
18 # Everything Solved, Inc. All Rights Reserved.
20 # Contributor(s): Max Kanat-Alexander <mkanat@bugzilla.org>
22 use strict;
23 use warnings;
25 # Have to abs_path('.') or calls to Bugzilla modules won't work once
26 # CPAN has chdir'ed around. We do all of this in this funny order to
27 # make sure that we use the lib/ modules instead of the base Perl modules,
28 # in case the lib/ modules are newer.
29 use Cwd qw(abs_path);
30 use lib abs_path('.');
31 use Bugzilla::Constants;
32 use lib abs_path(bz_locations()->{ext_libpath});
34 use Bugzilla::Install::CPAN;
36 use Bugzilla::Constants;
37 use Bugzilla::Install::Requirements;
39 use Data::Dumper;
40 use Getopt::Long;
41 use Pod::Usage;
43 our %switch;
45 GetOptions(\%switch, 'all|a', 'upgrade-all|u', 'show-config|s', 'global|g',
46 'help|h');
48 pod2usage({ -verbose => 1 }) if $switch{'help'};
50 if (ON_WINDOWS) {
51 print "\nYou cannot run this script on Windows. Please follow instructions\n";
52 print "given by checksetup.pl to install missing Perl modules.\n\n";
53 exit;
56 pod2usage({ -verbose => 0 }) if (!%switch && !@ARGV);
58 set_cpan_config($switch{'global'});
60 if ($switch{'show-config'}) {
61 print Dumper($CPAN::Config);
62 exit;
65 my $can_notest = 1;
66 if (substr(CPAN->VERSION, 0, 3) < 1.8) {
67 $can_notest = 0;
68 print "* Note: If you upgrade your CPAN module, installs will be faster.\n";
69 print "* You can upgrade CPAN by doing: $^X install-module.pl CPAN\n";
72 if ($switch{'all'} || $switch{'upgrade-all'}) {
73 my @modules;
74 if ($switch{'upgrade-all'}) {
75 @modules = (@{REQUIRED_MODULES()}, @{OPTIONAL_MODULES()});
76 push(@modules, DB_MODULE->{$_}->{dbd}) foreach (keys %{DB_MODULE()});
78 else {
79 # This is the only time we need a Bugzilla-related module, so
80 # we require them down here. Otherwise this script can be run from
81 # any directory, even outside of Bugzilla itself.
82 my $reqs = check_requirements(0);
83 @modules = (@{$reqs->{missing}}, @{$reqs->{optional}});
84 my $dbs = DB_MODULE;
85 foreach my $db (keys %$dbs) {
86 push(@modules, $dbs->{$db}->{dbd})
87 if !have_vers($dbs->{$db}->{dbd}, 0);
90 foreach my $module (@modules) {
91 my $cpan_name = $module->{module};
92 # --all shouldn't include mod_perl2, because it can have some complex
93 # configuration, and really should be installed on its own.
94 next if $cpan_name eq 'mod_perl2';
95 next if $cpan_name eq 'DBD::Oracle' and !$ENV{ORACLE_HOME};
96 install_module($cpan_name, $can_notest);
100 foreach my $module (@ARGV) {
101 install_module($module, $can_notest);
104 __END__
106 =head1 NAME
108 install-module.pl - Installs or upgrades modules from CPAN.
109 This script does not run on Windows.
111 =head1 SYNOPSIS
113 ./install-module.pl Module::Name [--global]
114 ./install-module.pl --all [--global]
115 ./install-module.pl --all-upgrade [--global]
116 ./install-module.pl --show-config
118 Do "./install-module.pl --help" for more information.
120 =head1 OPTIONS
122 =over
124 =item B<Module::Name>
126 The name of a module that you want to install from CPAN. This is the
127 same thing that you'd give to the C<install> command in the CPAN shell.
129 You can specify multiple module names separated by a space to install
130 multiple modules.
132 =item B<--global>
134 This makes install-module install modules globally for all applications,
135 instead of just for Bugzilla.
137 On most systems, you have to be root for C<--global> to work.
139 =item B<--all>
141 This will make install-module do its best to install every required
142 and optional module that is not installed that Bugzilla can use.
144 Some modules may fail to install. You can run checksetup.pl to see
145 which installed properly.
147 =item B<--upgrade-all>
149 This is like C<--all>, except it forcibly installs the very latest
150 version of every Bugzilla prerequisite, whether or not you already
151 have them installed.
153 =item B<--show-config>
155 Prints out the CPAN configuration in raw Perl format. Useful for debugging.
157 =item B<--help>
159 Shows this help.
161 =back