1 | #
|
---|
2 | # Manages Plugins for CasparBuster
|
---|
3 | #
|
---|
4 | # $Id$
|
---|
5 | #
|
---|
6 | #
|
---|
7 | package CasparBuster::Plugin;
|
---|
8 |
|
---|
9 | use strict;
|
---|
10 | use warnings;
|
---|
11 | use Carp;
|
---|
12 | use CasparBuster::Env;
|
---|
13 | use ProjectBuilder::Base;
|
---|
14 | use ProjectBuilder::Conf;
|
---|
15 | use Data::Dumper;
|
---|
16 |
|
---|
17 | # Global vars
|
---|
18 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
19 | #
|
---|
20 | use vars qw($VERSION $REVISION @ISA @EXPORT);
|
---|
21 | use Exporter;
|
---|
22 | #
|
---|
23 | # Export, by default, all the functions into the namespace of
|
---|
24 | # any code which uses this module.
|
---|
25 |
|
---|
26 | our @ISA = qw(Exporter);
|
---|
27 | our @EXPORT = qw(cb_plugin_load cb_plugin_get);
|
---|
28 |
|
---|
29 | =pod
|
---|
30 |
|
---|
31 | =head1 NAME
|
---|
32 |
|
---|
33 | CasparBuster::Plugin - module dealing with CasparBuster plugin management
|
---|
34 |
|
---|
35 | =head1 DESCRIPTION
|
---|
36 |
|
---|
37 | This modules provides functions to allow the management of CasparBuster plugins
|
---|
38 |
|
---|
39 | =head1 SYNOPSIS
|
---|
40 |
|
---|
41 | use CasparBuster::Plugin;
|
---|
42 |
|
---|
43 | =head1 USAGE
|
---|
44 |
|
---|
45 | =over 4
|
---|
46 |
|
---|
47 | =item B<cb_plugin_load>
|
---|
48 |
|
---|
49 | This function loads all the plugins defined for this CasparBuster environement
|
---|
50 |
|
---|
51 | =cut
|
---|
52 |
|
---|
53 | sub cb_plugin_load {
|
---|
54 |
|
---|
55 | my ($pluginsdir) = pb_conf_get("cbpluginssubdir");
|
---|
56 | my $cbconfdir = cb_env_confdir()."/$pluginsdir->{$ENV{'PBPROJ'}}";
|
---|
57 | opendir(DIR,$cbconfdir) || die "Unable to open $cbconfdir: $!";
|
---|
58 | foreach my $f (readdir(DIR)) {
|
---|
59 | next if ($f =~ /^\./);
|
---|
60 | # Add on plugins files
|
---|
61 | if ($f =~ /\.conf$/) {
|
---|
62 | pb_conf_add("$cbconfdir/$f") if (-f "$cbconfdir/$f");
|
---|
63 | }
|
---|
64 | }
|
---|
65 | closedir(DIR);
|
---|
66 |
|
---|
67 | my ($flist,$dlist,$dflist,$slist) = pb_conf_get_if("cbpluginfiles","cbplugindirs","cbplugindirsandfiles","cbppkgreload");
|
---|
68 | if (defined $flist) {
|
---|
69 | foreach my $plugin (keys %$flist) {
|
---|
70 | foreach my $block (split(/;/,$flist->{$plugin})) {
|
---|
71 | pb_log(3,"block : $block\n");
|
---|
72 | my ($name,$tmp) = split(/\|/,$block);
|
---|
73 | ($cbp->{'files'}->{$name}->{'uid'},$cbp->{'files'}->{$name}->{'gid'},$cbp->{'files'}->{$name}->{'mode'}) = split(/\,/,$tmp);
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 | if (defined $dlist) {
|
---|
78 | foreach my $plugin (keys %$dlist) {
|
---|
79 | foreach my $block (split(/;/,$dlist->{$plugin})) {
|
---|
80 | pb_log(3,"block : $block\n");
|
---|
81 | my ($name,$tmp) = split(/\|/,$block);
|
---|
82 | ($cbp->{'dirs'}->{$name}->{'uid'},$cbp->{'dirs'}->{$name}->{'gid'},$cbp->{'dirs'}->{$name}->{'mode'}) = split(/\,/,$tmp);
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|
86 | if (defined $dflist) {
|
---|
87 | foreach my $plugin (keys %$dflist) {
|
---|
88 | foreach my $block (split(/;/,$dflist->{$plugin})) {
|
---|
89 | pb_log(3,"block : $block\n");
|
---|
90 | my ($name,$tmp) = split(/\|/,$block);
|
---|
91 | ($cbp->{'dirsandfiles'}->{$name}->{'uid'},$cbp->{'dirsandfiles'}->{$name}->{'gid'},$cbp->{'dirsandfiles'}->{$name}->{'mode'}) = split(/\,/,$tmp);
|
---|
92 | }
|
---|
93 | }
|
---|
94 | }
|
---|
95 | if (defined $slist) {
|
---|
96 | foreach my $plugin (keys %$slist) {
|
---|
97 | foreach my $name (split(/,/,$slist->{$plugin})) {
|
---|
98 | $cbp->{'reload'}->{$plugin}->{'restart'} = $name;
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | =item B<cb_plugin_get>
|
---|
105 |
|
---|
106 | This function adds into the plugin hash, passed as second parameter, the new plugin content based on its name, passed as first parameter.
|
---|
107 |
|
---|
108 | =cut
|
---|
109 |
|
---|
110 | sub cb_plugin_get {
|
---|
111 |
|
---|
112 | my $plugin = shift;
|
---|
113 | my $cbp = shift;
|
---|
114 | my $remote = shift;
|
---|
115 | my $machine = shift;
|
---|
116 | my $debug = shift;
|
---|
117 | my $ssh2 = shift;
|
---|
118 |
|
---|
119 | pb_log(2,"Entering cb_plugin_get for plugin $plugin\n");
|
---|
120 | my ($flist,$dlist,$dflist,$slist,$plist) = pb_conf_get_if("cbpluginfiles","cbplugindirs","cbplugindirsandfiles","cbppkgreload","cbpluginpkgs");
|
---|
121 | if ((defined $flist) && (defined $flist->{$plugin}) && ($flist->{$plugin} !~ /^\s*$/)) {
|
---|
122 | foreach my $block (split(/;/,$flist->{$plugin})) {
|
---|
123 | pb_log(3,"block : $block\n");
|
---|
124 | my ($name,$tmp) = split(/\|/,$block);
|
---|
125 | ($cbp->{$plugin}->{'files'}->{$name}->{'uid'},$cbp->{$plugin}->{'files'}->{$name}->{'gid'},$cbp->{$plugin}->{'files'}->{$name}->{'mode'}) = split(/\,/,$tmp);
|
---|
126 | }
|
---|
127 | }
|
---|
128 | if ((defined $dlist) && (defined $dlist->{$plugin}) && ($dlist->{$plugin} !~ /^\s*$/)) {
|
---|
129 | foreach my $block (split(/;/,$dlist->{$plugin})) {
|
---|
130 | pb_log(3,"block : $block\n");
|
---|
131 | my ($name,$tmp) = split(/\|/,$block);
|
---|
132 | ($cbp->{$plugin}->{'dirs'}->{$name}->{'uid'},$cbp->{$plugin}->{'dirs'}->{$name}->{'gid'},$cbp->{$plugin}->{'dirs'}->{$name}->{'mode'}) = split(/\,/,$tmp);
|
---|
133 | }
|
---|
134 | }
|
---|
135 | if ((defined $dflist) && (defined $dflist->{$plugin}) && ($dflist->{$plugin} !~ /^\s*$/)) {
|
---|
136 | foreach my $block (split(/;/,$dflist->{$plugin})) {
|
---|
137 | pb_log(3,"block : $block\n");
|
---|
138 | my ($name,$tmp) = split(/\|/,$block);
|
---|
139 | ($cbp->{$plugin}->{'dirsandfiles'}->{$name}->{'uid'},$cbp->{$plugin}->{'dirsandfiles'}->{$name}->{'gid'},$cbp->{$plugin}->{'dirsandfiles'}->{$name}->{'mode'}) = split(/\,/,$tmp);
|
---|
140 | }
|
---|
141 | }
|
---|
142 | if ((defined $plist) && (defined $plist->{$plugin})) {
|
---|
143 | foreach my $name (split(/,/,$plist->{$plugin})) {
|
---|
144 | $cbp->{$plugin}->{'pkgs'}->{$name}->{'name'} = $name;
|
---|
145 | if ((defined $slist) && (defined $slist->{$name})) {
|
---|
146 | $cbp->{$plugin}->{'pkgs'}->{$name}->{'restart'} = $slist->{$name};
|
---|
147 | }
|
---|
148 | }
|
---|
149 | } else {
|
---|
150 | $cbp->{$plugin}->{'pkgs'}->{$plugin}->{'name'} = $plugin;
|
---|
151 | }
|
---|
152 | # Check remotely what conf files are needed for this plugin through its packages
|
---|
153 | $ssh2 = cb_ssh_init($remote,$machine,$debug) if (not defined $ssh2);
|
---|
154 |
|
---|
155 | my $chan = $ssh2->channel();
|
---|
156 | pb_log(3,"DEBUG: SSH2 chan called\n");
|
---|
157 | confess "Unable to create channel for $remote\@$machine: $!" if (not defined $chan);
|
---|
158 | if ($debug) {
|
---|
159 | pb_log(1,"DEBUG: launching a shell via Net:SSH2 ($remote\@$machine)\n");
|
---|
160 | }
|
---|
161 | confess "Unable to launch remote shell through Net:SSH2 ($remote\@$machine)" if (not $chan->shell());
|
---|
162 | pb_log(3,"DEBUG: SSH2 shell called\n");
|
---|
163 |
|
---|
164 | foreach my $p (keys $cbp->{$plugin}->{'pkgs'}) {
|
---|
165 | # TODO: Do not hardcode rpm
|
---|
166 | my $cmd = "sudo rpm -q -c --dump $p";
|
---|
167 | pb_log(2,"DEBUG: Calling $cmd\n");
|
---|
168 | print $chan "$cmd\n";
|
---|
169 | while (<$chan>) {
|
---|
170 | my ($name,$d1,$d2,$d3,$mode,$uid,$gid,$dummy) = split(/ /,$_);
|
---|
171 | $cbp->{$plugin}->{'files'}->{$name}->{'uid'} = $uid;
|
---|
172 | $cbp->{$plugin}->{'files'}->{$name}->{'gid'} = $gid;
|
---|
173 | $cbp->{$plugin}->{'files'}->{$name}->{'mode'} = substr($mode,4,);
|
---|
174 | pb_log(3,"DEBUG: Found $name");
|
---|
175 | }
|
---|
176 | }
|
---|
177 |
|
---|
178 | $chan->close();
|
---|
179 |
|
---|
180 | pb_log(2,"cbp: ".Dumper($cbp)."\n");
|
---|
181 | return($cbp);
|
---|
182 | }
|
---|
183 |
|
---|
184 | 1;
|
---|