Bug 23191: Add commandline script to install plugins
[koha-equinox.git] / misc / devel / install_plugins.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright 2019 Koha Development Team
6 #
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.
11 #
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.
16 #
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>.
19
20 use Modern::Perl;
21 use Getopt::Long;
22 use Pod::Usage;
23
24 use Koha::Script;
25
26 use C4::Context;
27 use Koha::Plugins;
28
29 my ($help);
30 GetOptions( 'help|?' => \$help );
31
32 pod2usage(1) if $help;
33
34 my $plugins_enabled = C4::Context->preference('UseKohaPlugins')
35   && C4::Context->config("enable_plugins");
36 unless ($plugins_enabled) {
37     print
38 "The plugin system must be enabled for one to be able to install plugins\n";
39     exit 1;
40 }
41
42 my @plugins = Koha::Plugins->new()->InstallPlugins();
43
44 unless (@plugins) {
45     my $plugins_dir = C4::Context->config("pluginsdir");
46     if ( ref($plugins_dir) eq 'ARRAY' ) {
47         print "No plugins found\n";
48         print "pluginsdir contains: \n" . join( '\n', @{$plugins_dir} );
49     }
50     else {
51         print "No plugins found at $plugins_dir\n";
52     }
53 }
54
55 for my $plugin (@plugins) {
56     print "Installed "
57       . $plugin->{metadata}->{name}
58       . " version "
59       . $plugin->{metadata}->{version} . "\n";
60 }
61
62 =head1 NAME
63
64 install_plugins.pl - install all plugins found in plugins_dir
65
66 =head1 SYNOPSIS
67
68  install_plugins.pl
69
70 Options:
71   -?|--help        brief help message
72
73 =head1 OPTIONS
74
75 =over 8
76
77 =item B<--help|-?>
78
79 Print a brief help message and exits
80
81 =back
82
83 =head1 DESCRIPTION
84
85 A simple script to install plugins from the command line
86
87 =cut