Main Koha release repository https://koha-community.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

191 lines
4.9 KiB

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