| 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 | |
|---|
| 68 | |
|---|
| 69 | =item B<cb_plugin_get> |
|---|
| 70 | |
|---|
| 71 | This 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 | |
|---|
| 75 | sub cb_plugin_get { |
|---|
| 76 | |
|---|
| 77 | my $plugin = shift; |
|---|
| 78 | my $cbp = shift; |
|---|
| 79 | my $remote = shift; |
|---|
| 80 | my $machine = shift; |
|---|
| 81 | my $debug = shift; |
|---|
| 82 | my $ssh2 = shift; |
|---|
| 83 | |
|---|
| 84 | pb_log(2,"Entering cb_plugin_get for plugin $plugin\n"); |
|---|
| 85 | my ($flist,$dlist,$dflist,$slist,$plist) = pb_conf_get_if("cbpluginfiles","cbplugindirs","cbplugindirsandfiles","cbppkgreload","cbpluginpkgs"); |
|---|
| 86 | if ((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 | } |
|---|
| 93 | if ((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 | } |
|---|
| 100 | if ((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 | } |
|---|
| 107 | if ((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 | |
|---|
| 120 | my $chan = $ssh2->channel(); |
|---|
| 121 | pb_log(3,"DEBUG: SSH2 chan called\n"); |
|---|
| 122 | confess "Unable to create channel for $remote\@$machine: $!" if (not defined $chan); |
|---|
| 123 | if ($debug) { |
|---|
| 124 | pb_log(1,"DEBUG: launching a shell via Net:SSH2 ($remote\@$machine)\n"); |
|---|
| 125 | } |
|---|
| 126 | confess "Unable to launch remote shell through Net:SSH2 ($remote\@$machine)" if (not $chan->shell()); |
|---|
| 127 | pb_log(3,"DEBUG: SSH2 shell called\n"); |
|---|
| 128 | |
|---|
| 129 | foreach 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 | |
|---|
| 145 | pb_log(2,"cbp: ".Dumper($cbp)."\n"); |
|---|
| 146 | return($cbp); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | 1; |
|---|