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

Revision 1679, 4.3 KB checked in by bruno, 6 months ago (diff)
  • Start working on plugins
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}
67
68
69=item B<cb_plugin_get>
70
71This function adds into the plugin hash, passed as second parameter, the new plugin content based on its name, passed as first parameter.
72
73=cut
74
75sub cb_plugin_get {
76
77my $plugin = shift;
78my $cbp = shift;
79my $remote = shift;
80my $machine = shift;
81my $debug = shift;
82my $ssh2 = shift;
83
84pb_log(2,"Entering cb_plugin_get for plugin $plugin\n");
85my ($flist,$dlist,$dflist,$slist,$plist) = pb_conf_get_if("cbpluginfiles","cbplugindirs","cbplugindirsandfiles","cbppkgreload","cbpluginpkgs");
86if ((defined $flist) && (defined $flist->{$plugin}) && ($flist->{$plugin} !~ /^\s*$/)) {
87        foreach my $block (split(/;/,$flist->{$plugin})) {
88                pb_log(3,"block : $block\n");
89                my ($name,$tmp) = split(/\|/,$block);
90                ($cbp->{$plugin}->{'files'}->{$name}->{'uid'},$cbp->{$plugin}->{'files'}->{$name}->{'gid'},$cbp->{$plugin}->{'files'}->{$name}->{'mode'}) = split(/\,/,$tmp);
91        }
92}
93if ((defined $dlist) && (defined $dlist->{$plugin}) && ($dlist->{$plugin} !~ /^\s*$/)) {
94        foreach my $block (split(/;/,$dlist->{$plugin})) {
95                pb_log(3,"block : $block\n");
96                my ($name,$tmp) = split(/\|/,$block);
97                ($cbp->{$plugin}->{'dirs'}->{$name}->{'uid'},$cbp->{$plugin}->{'dirs'}->{$name}->{'gid'},$cbp->{$plugin}->{'dirs'}->{$name}->{'mode'}) = split(/\,/,$tmp);
98        }
99}
100if ((defined $dflist) && (defined $dflist->{$plugin}) && ($dflist->{$plugin} !~ /^\s*$/)) {
101        foreach my $block (split(/;/,$dflist->{$plugin})) {
102                pb_log(3,"block : $block\n");
103                my ($name,$tmp) = split(/\|/,$block);
104                ($cbp->{$plugin}->{'dirsandfiles'}->{$name}->{'uid'},$cbp->{$plugin}->{'dirsandfiles'}->{$name}->{'gid'},$cbp->{$plugin}->{'dirsandfiles'}->{$name}->{'mode'}) = split(/\,/,$tmp);
105        }
106}
107if ((defined $plist) && (defined $plist->{$plugin})) {
108        foreach my $name (split(/,/,$plist->{$plugin})) {
109                $cbp->{$plugin}->{'pkgs'}->{$name}->{'name'} = $name;
110                if ((defined $slist) && (defined $slist->{$name})) {
111                        $cbp->{$plugin}->{'pkgs'}->{$name}->{'restart'} = $slist->{$name};
112                }
113        }
114} else {
115        $cbp->{$plugin}->{'pkgs'}->{$plugin}->{'name'} = $plugin;
116}
117# Check remotely what conf files are needed for this plugin through its packages
118$ssh2 = cb_ssh_init($remote,$machine,$debug) if (not defined $ssh2);
119
120my $chan = $ssh2->channel();
121pb_log(3,"DEBUG: SSH2 chan called\n");
122confess "Unable to create channel for $remote\@$machine: $!" if (not defined $chan);
123if ($debug) {
124        pb_log(1,"DEBUG: launching a shell via Net:SSH2 ($remote\@$machine)\n");
125}
126confess "Unable to launch remote shell through Net:SSH2 ($remote\@$machine)" if (not $chan->shell());
127pb_log(3,"DEBUG: SSH2 shell called\n");
128
129foreach my $p (keys $cbp->{$plugin}->{'pkgs'}) {
130        # TODO: Do not hardcode rpm
131        my $cmd = "sudo rpm -q -c --dump $p";
132        pb_log(2,"DEBUG: Calling $cmd\n");
133        print $chan "$cmd\n";
134        while (<$chan>) {
135                my ($name,$d1,$d2,$d3,$mode,$uid,$gid,$dummy) = split(/ /,$_);
136                $cbp->{$plugin}->{'files'}->{$name}->{'uid'} = $uid;
137                $cbp->{$plugin}->{'files'}->{$name}->{'gid'} = $gid;
138                $cbp->{$plugin}->{'files'}->{$name}->{'mode'} = substr($mode,4,);
139                pb_log(3,"DEBUG: Found $name");
140        }
141}
142
143$chan->close();
144
145pb_log(2,"cbp: ".Dumper($cbp)."\n");
146return($cbp);
147}
148
1491;
Note: See TracBrowser for help on using the repository browser.