source: ProjectBuilder/projects/casparbuster/devel/lib/CasparBuster/Plugin.pm@ 1765

Last change on this file since 1765 was 1765, checked in by Bruno Cornec, 11 years ago
  • Adds support for Debian 7.0 to some projects
  • latest cb commits
  • mindi 2.1.5 announce
File size: 5.6 KB
Line 
1#
2# Manages Plugins for CasparBuster
3#
4# $Id$
5#
6#
7package CasparBuster::Plugin;
8
9use strict;
10use warnings;
11use Carp;
12use CasparBuster::Env;
13use ProjectBuilder::Base;
14use ProjectBuilder::Conf;
15use Data::Dumper;
16
17# Global vars
18# Inherit from the "Exporter" module which handles exporting functions.
19#
20use vars qw($VERSION $REVISION @ISA @EXPORT);
21use Exporter;
22#
23# Export, by default, all the functions into the namespace of
24# any code which uses this module.
25
26our @ISA = qw(Exporter);
27our @EXPORT = qw(cb_plugin_load cb_plugin_get);
28
29=pod
30
31=head1 NAME
32
33CasparBuster::Plugin - module dealing with CasparBuster plugin management
34
35=head1 DESCRIPTION
36
37This 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
49This function loads all the plugins defined for this CasparBuster environement
50
51=cut
52
53sub cb_plugin_load {
54
55my ($pluginsdir) = pb_conf_get("cbpluginssubdir");
56my $cbconfdir = cb_env_confdir()."/$pluginsdir->{$ENV{'PBPROJ'}}";
57opendir(DIR,$cbconfdir) || die "Unable to open $cbconfdir: $!";
58foreach 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}
65closedir(DIR);
66
67my ($flist,$dlist,$dflist,$slist) = pb_conf_get_if("cbpluginfiles","cbplugindirs","cbplugindirsandfiles","cbppkgreload");
68if (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}
77if (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}
86if (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}
95if (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
106This 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
110sub cb_plugin_get {
111
112my $plugin = shift;
113my $cbp = shift;
114my $remote = shift;
115my $machine = shift;
116my $debug = shift;
117my $ssh2 = shift;
118
119pb_log(2,"Entering cb_plugin_get for plugin $plugin\n");
120my ($flist,$dlist,$dflist,$slist,$plist) = pb_conf_get_if("cbpluginfiles","cbplugindirs","cbplugindirsandfiles","cbppkgreload","cbpluginpkgs");
121if ((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}
128if ((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}
135if ((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}
142if ((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
155my $chan = $ssh2->channel();
156pb_log(3,"DEBUG: SSH2 chan called\n");
157confess "Unable to create channel for $remote\@$machine: $!" if (not defined $chan);
158if ($debug) {
159 pb_log(1,"DEBUG: launching a shell via Net:SSH2 ($remote\@$machine)\n");
160}
161confess "Unable to launch remote shell through Net:SSH2 ($remote\@$machine)" if (not $chan->shell());
162pb_log(3,"DEBUG: SSH2 shell called\n");
163
164foreach 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
180pb_log(2,"cbp: ".Dumper($cbp)."\n");
181return($cbp);
182}
183
1841;
Note: See TracBrowser for help on using the repository browser.