Bug 21395: Ignore .perlcriticrc in t/Makefile.t
[koha.git] / misc / devel / install_plugins.pl
blob073ddbbb1c614389171835dd843b8fd24056eca8
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Copyright 2019 Koha Development Team
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
21 use Getopt::Long;
22 use Pod::Usage;
24 use Koha::Script;
26 use C4::Context;
27 use Koha::Plugins;
29 my ($help);
30 GetOptions( 'help|?' => \$help );
32 pod2usage(1) if $help;
34 unless ( C4::Context->config("enable_plugins") ) {
35 print
36 "The plugin system must be enabled for one to be able to install plugins\n";
37 exit 1;
41 my @existing_plugins = Koha::Plugins->new()->GetPlugins({
42 all => 1,
43 });
44 my $existing_plugins;
45 for my $existing_plugin (@existing_plugins) {
46 $existing_plugins->{ $existing_plugin->{metadata}->{name} } =
47 $existing_plugin->{metadata}->{version};
50 my @installed_plugins = Koha::Plugins->new()->InstallPlugins();
51 unless (@installed_plugins) {
52 my $plugins_dir = C4::Context->config("pluginsdir");
53 if ( ref($plugins_dir) eq 'ARRAY' ) {
54 print "No plugins found\n";
55 print "pluginsdir contains: \n" . join( '\n', @{$plugins_dir} );
57 else {
58 print "No plugins found at $plugins_dir\n";
60 exit 0;
63 for my $installed_plugin (@installed_plugins) {
64 if ( !exists( $existing_plugins->{ $installed_plugin->{metadata}->{name} } )
67 print "Installed "
68 . $installed_plugin->{metadata}->{name}
69 . " version "
70 . $installed_plugin->{metadata}->{version} . "\n";
72 elsif ( $existing_plugins->{ $installed_plugin->{metadata}->{name} } ne
73 $installed_plugin->{metadata}->{version} )
75 print "Upgraded "
76 . $installed_plugin->{metadata}->{name}
77 . " from version "
78 . $existing_plugins->{ $installed_plugin->{metadata}->{name} }
79 . " to version "
80 . $installed_plugin->{metadata}->{version} . "\n";
83 print "All plugins successfully re-initialised\n";
85 =head1 NAME
87 install_plugins.pl - install all plugins found in plugins_dir
89 =head1 SYNOPSIS
91 install_plugins.pl
93 Options:
94 -?|--help brief help message
96 =head1 OPTIONS
98 =over 8
100 =item B<--help|-?>
102 Print a brief help message and exits
104 =back
106 =head1 DESCRIPTION
108 A simple script to install plugins from the command line
110 =cut