|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# |
| 4 |
# Copyright 2020 Prosentient Systems |
| 5 |
# |
| 6 |
# This program is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
use Getopt::Long; |
| 20 |
use Modern::Perl; |
| 21 |
use Pod::Usage; |
| 22 |
use URI; |
| 23 |
use Mojo::UserAgent; |
| 24 |
|
| 25 |
use Koha::Plugins; |
| 26 |
use Koha::Plugins::Handler; |
| 27 |
use Koha::Plugins::Utils; |
| 28 |
|
| 29 |
my $plugins_dir = C4::Context->config("pluginsdir"); |
| 30 |
|
| 31 |
my $help = 0; |
| 32 |
my $install = ''; |
| 33 |
my $uninstall = ''; |
| 34 |
GetOptions( |
| 35 |
'help' => \$help, |
| 36 |
'install=s' => \$install, |
| 37 |
'uninstall=s' => \$uninstall, |
| 38 |
); |
| 39 |
usage() if $help; |
| 40 |
usage() unless ($install || $uninstall); |
| 41 |
|
| 42 |
my $plugin_arg = shift @ARGV; |
| 43 |
my @instances = @ARGV; |
| 44 |
|
| 45 |
if ($install){ |
| 46 |
my $plugin_arg = $install; |
| 47 |
my $plugin_uri = URI->new($plugin_arg); |
| 48 |
if ($plugin_uri){ |
| 49 |
my $plugin; |
| 50 |
if ( _is_file_uri($plugin_uri) ){ |
| 51 |
|
| 52 |
warn "file"; |
| 53 |
} |
| 54 |
elsif ( _is_http_uri($plugin_uri) ){ |
| 55 |
$plugin = Koha::Plugins::Utils->download_plugin({ |
| 56 |
url => $plugin_uri->as_string, |
| 57 |
}); |
| 58 |
} |
| 59 |
if ($plugin){ |
| 60 |
my $unzipped_plugin; |
| 61 |
if ( -f $plugin ){ |
| 62 |
$unzipped_plugin = Koha::Plugins::Utils->unzip_plugin({ |
| 63 |
zip => $plugin, |
| 64 |
}); |
| 65 |
} |
| 66 |
elsif ( -d $plugin ){ |
| 67 |
$unzipped_plugin = $plugin; |
| 68 |
} |
| 69 |
if ($unzipped_plugin){ |
| 70 |
my $copied = Koha::Plugins::Utils->copy_unzipped_plugin({ |
| 71 |
unzipped_plugin => $unzipped_plugin, |
| 72 |
plugin_dir => $plugins_dir, |
| 73 |
}); |
| 74 |
if ($copied){ |
| 75 |
my @installed_plugins = Koha::Plugins->new()->InstallPlugins(); |
| 76 |
warn scalar @installed_plugins; |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
elsif ($uninstall){ |
| 83 |
my $class = $uninstall; |
| 84 |
Koha::Plugins::Handler->delete( { class => $class } ); |
| 85 |
#FIXME: The above method should return more meaningful output |
| 86 |
} |
| 87 |
|
| 88 |
sub _is_http_uri { |
| 89 |
my ($uri) = @_; |
| 90 |
my $is_http = 0; |
| 91 |
#NOTE: This includes both http and https URIs |
| 92 |
if ($uri->isa("URI::http")){ |
| 93 |
$is_http = 1; |
| 94 |
} |
| 95 |
return $is_http; |
| 96 |
} |
| 97 |
|
| 98 |
sub _is_file_uri { |
| 99 |
my ($uri) = @_; |
| 100 |
my $is_file = 0; |
| 101 |
if ( (! defined $uri->scheme) || ($uri->scheme eq 'file') ){ |
| 102 |
$is_file = 1; |
| 103 |
} |
| 104 |
return $is_file; |
| 105 |
} |
| 106 |
|
| 107 |
sub usage { |
| 108 |
pod2usage( -verbose => 1, -message => "koha-plugin\n\nThis script lets you manage Koha plugins for your Koha instances.\n", -width => 90 ); |
| 109 |
exit; |
| 110 |
} |
| 111 |
|
| 112 |
=head1 NAME |
| 113 |
|
| 114 |
koha_plugin.pl - This script lets you manage Koha plugins for your Koha instance |
| 115 |
|
| 116 |
=head1 USAGE |
| 117 |
|
| 118 |
=over |
| 119 |
|
| 120 |
=item koha_plugin.pl --install file:///unzipped_koha-plugin |
| 121 |
|
| 122 |
=item koha_plugin.pl --install file:///koha-plugin.kpz |
| 123 |
|
| 124 |
=item koha_plugin.pl --install https://localhost/koha-plugin.kpz |
| 125 |
|
| 126 |
=item koha_plugin.pl --uninstall plugin_class |
| 127 |
|
| 128 |
=item koha_plugin.pl -h|--help |
| 129 |
|
| 130 |
=back |
| 131 |
|
| 132 |
=over |
| 133 |
|
| 134 |
=item --install |
| 135 |
|
| 136 |
Install the plugin for the specified instances |
| 137 |
|
| 138 |
=item --uninstall |
| 139 |
|
| 140 |
Uninstall the plugin for the specified instances |
| 141 |
|
| 142 |
=item --help|h |
| 143 |
|
| 144 |
Display this help message |
| 145 |
|
| 146 |
=back |