| 1 | #!/usr/bin/perl -w |
|---|
| 2 | # |
|---|
| 3 | =head1 NAME |
|---|
| 4 | |
|---|
| 5 | cbusterize - Creates the correct CasparBuster structure in your CMS environment |
|---|
| 6 | |
|---|
| 7 | =head1 SYNOPSIS |
|---|
| 8 | |
|---|
| 9 | cbusterize [options] [--source /path/to/file/to/CasparBusterize | --plugin PluginName] |
|---|
| 10 | |
|---|
| 11 | Options: |
|---|
| 12 | --debug |-d debug mode |
|---|
| 13 | --help |-h brief help message |
|---|
| 14 | --man full documentation |
|---|
| 15 | --force |-f force copy of files, even if they exist |
|---|
| 16 | --source |-s <file/dir> directory or files to copy in the CasparBuster tree (',' separated if many) |
|---|
| 17 | --plugin |-p <plugin name> plugin defining what to copy in the CasparBuster tree (',' separated if many) |
|---|
| 18 | --machine|-m <machine> machine to consider in the subtree |
|---|
| 19 | |
|---|
| 20 | =head1 OPTIONS |
|---|
| 21 | |
|---|
| 22 | =over 4 |
|---|
| 23 | |
|---|
| 24 | =item B<--debug> |
|---|
| 25 | |
|---|
| 26 | Enter debug mode. This will print what would be done. No commands are executed, |
|---|
| 27 | so this is safe to use when testing. |
|---|
| 28 | |
|---|
| 29 | =item B<--help> |
|---|
| 30 | |
|---|
| 31 | Print a brief help message and exits. |
|---|
| 32 | |
|---|
| 33 | =item B<--man> |
|---|
| 34 | |
|---|
| 35 | Prints the manual page and exits. |
|---|
| 36 | |
|---|
| 37 | =item B<--machine> I<machine name> |
|---|
| 38 | |
|---|
| 39 | Specify the machine to consider when dealing with the CasparBuster structure. |
|---|
| 40 | The file will be taken from this machine, and a subdirectory named after the machine |
|---|
| 41 | will be used under the basedir to host the directory structure to manage |
|---|
| 42 | |
|---|
| 43 | =item B<--source> I<path> |
|---|
| 44 | |
|---|
| 45 | Specify the path to the source file or directory to manage with CasparBuster. Multiple paths can be specified separated by ','. |
|---|
| 46 | |
|---|
| 47 | =item B<--plugin> I<name> |
|---|
| 48 | |
|---|
| 49 | Specify the name of the plugin to manage with CasparBuster. Multiple plugins can be specified separated by ','. |
|---|
| 50 | A plugin defines a set of files (with their mode and owner), a set of directories (with their mode and owner) and a set of scripts to launch once the files are copied remotely. |
|---|
| 51 | |
|---|
| 52 | =back |
|---|
| 53 | |
|---|
| 54 | =head1 DESCRIPTION |
|---|
| 55 | |
|---|
| 56 | Creates a directory under the machine dir passed as parameter in working |
|---|
| 57 | directory or directory passed as parameter named like the last path |
|---|
| 58 | element of the parameter, and creates the standard CasparBuster setup |
|---|
| 59 | that refers to the parameter path in the new directory, and configuration |
|---|
| 60 | files when possible. It also copies the original config file into the new dir. |
|---|
| 61 | Is reasonably picky about path names, tries to avoid common errors. |
|---|
| 62 | |
|---|
| 63 | Schema looks like: |
|---|
| 64 | |
|---|
| 65 | Base dir |
|---|
| 66 | | |
|---|
| 67 | |- machine1 (optional) |
|---|
| 68 | | | |
|---|
| 69 | | |-- conf dir1 |
|---|
| 70 | | | | |
|---|
| 71 | | | |- conf file 1 |
|---|
| 72 | | [...] [...] |
|---|
| 73 | | |
|---|
| 74 | |- machine2 (optional) |
|---|
| 75 | | | |
|---|
| 76 | | |-- conf dir2 |
|---|
| 77 | | | | |
|---|
| 78 | | | |- conf file 2 |
|---|
| 79 | | [...] [...] |
|---|
| 80 | |
|---|
| 81 | Use of machines require use of option -m (if using cbusemachines in cb.conf) |
|---|
| 82 | If not, the conf dirs are directly attached to the base dir |
|---|
| 83 | |
|---|
| 84 | =head1 EXAMPLES |
|---|
| 85 | |
|---|
| 86 | # this will create the appropriate CasparBuster environment |
|---|
| 87 | # under the base ~/prj/musique-ancienne.org directory (Cf cbbasedir in cb.conf) |
|---|
| 88 | # containing the directory victoria2 for this machine |
|---|
| 89 | # under which it will copy the required structure if needed (/etc/ssh) |
|---|
| 90 | # to finaly put a copy of the file sshd_conf in it from the victoria2 machine |
|---|
| 91 | |
|---|
| 92 | cbusterize -m victoria2 -s /etc/ssh/sshd_config |
|---|
| 93 | |
|---|
| 94 | =head1 AUTHOR |
|---|
| 95 | |
|---|
| 96 | =over 4 |
|---|
| 97 | |
|---|
| 98 | Bruno Cornec, http://brunocornec.wordpress.com |
|---|
| 99 | |
|---|
| 100 | =back |
|---|
| 101 | |
|---|
| 102 | =head1 LICENSE |
|---|
| 103 | |
|---|
| 104 | Copyright (C) 2012 Bruno Cornec <bruno@project-builder.org> |
|---|
| 105 | Released under the GPLv2 or the Artistic license at your will. |
|---|
| 106 | |
|---|
| 107 | =cut |
|---|
| 108 | use strict; |
|---|
| 109 | use CasparBuster::Version; |
|---|
| 110 | use CasparBuster::Env; |
|---|
| 111 | use CasparBuster::Plugin; |
|---|
| 112 | use File::Basename; |
|---|
| 113 | use File::Path; |
|---|
| 114 | use Getopt::Long; |
|---|
| 115 | use Pod::Usage; |
|---|
| 116 | use Data::Dumper; |
|---|
| 117 | use Net::SSH2; |
|---|
| 118 | use Cwd; |
|---|
| 119 | use Archive::Tar; |
|---|
| 120 | use Carp; |
|---|
| 121 | use ProjectBuilder::Base; |
|---|
| 122 | use ProjectBuilder::Conf; |
|---|
| 123 | use ProjectBuilder::VCS; |
|---|
| 124 | |
|---|
| 125 | # settings |
|---|
| 126 | my $debug = 0; |
|---|
| 127 | my $help = undef; |
|---|
| 128 | my $man = undef; |
|---|
| 129 | my $source = undef; |
|---|
| 130 | my $machine = undef; |
|---|
| 131 | my $plugin = undef; |
|---|
| 132 | my $quiet = undef; |
|---|
| 133 | my $force = undef; |
|---|
| 134 | my $log = undef; |
|---|
| 135 | my $LOG = undef; |
|---|
| 136 | my $ssh2 = undef; |
|---|
| 137 | my $chan = undef; |
|---|
| 138 | |
|---|
| 139 | my ($cbver,$cbrev) = cb_version_init(); |
|---|
| 140 | my $appname = "cb"; |
|---|
| 141 | $ENV{'PBPROJ'} = $appname; |
|---|
| 142 | pb_temp_init(); |
|---|
| 143 | |
|---|
| 144 | # Initialize the syntax string |
|---|
| 145 | pb_syntax_init("$appname (aka CasparBuster) Version $cbver-$cbrev\n"); |
|---|
| 146 | |
|---|
| 147 | # parse command-line options |
|---|
| 148 | GetOptions( |
|---|
| 149 | 'machine|m=s' => \$machine, |
|---|
| 150 | 'debug|d+' => \$debug, |
|---|
| 151 | 'help|h' => \$help, |
|---|
| 152 | 'quiet|q' => \$quiet, |
|---|
| 153 | 'force|f' => \$force, |
|---|
| 154 | 'man' => \$man, |
|---|
| 155 | 'logfile|l=s' => \$log, |
|---|
| 156 | 'source|s=s' => \$source, |
|---|
| 157 | 'plugin|p=s' => \$plugin, |
|---|
| 158 | ) || pb_syntax(-1,0); |
|---|
| 159 | |
|---|
| 160 | if (defined $help) { |
|---|
| 161 | pb_syntax(0,1); |
|---|
| 162 | } |
|---|
| 163 | if (defined $man) { |
|---|
| 164 | pb_syntax(0,2); |
|---|
| 165 | } |
|---|
| 166 | if (defined $quiet) { |
|---|
| 167 | $debug=-1; |
|---|
| 168 | } |
|---|
| 169 | if (defined $log) { |
|---|
| 170 | open(LOG,"> $log") || die "Unable to log to $log: $!"; |
|---|
| 171 | $LOG = \*LOG; |
|---|
| 172 | $debug = 0 if ($debug == -1); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | $pbdebug = $debug; |
|---|
| 176 | pb_log_init($debug, $LOG); |
|---|
| 177 | pb_log(0,"Starting cbusterize\n"); |
|---|
| 178 | |
|---|
| 179 | # Get conf file in context |
|---|
| 180 | pb_conf_init($appname); |
|---|
| 181 | # The personal one if there is such |
|---|
| 182 | pb_conf_add("$ENV{'HOME'}/.cbrc") if (-f "$ENV{'HOME'}/.cbrc"); |
|---|
| 183 | # The system one |
|---|
| 184 | pb_conf_add(cb_env_conffile()); |
|---|
| 185 | |
|---|
| 186 | # Get configuration parameters |
|---|
| 187 | my %cb; |
|---|
| 188 | my $cb = \%cb; |
|---|
| 189 | ($cb->{'basedir'},$cb->{'usemachines'},$cb->{'cms'}) = pb_conf_get("cbbasedir","cbusemachines","cbcms"); |
|---|
| 190 | pb_log(2,"%cb: ",Dumper($cb)); |
|---|
| 191 | |
|---|
| 192 | # Check for mandatory params |
|---|
| 193 | pod2usage("Error: --source or --plugin is a mandatory argument\n") if ((not defined $source) && (not defined $plugin)); |
|---|
| 194 | pod2usage("Error: --machine is a mandatory argument when configure with cbusemachines = true\n") if (($cb->{'usemachines'}->{$appname} =~ /true/) && (not defined $machine)); |
|---|
| 195 | |
|---|
| 196 | if (defined $plugin) { |
|---|
| 197 | # Load plugins |
|---|
| 198 | cb_plugin_load(); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | my $basedir = $cb->{'basedir'}->{$appname}; |
|---|
| 202 | eval { $basedir =~ s/(\$ENV.+\})/$1/eeg }; |
|---|
| 203 | |
|---|
| 204 | pb_log(1, "DEBUG MODE, not doing anything, just printing\nDEBUG: basedir = $basedir\n"); |
|---|
| 205 | pb_log(1, "DEBUG: source = $source\n") if (defined $source); |
|---|
| 206 | pb_log(1, "DEBUG: machine = $machine\n") if (defined $machine); |
|---|
| 207 | |
|---|
| 208 | # Use potentially a remote account if defined |
|---|
| 209 | my $account = undef; |
|---|
| 210 | my $remote = undef; |
|---|
| 211 | ($account) = pb_conf_get_if("cbaccount") if (defined $machine); |
|---|
| 212 | $remote = $account->{$machine} if ((defined $account) && (defined $machine) && (defined $account->{$machine})); |
|---|
| 213 | pb_log(1, "DEBUG: remote account1 = $remote\n") if (defined $remote); |
|---|
| 214 | $remote = getpwuid($<) if (not defined $remote); |
|---|
| 215 | pb_log(1, "DEBUG: remote account2 = $remote\n"); |
|---|
| 216 | |
|---|
| 217 | # Create basedir if it doesn't exist |
|---|
| 218 | if (not -d $basedir) { |
|---|
| 219 | if ($debug) { |
|---|
| 220 | pb_log(1, "DEBUG: Creating recursively directory $basedir\n"); |
|---|
| 221 | } else { |
|---|
| 222 | pb_mkdir_p($basedir) || die "Unable to recursively create $basedir: $!"; |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | if (defined $source) { |
|---|
| 227 | foreach my $f (split(/,/,$source)) { |
|---|
| 228 | cb_busterize($f,"true"); |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | # Now handle plugins if any |
|---|
| 233 | my $cbp = (); |
|---|
| 234 | |
|---|
| 235 | if (defined $plugin) { |
|---|
| 236 | foreach my $p (split(/,/,$plugin)) { |
|---|
| 237 | pb_log(1,"Getting context for plugin $p\n"); |
|---|
| 238 | $cbp = cb_plugin_get($p,$cbp); |
|---|
| 239 | pb_log(2,"cbp: ".Dumper($cbp)."\n"); |
|---|
| 240 | foreach my $k (keys %{$cbp->{$plugin}->{'dirsandfiles'}}) { |
|---|
| 241 | cb_busterize($k,"true"); |
|---|
| 242 | } |
|---|
| 243 | foreach my $k ((keys %{$cbp->{$plugin}->{'dirs'}}),(keys %{$cbp->{$plugin}->{'files'}})) { |
|---|
| 244 | cb_busterize($k,"false"); |
|---|
| 245 | } |
|---|
| 246 | } |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | $ssh2->disconnect() if (defined $machine); |
|---|
| 250 | |
|---|
| 251 | sub cb_busterize { |
|---|
| 252 | |
|---|
| 253 | my $source = shift; |
|---|
| 254 | my $recur = shift; |
|---|
| 255 | |
|---|
| 256 | pb_log(2,"Entering cb_busterize source: $source\n"); |
|---|
| 257 | # Is the source a file or a dir ? Split the source parameter in 2 |
|---|
| 258 | my $srcdir = undef; |
|---|
| 259 | my $srcfile = undef; |
|---|
| 260 | my $cmd = undef; |
|---|
| 261 | my $sftp; |
|---|
| 262 | |
|---|
| 263 | if (not defined $machine) { |
|---|
| 264 | if (-d $source) { |
|---|
| 265 | $srcdir = $source; |
|---|
| 266 | } else { |
|---|
| 267 | $srcdir = dirname($source); |
|---|
| 268 | $srcfile = basename($source); |
|---|
| 269 | } |
|---|
| 270 | } else { |
|---|
| 271 | if (not defined $ssh2) { |
|---|
| 272 | pb_log(1,"DEBUG: First time so we need to create the SSH::Net2 object\n"); |
|---|
| 273 | $ssh2 = Net::SSH2->new(); |
|---|
| 274 | if ($debug >= 3) { |
|---|
| 275 | $ssh2->debug(1); |
|---|
| 276 | } |
|---|
| 277 | $ssh2->connect($machine) || confess "Unable to connect to $remote\@$machine: $!"; |
|---|
| 278 | my $hdir = (getpwnam(getpwuid($<)))[7]; |
|---|
| 279 | confess "Unable to connect to $remote\@$machine: $!" if (not $ssh2->auth_publickey($remote,"$hdir/.ssh/id_dsa.pub","$hdir/.ssh/id_dsa")); |
|---|
| 280 | $chan = $ssh2->channel(); |
|---|
| 281 | die "Unable to create channel for $remote\@$machine: $!" if (not defined $chan); |
|---|
| 282 | my ($code, $error_name, $error_string) = $ssh2->error(); |
|---|
| 283 | if ($code ne 0) { |
|---|
| 284 | pb_log(0,"code = $code"); |
|---|
| 285 | pb_log(0,"error_name = $error_name"); |
|---|
| 286 | pb_log(0,"error_string = $error_string"); |
|---|
| 287 | } |
|---|
| 288 | #$ssh2->blocking(0); |
|---|
| 289 | if ($debug) { |
|---|
| 290 | pb_log(1,"DEBUG: launching a shell via Net:SSH2 ($remote\@$machine)"); |
|---|
| 291 | } |
|---|
| 292 | confess "Unable to launch remote shell through Net:SSH2 ($remote\@$machine)" if (not $chan->shell()); |
|---|
| 293 | } |
|---|
| 294 | $sftp = $ssh2->sftp; |
|---|
| 295 | die "Unable to create sftp channel for $remote\@$machine: $!" if (not defined $sftp); |
|---|
| 296 | my %dirs = $sftp->stat("$source/."); |
|---|
| 297 | my $res = 0; |
|---|
| 298 | $res = -1 if (not defined $dirs{'mode'}); |
|---|
| 299 | pb_log(2,"DEBUG: Found res = $res\n"); |
|---|
| 300 | if ($res == 0) { |
|---|
| 301 | $srcdir = $source; |
|---|
| 302 | pb_log(1,"DEBUG: Found remote dir = $source\n"); |
|---|
| 303 | } else { |
|---|
| 304 | $srcdir = dirname($source); |
|---|
| 305 | $srcfile = basename($source); |
|---|
| 306 | pb_log(1,"DEBUG: Found remote file = $source\n"); |
|---|
| 307 | } |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | pb_log(1,"DEBUG: Found srcdir = $srcdir\n"); |
|---|
| 311 | if (defined $srcfile) { |
|---|
| 312 | pb_log(1,"DEBUG: Found srcfile = $srcfile\n"); |
|---|
| 313 | } else { |
|---|
| 314 | pb_log(1,"DEBUG: Found no srcfile\n"); |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | # Deduce the target directory from the local structure and the source |
|---|
| 318 | my $target = $basedir; |
|---|
| 319 | $target .= "/$machine" if defined ($machine); |
|---|
| 320 | $target .= "$srcdir"; |
|---|
| 321 | |
|---|
| 322 | my $scheme = $cb->{'cms'}->{$appname}; |
|---|
| 323 | |
|---|
| 324 | # If both source and target are dirs, then copy into the parent of the target |
|---|
| 325 | $target = basename($target) if ((not defined $srcfile) && (-d $target)); |
|---|
| 326 | |
|---|
| 327 | # Create target if it doesn't exist |
|---|
| 328 | if (not -d $target) { |
|---|
| 329 | if ($debug) { |
|---|
| 330 | pb_log(1,"DEBUG: Creating recursively directory $target\n"); |
|---|
| 331 | } else { |
|---|
| 332 | pb_mkdir_p($target) || confess "Unable to recursively create $target: $!"; |
|---|
| 333 | } |
|---|
| 334 | # Add all the dirs in it to VCS (in reverse order) |
|---|
| 335 | my $tdir = $target; |
|---|
| 336 | my @tab = (); |
|---|
| 337 | while ($tdir ne $basedir) { |
|---|
| 338 | push(@tab,$tdir); |
|---|
| 339 | $tdir = dirname($tdir); |
|---|
| 340 | pb_log(3,"tdir is now $tdir\n"); |
|---|
| 341 | } |
|---|
| 342 | if ($debug) { |
|---|
| 343 | pb_log(0,"INFO: Added to your $scheme system the dirs: ".join(' ',reverse(@tab))."\n"); |
|---|
| 344 | } else { |
|---|
| 345 | pb_vcs_add($scheme,reverse(@tab)); |
|---|
| 346 | } |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | # For local handling |
|---|
| 350 | my $cmdopt = ""; |
|---|
| 351 | # Recursive if we copy dirs |
|---|
| 352 | $cmdopt = "-r" if (not defined $srcfile); |
|---|
| 353 | $cmd = "cp -p $cmdopt $source $target"; |
|---|
| 354 | |
|---|
| 355 | if (defined $srcfile) { |
|---|
| 356 | # File case |
|---|
| 357 | if ((! -f "$target/$srcfile") || (defined $force)) { |
|---|
| 358 | # doesn't exist locally |
|---|
| 359 | if (defined $machine) { |
|---|
| 360 | # Remote |
|---|
| 361 | cb_ssh_do($remote,$source,$target,$debug); |
|---|
| 362 | } else { |
|---|
| 363 | # Local |
|---|
| 364 | if ($debug) { |
|---|
| 365 | pb_log(1,"DEBUG: launching $cmd\n"); |
|---|
| 366 | } else { |
|---|
| 367 | pb_system($cmd); |
|---|
| 368 | } |
|---|
| 369 | } |
|---|
| 370 | if ($debug) { |
|---|
| 371 | pb_log(1,"DEBUG: Adding $target/$srcfile to your $scheme system\n"); |
|---|
| 372 | } else { |
|---|
| 373 | pb_vcs_add($scheme,"$target/$srcfile"); |
|---|
| 374 | pb_log(0,"INFO: Created $target/$srcfile and added it to your $scheme system\n"); |
|---|
| 375 | } |
|---|
| 376 | } else { |
|---|
| 377 | pb_log(0,"INFO: File $target/$srcfile already there\n"); |
|---|
| 378 | } |
|---|
| 379 | } else { |
|---|
| 380 | # Directory case |
|---|
| 381 | if ($recur eq "true") { |
|---|
| 382 | # with files in it |
|---|
| 383 | if ((! -d "$target") || (defined $force)) { |
|---|
| 384 | # doesn't exist locally |
|---|
| 385 | if (defined $machine) { |
|---|
| 386 | # Remote |
|---|
| 387 | cb_ssh_do($remote,$source,$target,$debug); |
|---|
| 388 | } else { |
|---|
| 389 | # Local |
|---|
| 390 | if ($debug) { |
|---|
| 391 | pb_log(1,"DEBUG: launching $cmd\n"); |
|---|
| 392 | } else { |
|---|
| 393 | pb_system($cmd); |
|---|
| 394 | } |
|---|
| 395 | } |
|---|
| 396 | } else { |
|---|
| 397 | pb_log(0,"INFO: Directory $target already there\n"); |
|---|
| 398 | } |
|---|
| 399 | } else { |
|---|
| 400 | # Only deal with that dir, nothing below, so just created locally |
|---|
| 401 | if ($debug) { |
|---|
| 402 | pb_log(1,"DEBUG: mkdir -p $target\n"); |
|---|
| 403 | } else { |
|---|
| 404 | pb_mkdir_p("$target"); |
|---|
| 405 | } |
|---|
| 406 | } |
|---|
| 407 | if ($debug) { |
|---|
| 408 | pb_log(1,"DEBUG: Adding $target to your $scheme system\n"); |
|---|
| 409 | } else { |
|---|
| 410 | pb_vcs_add($scheme,"$target"); |
|---|
| 411 | pb_log(0,"INFO: Created $target and added it to your $scheme system\n"); |
|---|
| 412 | } |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | pb_log(2,"Exiting cb_busterize\n"); |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | sub cb_ssh_do { |
|---|
| 419 | |
|---|
| 420 | my $remote = shift; |
|---|
| 421 | my $source = shift; |
|---|
| 422 | my $target = shift; |
|---|
| 423 | my $debug = shift; |
|---|
| 424 | |
|---|
| 425 | # TODO: if sudo asks a passwd it won't work. |
|---|
| 426 | my $cmd = "sudo tar cvhf /tmp/cb.$$.tar $source\n"; |
|---|
| 427 | if ($debug) { |
|---|
| 428 | pb_log(1,"DEBUG: launching through Net:SSH2 ($remote\@$machine) $cmd"); |
|---|
| 429 | } |
|---|
| 430 | print $chan "$cmd"; |
|---|
| 431 | pb_log(1,"DEBUG: LINE : $_") while <$chan>; |
|---|
| 432 | $cmd = "sudo chmod 600 /tmp/cb.$$.tar\n"; |
|---|
| 433 | if ($debug) { |
|---|
| 434 | pb_log(1,"DEBUG: launching through Net:SSH2 ($remote\@$machine) $cmd"); |
|---|
| 435 | } |
|---|
| 436 | print $chan "$cmd"; |
|---|
| 437 | pb_log(1,"DEBUG: LINE : $_") while <$chan>; |
|---|
| 438 | $cmd = "sudo chown $remote /tmp/cb.$$.tar\n"; |
|---|
| 439 | if ($debug) { |
|---|
| 440 | pb_log(1,"DEBUG: launching through Net:SSH2 ($remote\@$machine) $cmd"); |
|---|
| 441 | } |
|---|
| 442 | print $chan "$cmd"; |
|---|
| 443 | pb_log(1,"DEBUG: LINE : $_") while <$chan>; |
|---|
| 444 | if ($debug) { |
|---|
| 445 | pb_log(1,"DEBUG: gettting through Net:SSH2 ($remote\@$machine) /tmp/cb.$$.tar\n"); |
|---|
| 446 | } |
|---|
| 447 | $ssh2->scp_get("/tmp/cb.$$.tar","/tmp/cb.$$.tar"); |
|---|
| 448 | if ($debug) { |
|---|
| 449 | pb_log(1,"DEBUG: erasing through Net:SSH2 ($remote\@$machine) /tmp/cb.$$.tar\n"); |
|---|
| 450 | } else { |
|---|
| 451 | print $chan "sudo rm -f /tmp/cb.$$.tar\n"; |
|---|
| 452 | } |
|---|
| 453 | my $tar = Archive::Tar->new("/tmp/cb.$$.tar"); |
|---|
| 454 | $tar->setcwd($target); |
|---|
| 455 | if ($debug) { |
|---|
| 456 | pb_log(1,"DEBUG: Extracting /tmp/cb.$$.tar\n"); |
|---|
| 457 | foreach my $f ($tar->list_files()) { |
|---|
| 458 | pb_log(1,"DEBUG: $f\n"); |
|---|
| 459 | } |
|---|
| 460 | } else { |
|---|
| 461 | $tar->extract(); |
|---|
| 462 | } |
|---|
| 463 | if ($debug) { |
|---|
| 464 | pb_log(1,"DEBUG: cleanup\n"); |
|---|
| 465 | } else { |
|---|
| 466 | $tar->clear; |
|---|
| 467 | unlink("/tmp/cb.$$.tar"); |
|---|
| 468 | } |
|---|
| 469 | } |
|---|