Bug 4517 - add authentication to reorder_members.pl
[koha.git] / koha_perl_deps.pl
1 #!/usr/bin/perl
2
3 use Getopt::Long;
4 use Pod::Usage;
5 use Term::ANSIColor;
6 use FindBin; # we need to enforce which C4::Installer is used in case more than one is installed
7
8 use lib $FindBin::Bin;
9
10 use C4::Installer;
11
12 my $help = 0;
13 my $missing = 0;
14 my $installed = 0;
15 my $upgrade = 0;
16 my $all = 0;
17 my $color = 0;
18
19 GetOptions(
20             'h|help|?'    => \$help,
21             'm|missing'   => \$missing,
22             'i|installed' => \$installed,
23             'u|upgrade'   => \$upgrade,
24             'a|all'       => \$all,
25             'c|color'     => \$color,
26           );
27
28 pod2usage(1) if $help || (!$missing && !$installed && !$upgrade && !$all);
29
30 my $koha_pm = C4::Installer::PerlModules->new;
31 $koha_pm->version_info(all => 1);
32
33 my @pm = ();
34
35 push @pm, 'missing_pm' if $missing || $all;
36 push @pm, 'upgrade_pm' if $upgrade || $all;
37 push @pm, 'current_pm' if $installed || $all;
38
39 print color 'bold white' if $color;
40 print"
41 Module Name                                 Current Version                       Required Version         Module Required
42 --------------------------------------------------------------------------------------------------------------------------
43 ";
44
45 my $count = 0;
46 foreach my $type (@pm) {
47     my $mod_type = $type;
48     $mod_type =~ s/_pm$//;
49     my $pm = $koha_pm->get_attr($type);
50     foreach (@$pm) {
51         foreach my $pm (keys(%$_)) {
52             print color 'yellow' if $type eq 'upgrade_pm' && $color;
53             print color 'red' if $type eq 'missing_pm' && $color;
54             print color 'green' if $type eq 'current_pm' && $color;
55             $count++;
56             my $required = ($_->{$pm}->{'required'}?'Yes':'No');
57             my $current_version = ($color ? $_->{$pm}->{'cur_ver'} :
58                                    $type eq 'missing_pm' || $type eq 'upgrade_pm' ? $_->{$pm}->{'cur_ver'}." *" : $_->{$pm}->{'cur_ver'});
59 format =
60 @<<<<<<<<<<<<<<<<<<<<<<<<<                  @<<<<<<<<<<                           @<<<<<<<<<<              @<<<<<
61 $pm,                                        $current_version,                     $_->{$pm}->{'min_ver'},  $required
62 .
63 write;
64         }
65     }
66 }
67 print color 'bold white' if $color;
68 my $footer = "
69 --------------------------------------------------------------------------------------------------------------------------
70 Total modules reported: $count                                                     ";
71
72 if ($color) {
73     $footer .= "\n\n";
74 }
75 else {
76     $footer .= "* Module is missing or requires an upgrade.\n\n";
77 }
78
79 print $footer;
80
81 1;
82
83 __END__
84
85 =head1 NAME
86
87 koha_perl_deps.pl
88
89 =head1 SYNOPSIS
90
91 ./koha_perl_deps.pl -m
92
93 =head1 OPTIONS
94
95 =over 8
96
97 =item B<-m|--missing>
98
99 lists all missing perl modules
100
101 =item B<-i|--installed>
102
103 lists all installed perl modules
104
105 =item B<-u|--upgrade>
106
107 lists all perl modules needing to be upgraded relative to Koha
108
109 =item B<-a|--all>
110
111 lists all koha perl dependencies
112
113 =item B<-c|--color>
114
115 formats the output in color; red = module is missing, yellow = module requires upgrading, green = module is installed and current
116
117 =item B<-h|--help|?>
118
119 prints this help text
120
121 =back
122
123 =head1 AUTHOR
124
125 Chris Nighswonger <cnighswonger AT foundations DOT edu>
126
127 =head1 COPYRIGHT
128
129 Copyright 2010 Foundations Bible College.
130
131 =head1 LICENSE
132
133 This file is part of Koha.
134
135 Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
136 Foundation; either version 2 of the License, or (at your option) any later version.
137
138 You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
139 Suite 330, Boston, MA  02111-1307 USA
140
141 =head1 DISCLAIMER OF WARRANTY
142
143 Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
144 A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
145
146 =cut