- Timestamp:
- Apr 29, 2012, 7:19:37 PM (13 years ago)
- Location:
- projects/casparbuster/devel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
projects/casparbuster/devel/bin/cb
r1489 r1490 89 89 use Pod::Usage; 90 90 use Data::Dumper; 91 use Time::Local; 92 use Net::SSH2; 91 93 use ProjectBuilder::Base; 92 94 use ProjectBuilder::Conf; … … 187 189 { RaiseError => 1, AutoCommit => 1 }) 188 190 || die "Unable to connect to $db"; 191 my $sth; 189 192 190 193 if ($precmd ne "") { 191 my$sth = $dbh->prepare(qq{$precmd}) || die "Unable to create table into $db";194 $sth = $dbh->prepare(qq{$precmd}) || die "Unable to create table into $db"; 192 195 if ($debug) { 193 196 pb_log(1,"DEBUG: Creating DB $db\n"); … … 224 227 225 228 # Cleanup 226 pb_rm_rf($dest); 229 if (not $debug) { 230 pb_rm_rf($dest); 231 } else { 232 pb_log(0,"DEBUG: Please remove manually with rm -rf $dest\n") 233 } 227 234 $dbh->disconnect; 228 235 … … 237 244 238 245 # Use potentially a remote account if defined 239 my $account = undef; 240 my $remote = $machine; 241 ($account) = pb_conf_get_if("cbaccount") if (defined $machine); 242 $remote = $account->{$machine}."@".$machine if ((defined $account) && (defined $account->{$machine})); 243 pb_log(1, "DEBUG: remote = $remote\n") if (defined $remote); 246 my $remote = undef; 247 my ($account) = pb_conf_get_if("cbaccount") if (defined $machine); 248 $remote = $account->{$machine} if ((defined $account) && (defined $machine) && (defined $account->{$machine})); 249 pb_log(1, "DEBUG: remote account1 = $remote\n") if (defined $remote); 250 $remote = getpwuid($<) if (not defined $remote); 251 pb_log(1, "DEBUG: remote account2 = $remote\n"); 244 252 245 253 # Now handle plugins if any … … 298 306 my $mac = $machine; 299 307 $mac = "localhost" if (not defined $machine); 300 my $all = $dbh->selectall_arrayref("SELECT id,date,file,machine FROM dates WHERE machine=$mac"); 301 # Check what in cbp is in the DB and deploy only if necessary 308 # Allow for errors to occur at DBI level 309 $dbh->{RaiseError} = 0; 310 my $checkdb = 1; 311 my $dbcmd = "SELECT id,date,file,machine FROM dates WHERE machine=\"$mac\""; 312 if (! ($sth = $dbh->prepare(qq{$dbcmd}))) { 313 pb_log(0,"Unable to prepare DB statement $dbcmd\n"); 314 $checkdb = 0; 315 } 316 # DisAllow for errors to occur at DBI level 317 $dbh->{RaiseError} = 1; 318 my $dbid = (); 319 if ($checkdb == 1) { 320 $sth->execute(); 321 # Check what in cbp is in the DB and deploy only if necessary 322 foreach my $k (keys %{$cbp}) { 323 foreach my $type ('files','dirs') { 324 foreach my $o (keys %{$cbp->{$k}->{$type}}) { 325 # Compare with info from DB 326 foreach my $row ($sth->fetch) { 327 next if (not defined $row); 328 my ($id, $date, $file, $mac1) = @$row; 329 # If less recent than in the DB remove it 330 $cbp->{$k}->{$type}->{$o}->{'deleted'} = "true" if ((defined $file) && ($file eq $o) && ($date > $cbp->{$k}->{$type}->{$o}->{'mtime'})); 331 $dbid->{$o} = $id; 332 } 333 } 334 } 335 } 336 $sth->finish(); 337 } 338 pb_log(2,"INFO: cleaned cbp: ".Dumper($cbp)."\n"); 339 340 # Now create a tar containing all the relevant content 341 # We need to loop separately to allow for DB to not exist in the previous loop ! 342 my $tdir = undef; 343 if (defined $machine) { 344 $tdir = "$dest/$machine"; 345 } else { 346 $tdir = "$dest"; 347 } 348 chdir("$tdir") || die "ERROR: Unable to chdir to $tdir\n"; 349 pb_log(2,"Working now under $tdir\n"); 350 351 my $tar = Archive::Tar->new; 352 $tar->setcwd($tdir); 353 my $curdate = time(); 302 354 foreach my $k (keys %{$cbp}) { 303 355 foreach my $type ('files','dirs') { 304 foreach my $o (keys %{$cbp->{$k}->{$type}}) { 305 # Compare with info from DB 306 foreach my $row (@$all) { 307 my ($id, $date, $file, $mac1) = @$row; 308 # If less recent than in the DB remove it 309 delete($cbp->{$k}->{$type}->{$o}) if (($file eq $o) && ($date > $cbp->{$k}->{$type}->{$o}->{'mtime'})); 356 foreach my $o ((keys %{$cbp->{$k}->{$type}})) { 357 if (not defined $cbp->{$k}->{$type}->{$o}->{'deleted'}) { 358 $tar->add_files("./$o"); 359 # Add an entry to the DB 360 if (defined $dbid->{$o}) { 361 # Modify an existing entry 362 $dbcmd = "UPDATE dates SET date=$curdate,file=$o WHERE id='?'"; 363 if (not $debug) { 364 $sth = $dbh->prepare(qq{$dbcmd}); 365 $sth = $dbh->execute($dbid->{$o}); 366 } else { 367 pb_log(0,"Executing in DB: $dbcmd with curdate=$curdate,file=$o,id=$dbid->{$o}\n"); 368 } 369 } else { 370 # Add an new entry 371 $dbcmd = "INSERT INTO dates VALUES (NULL,?,?,$mac)"; 372 if (not $debug) { 373 $sth = $dbh->prepare(qq{$dbcmd}); 374 $sth = $dbh->execute($curdate,$o); 375 } else { 376 pb_log(0,"Executing in DB: $dbcmd with curdate=$curdate,file=$o,machine=$mac\n"); 377 } 378 } 379 if (not $debug) { 380 $sth->finish(); 381 } 310 382 } 311 383 } 312 384 } 313 385 } 314 pb_log(2,"INFO: cleaned cbp: ".Dumper($cbp)."\n"); 315 316 # Now create a tar containing all the relevant content 317 my $tar = Archive::Tar->new; 386 my $tarfile = "$ENV{'TMPDIR'}/cbcontent$$.tar"; 387 $tar->write("$tarfile"); 388 389 my $ssh2; 390 my $chan; 391 392 # deal with content first 393 if (defined $machine) { 394 # Create remote connection and copy tar file there 395 $ssh2 = Net::SSH2->new(); 396 $ssh2->connect($machine); 397 my $hdir = (getpwnam(getpwuid($<)))[7]; 398 if ($ssh2->auth_publickey($remote,"$hdir/.ssh/id_dsa.pub","$hdir/.ssh/id_dsa")) { 399 $chan = $ssh2->channel(); 400 if (not $debug) { 401 $chan->exec("if [ ! -d $ENV{'TMPDIR'} ]; then mkdir -p $ENV{'TMPDIR'} fi"); 402 $ssh2->scp_put($tarfile,$ENV{'TMPDIR'}); 403 #$chan->exec("cd / ; tar xf $tarfile"); 404 } else { 405 pb_log(1,"INFO: creating $ENV{'TMPDIR'} if needed on $remote\@$machine and copying content\n"); 406 } 407 } else { 408 pb_log(0,"ERROR: Unable to authenticate to $remote\@$machine\n"); 409 return; 410 } 411 } 412 413 # Pointer to function depending whether we're local or remote 414 my $func; 415 if (defined $machine) { 416 $func = \&{ $chan->exec }; 417 } else { 418 $func = \&pb_system; 419 } 420 421 if (not $debug) { 422 &$func("cd / ; tar xf $tarfile"); 423 } else { 424 pb_log(1,"INFO: Extracting (on $mac) $tarfile under /\n"); 425 } 426 318 427 foreach my $k (keys %{$cbp}) { 319 $tar->add_files((keys %{$cbp->{$k}->{'files'}}),(keys %{$cbp->{$k}->{'dirs'}})); 320 # Add an entryo to the DB 321 } 322 my $tarfile = "$ENV{'TMPDIR'}/content$$.tar"; 323 $tar->write("$tarfile"); 324 325 my $cmd = ""; 326 # Copy the tar file and extract it + set up modes/uids/gids 428 foreach my $type ('files','dirs') { 429 foreach my $o ((keys %{$cbp->{$k}->{$type}})) { 430 if (not defined $cbp->{$k}->{$type}->{$o}->{'deleted'}) { 431 if ($debug) { 432 pb_log(1,"INFO: Executing (on $mac) sudo chown $cbp->{$k}->{$type}->{$o}->{'uid'}:$cbp->{$k}->{$type}->{$o}->{'gid'} $o\n"); 433 pb_log(1,"INFO: Executing (on $mac) sudo chmod $cbp->{$k}->{$type}->{$o}->{'mode'} $o\n"); 434 } else { 435 &$func("sudo chown $cbp->{$k}->{$type}->{$o}->{'uid'}:$cbp->{$k}->{$type}->{$o}->{'gid'} $o"); 436 &$func("sudo chmod $cbp->{$k}->{$type}->{$o}->{'mode'} $o"); 437 } 438 } 439 } 440 } 441 if (defined $cbp->{$k}->{'reloadscript'}) { 442 if ($debug) { 443 pb_log(1,"INFO: Executing (on $mac) sudo $cbp->{$k}->{'reloadscript'}\n"); 444 } else { 445 &$func("sudo $cbp->{$k}->{'reloadscript'}"); 446 } 447 } 448 } 449 327 450 if (defined $machine) { 328 $cmd = "scp -p -q $tarfile $remote:/tmp";329 } else { 330 $ cmd = "cp -p $source /tmp";331 } 332 333 if ($debug) { 334 pb_log(1,"DEBUG: launching $cmd\n"); 335 } else { 336 pb_system($cmd); 337 pb_log(0," INFO: \n");451 # Remote cleanup 452 $chan->exec("rm -rf $ENV{'TMPDIR'}"); 453 $ssh2->disconnect(); 454 } 455 456 # Cleanup 457 if (not $debug) { 458 unlink("$tarfile"); 459 } else { 460 pb_log(0,"DEBUG: Please remove manually with rm -f $tarfile\n") 338 461 } 339 462 pb_log(2,"Exiting cb_distribute\n"); … … 342 465 sub cb_add_to_cbp { 343 466 467 pb_log(3,"Entering into cb_addto_cbp\n"); 344 468 my $type = 'files'; 345 469 if (-d $File::Find::name) { -
projects/casparbuster/devel/lib/CasparBuster/Plugin.pm
r1489 r1490 77 77 my $cbp = shift; 78 78 79 pb_log(2,"Entering cb_plugin_get for plugin $plugin\n"); 79 80 my ($flist,$dlist,$slist) = pb_conf_get_if("cbpluginfiles","cbplugindirs","cbpluginreload"); 80 81 if ((defined $flist) && (defined $flist->{$plugin}) && ($flist->{$plugin} !~ /^\s*$/)) {
Note:
See TracChangeset
for help on using the changeset viewer.