1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | =head1 NAME
|
---|
4 |
|
---|
5 | cb - CasparBuster looks at the structure in your CMS environment and deploy it to the target systems as needed
|
---|
6 |
|
---|
7 | =head1 SYNOPSIS
|
---|
8 |
|
---|
9 | cb [options]
|
---|
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 from the CasparBuster tree (',' separated if many) to the target
|
---|
17 | --plugin |-p <plugin name> plugin defining what to copy from the CasparBuster tree (',' separated if many) to the target
|
---|
18 | --machine|-m <machine> machine to deploy on.
|
---|
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 files will be pushed to this machine, and a subdirectory named after the machine
|
---|
41 | will be used under the basedir to look at the directory structure to deploy
|
---|
42 |
|
---|
43 | =item B<--source> I<path>
|
---|
44 |
|
---|
45 | Specify the path of the source file or directory to deploy 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 deploy 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 | Deploy the standard CasparBuster structure created by I<cbusterize>. It will reinstall all files and directory in the plugin, with correct owner, group and mode, and launch at the end the script to re-enable potentially the service using the updated files.
|
---|
57 |
|
---|
58 | =head1 EXAMPLES
|
---|
59 |
|
---|
60 | # this will deploy the appropriate CasparBuster environment for DHCP
|
---|
61 | # from the base ~/prj/musique-ancienne.org directory (Cf cbbasedir in cb.conf)
|
---|
62 | # containing the directory victoria2 for this machine
|
---|
63 | # to which it will copy the required files
|
---|
64 |
|
---|
65 | cb -m victoria2 -p dhcpd
|
---|
66 |
|
---|
67 | =head1 AUTHOR
|
---|
68 |
|
---|
69 | =over 4
|
---|
70 |
|
---|
71 | Bruno Cornec, http://brunocornec.wordpress.com
|
---|
72 |
|
---|
73 | =back
|
---|
74 |
|
---|
75 | =head1 LICENSE
|
---|
76 |
|
---|
77 | Copyright (C) 2012 Bruno Cornec <bruno@project-builder.org>
|
---|
78 | Released under the GPLv2 or the Artistic license at your will.
|
---|
79 |
|
---|
80 | =cut
|
---|
81 | use strict;
|
---|
82 | use CasparBuster::Version;
|
---|
83 | use CasparBuster::Env;
|
---|
84 | use CasparBuster::Plugin;
|
---|
85 | #use Cwd 'realpath';
|
---|
86 | use File::Find;
|
---|
87 | use Archive::Tar;
|
---|
88 | use Getopt::Long;
|
---|
89 | use Pod::Usage;
|
---|
90 | use Data::Dumper;
|
---|
91 | use Time::Local;
|
---|
92 | use Net::SSH2;
|
---|
93 | use ProjectBuilder::Base;
|
---|
94 | use ProjectBuilder::Conf;
|
---|
95 | use ProjectBuilder::VCS;
|
---|
96 | use DBI;
|
---|
97 | use DBD::SQLite;
|
---|
98 |
|
---|
99 | # settings
|
---|
100 | my $debug = 0;
|
---|
101 | my $help = undef;
|
---|
102 | my $man = undef;
|
---|
103 | my $source = undef;
|
---|
104 | my $machine = undef;
|
---|
105 | my $plugin = undef;
|
---|
106 | my $quiet = undef;
|
---|
107 | my $force = undef;
|
---|
108 | my $log = undef;
|
---|
109 | my $LOG = undef;
|
---|
110 |
|
---|
111 | my ($cbver,$cbrev) = cb_version_init();
|
---|
112 | my $appname = "cb";
|
---|
113 | $ENV{'PBPROJ'} = $appname;
|
---|
114 | pb_temp_init();
|
---|
115 |
|
---|
116 | # Initialize the syntax string
|
---|
117 | pb_syntax_init("$appname (aka CasparBuster) Version $cbver-$cbrev\n");
|
---|
118 |
|
---|
119 | # parse command-line options
|
---|
120 | GetOptions(
|
---|
121 | 'machine|m=s' => \$machine,
|
---|
122 | 'debug|d+' => \$debug,
|
---|
123 | 'help|h' => \$help,
|
---|
124 | 'quiet|q' => \$quiet,
|
---|
125 | 'force|f' => \$force,
|
---|
126 | 'man' => \$man,
|
---|
127 | 'logfile|l=s' => \$log,
|
---|
128 | 'source|s=s' => \$source,
|
---|
129 | 'plugin|p=s' => \$plugin,
|
---|
130 | ) || pb_syntax(-1,0);
|
---|
131 |
|
---|
132 | if (defined $help) {
|
---|
133 | pb_syntax(0,1);
|
---|
134 | }
|
---|
135 | if (defined $man) {
|
---|
136 | pb_syntax(0,2);
|
---|
137 | }
|
---|
138 | if (defined $quiet) {
|
---|
139 | $debug=-1;
|
---|
140 | }
|
---|
141 | if (defined $log) {
|
---|
142 | open(LOG,"> $log") || die "Unable to log to $log: $!";
|
---|
143 | $LOG = \*LOG;
|
---|
144 | $debug = 0 if ($debug == -1);
|
---|
145 | }
|
---|
146 |
|
---|
147 | $pbdebug = $debug;
|
---|
148 | pb_log_init($debug, $LOG);
|
---|
149 | pb_log(0,"Starting cb\n");
|
---|
150 |
|
---|
151 | # Get conf file in context
|
---|
152 | pb_conf_init($appname);
|
---|
153 | # The personal one if there is such
|
---|
154 | pb_conf_add("$ENV{'HOME'}/.cbrc") if (-f "$ENV{'HOME'}/.cbrc");
|
---|
155 | # The system one
|
---|
156 | pb_conf_add(cb_env_conffile());
|
---|
157 |
|
---|
158 | # Get configuration parameters
|
---|
159 | my %cb;
|
---|
160 | my $cbp = ();
|
---|
161 | my $cb = \%cb;
|
---|
162 | ($cb->{'basedir'},$cb->{'usemachines'},$cb->{'cms'},$cb->{'database'}) = pb_conf_get("cbbasedir","cbusemachines","cbcms","cbdatabase");
|
---|
163 | pb_log(2,"%cb: ",Dumper($cb));
|
---|
164 |
|
---|
165 | die "No machine should be given when using machine structure" if (($cb->{'usemachines'}->{$appname} !~ /true/) && (defined $machine));
|
---|
166 |
|
---|
167 | if (defined $plugin) {
|
---|
168 | # Load plugins
|
---|
169 | cb_plugin_load();
|
---|
170 | }
|
---|
171 |
|
---|
172 | my $basedir = $cb->{'basedir'}->{$appname};
|
---|
173 | eval { $basedir =~ s/(\$ENV.+\})/$1/eeg };
|
---|
174 |
|
---|
175 | # Create basedir if it doesn't exist
|
---|
176 | die "Unable to find base directory at $basedir" if (not -d $basedir);
|
---|
177 |
|
---|
178 | pb_log(1, "DEBUG MODE, not doing anything, just printing\nDEBUG: basedir = $basedir\n");
|
---|
179 |
|
---|
180 | # Create database if not existing and give a handler
|
---|
181 | my $db = "$basedir/$cb->{'database'}->{$appname}";
|
---|
182 |
|
---|
183 | my $precmd = "";
|
---|
184 | if (! -f $db) {
|
---|
185 | $precmd = "CREATE TABLE dates (id INTEGER PRIMARY KEY AUTOINCREMENT, date INTEGER, file VARCHAR[65535], machine VARCHAR[65535])";
|
---|
186 | }
|
---|
187 |
|
---|
188 | my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
|
---|
189 | { RaiseError => 1, AutoCommit => 1 })
|
---|
190 | || die "Unable to connect to $db";
|
---|
191 | my $sth;
|
---|
192 |
|
---|
193 | if ($precmd ne "") {
|
---|
194 | $sth = $dbh->prepare(qq{$precmd}) || die "Unable to create table into $db";
|
---|
195 | if ($debug) {
|
---|
196 | pb_log(1,"DEBUG: Creating DB $db\n");
|
---|
197 | pb_log(1,"DEBUG: with command $precmd\n");
|
---|
198 | } else {
|
---|
199 | $sth->execute();
|
---|
200 | }
|
---|
201 | $sth->finish();
|
---|
202 | }
|
---|
203 |
|
---|
204 | # Define destination dir and populate with a VCS export
|
---|
205 | my $dest = "$ENV{'TMPDIR'}/vcs.$$";
|
---|
206 | my $scheme = $cb->{'cms'}->{$appname};
|
---|
207 | pb_vcs_export(pb_vcs_get_uri($scheme,$basedir),$basedir,$dest);
|
---|
208 |
|
---|
209 | # Now distribute to the right machines
|
---|
210 | if (defined $machine) {
|
---|
211 | cb_distribute($machine);
|
---|
212 | } else {
|
---|
213 | if ($cb->{'usemachines'}->{$appname} =~ /true/) {
|
---|
214 | # First dir level is the machine, then the content
|
---|
215 | opendir(DIR,$dest) || die "Unable to open $dest: $!";
|
---|
216 | foreach my $m (readdir(DIR)) {
|
---|
217 | next if ($m =~ /^\./);
|
---|
218 | next if (! -d $m);
|
---|
219 | # Machine name
|
---|
220 | cb_distribute($m);
|
---|
221 | }
|
---|
222 | closedir(DIR);
|
---|
223 | } else {
|
---|
224 | cb_distribute(undef);
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 | # Cleanup
|
---|
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 | }
|
---|
234 | $dbh->disconnect;
|
---|
235 |
|
---|
236 | # End of Main
|
---|
237 |
|
---|
238 | # Distribute files to target machines
|
---|
239 | sub cb_distribute {
|
---|
240 |
|
---|
241 | my $machine = shift;
|
---|
242 |
|
---|
243 | pb_log(2,"Entering into cb_distribute with machine $machine\n");
|
---|
244 |
|
---|
245 | # Use potentially a remote account if defined
|
---|
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");
|
---|
252 |
|
---|
253 | # Now handle plugins if any
|
---|
254 | if (defined $plugin) {
|
---|
255 | foreach my $p (split(/,/,$plugin)) {
|
---|
256 | pb_log(1,"Getting context for plugin $p\n");
|
---|
257 | $cbp = cb_plugin_get($p,$cbp);
|
---|
258 | # Adds mtime info to the plugin structure
|
---|
259 | foreach my $type ('files','dirs','dirsandfiles') {
|
---|
260 | foreach my $f (keys %{$cbp->{$p}->{$type}}) {
|
---|
261 | my $tdir = $dest;
|
---|
262 | if (defined $machine) {
|
---|
263 | $tdir = "$dest/$machine";
|
---|
264 | }
|
---|
265 | if (-r "$tdir/$f") {
|
---|
266 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$tdir/$f") || die "Unable to stat $tdir: $!";
|
---|
267 | $cbp->{$p}->{$type}->{$f}->{'mtime'} = $mtime;
|
---|
268 | } else {
|
---|
269 | pb_log(0,"WARNING: Unable to read $tdir/$f from plugin $p\n");
|
---|
270 | }
|
---|
271 | }
|
---|
272 | }
|
---|
273 | }
|
---|
274 | }
|
---|
275 |
|
---|
276 | # Handle this source
|
---|
277 | if (defined $source) {
|
---|
278 | my $fullsource = "$source";
|
---|
279 | $fullsource = "$machine/$source" if (defined $machine);
|
---|
280 | pb_log(2,"fullsource is $fullsource\n");
|
---|
281 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$dest/$fullsource") || die "Unable to stat $fullsource: $!";
|
---|
282 | my $type = 'files';
|
---|
283 | if (-d $fullsource) {
|
---|
284 | $type = 'dirsandfiles';
|
---|
285 | }
|
---|
286 | die "ERROR: Only able to handle files or dirs with option --source\n" if ((! -d $fullsource) && (! -f $fullsource));
|
---|
287 |
|
---|
288 | $cbp->{"cb.source"}->{$type}->{$source}->{'uid'} = $uid;
|
---|
289 | $cbp->{"cb.source"}->{$type}->{$source}->{'gid'} = $gid;
|
---|
290 | $cbp->{"cb.source"}->{$type}->{$source}->{'mode'} = $mode;
|
---|
291 | $cbp->{"cb.source"}->{$type}->{$source}->{'mtime'} = $mtime;
|
---|
292 | }
|
---|
293 |
|
---|
294 | if ((not defined $source) && (not defined $plugin)) {
|
---|
295 | # Here we need to take all content under $dest considering that machine
|
---|
296 | if (defined $machine) {
|
---|
297 | find(\&cb_add_to_cbp,("$dest/$machine"));
|
---|
298 | } else {
|
---|
299 | find(\&cb_add_to_cbp,($dest));
|
---|
300 | }
|
---|
301 | }
|
---|
302 | pb_log(2,"INFO: RAW cbp: ".Dumper(%$cbp)."\n");
|
---|
303 |
|
---|
304 | # Clean up cbp structure by comparing with data stored in the DB
|
---|
305 | # Only keep the more recent modified content
|
---|
306 | my $mac = $machine;
|
---|
307 | $mac = "localhost" if (not defined $machine);
|
---|
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','dirsandfiles') {
|
---|
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();
|
---|
354 | foreach my $k (keys %{$cbp}) {
|
---|
355 | foreach my $type ('files','dirs','dirsandfiles') {
|
---|
356 | # TODO: for dirs we may remove the files below ?
|
---|
357 | foreach my $o ((keys %{$cbp->{$k}->{$type}})) {
|
---|
358 | if (not defined $cbp->{$k}->{$type}->{$o}->{'deleted'}) {
|
---|
359 | $tar->add_files("./$o");
|
---|
360 | # Add an entry to the DB
|
---|
361 | if (defined $dbid->{$o}) {
|
---|
362 | # Modify an existing entry
|
---|
363 | $dbcmd = "UPDATE dates SET date=$curdate,file=$o WHERE id='?'";
|
---|
364 | if (not $debug) {
|
---|
365 | $sth = $dbh->prepare(qq{$dbcmd});
|
---|
366 | $sth = $dbh->execute($dbid->{$o});
|
---|
367 | } else {
|
---|
368 | pb_log(0,"Executing in DB: $dbcmd with curdate=$curdate,file=$o,id=$dbid->{$o}\n");
|
---|
369 | }
|
---|
370 | } else {
|
---|
371 | # Add an new entry
|
---|
372 | $dbcmd = "INSERT INTO dates VALUES (NULL,?,?,$mac)";
|
---|
373 | if (not $debug) {
|
---|
374 | $sth = $dbh->prepare(qq{$dbcmd});
|
---|
375 | $sth = $dbh->execute($curdate,$o);
|
---|
376 | } else {
|
---|
377 | pb_log(0,"Executing in DB: $dbcmd with curdate=$curdate,file=$o,machine=$mac\n");
|
---|
378 | }
|
---|
379 | }
|
---|
380 | if (not $debug) {
|
---|
381 | $sth->finish();
|
---|
382 | }
|
---|
383 | }
|
---|
384 | }
|
---|
385 | }
|
---|
386 | }
|
---|
387 | my $tarfile = "$ENV{'TMPDIR'}/cbcontent$$.tar";
|
---|
388 | $tar->write("$tarfile");
|
---|
389 |
|
---|
390 | my $ssh2;
|
---|
391 | my $chan;
|
---|
392 |
|
---|
393 | # deal with content first
|
---|
394 | if (defined $machine) {
|
---|
395 | # Create remote connection and copy tar file there
|
---|
396 | $ssh2 = Net::SSH2->new();
|
---|
397 | $ssh2->connect($machine);
|
---|
398 | my $hdir = (getpwnam(getpwuid($<)))[7];
|
---|
399 | if ($ssh2->auth_publickey($remote,"$hdir/.ssh/id_dsa.pub","$hdir/.ssh/id_dsa")) {
|
---|
400 | $chan = $ssh2->channel();
|
---|
401 | if (not $debug) {
|
---|
402 | $chan->exec("if [ ! -d $ENV{'TMPDIR'} ]; then mkdir -p $ENV{'TMPDIR'} fi");
|
---|
403 | $ssh2->scp_put($tarfile,$ENV{'TMPDIR'});
|
---|
404 | #$chan->exec("cd / ; tar xf $tarfile");
|
---|
405 | } else {
|
---|
406 | pb_log(1,"INFO: creating $ENV{'TMPDIR'} if needed on $remote\@$machine and copying content\n");
|
---|
407 | }
|
---|
408 | } else {
|
---|
409 | pb_log(0,"ERROR: Unable to authenticate to $remote\@$machine\n");
|
---|
410 | return;
|
---|
411 | }
|
---|
412 | }
|
---|
413 |
|
---|
414 | # Pointer to function depending whether we're local or remote
|
---|
415 | my $func;
|
---|
416 | if (defined $machine) {
|
---|
417 | $func = \&{ $chan->exec };
|
---|
418 | } else {
|
---|
419 | $func = \&pb_system;
|
---|
420 | }
|
---|
421 |
|
---|
422 | if (not $debug) {
|
---|
423 | &$func("cd / ; tar xf $tarfile");
|
---|
424 | } else {
|
---|
425 | pb_log(1,"INFO: Extracting (on $mac) $tarfile under /\n");
|
---|
426 | }
|
---|
427 |
|
---|
428 | foreach my $k (keys %{$cbp}) {
|
---|
429 | foreach my $type ('files','dirs','dirsandfiles') {
|
---|
430 | # TODO: do we act recursively for dirsandfiles at least for uid/gid ?
|
---|
431 | foreach my $o ((keys %{$cbp->{$k}->{$type}})) {
|
---|
432 | if (not defined $cbp->{$k}->{$type}->{$o}->{'deleted'}) {
|
---|
433 | if ($debug) {
|
---|
434 | pb_log(1,"INFO: Executing (on $mac) sudo chown $cbp->{$k}->{$type}->{$o}->{'uid'}:$cbp->{$k}->{$type}->{$o}->{'gid'} $o\n");
|
---|
435 | pb_log(1,"INFO: Executing (on $mac) sudo chmod $cbp->{$k}->{$type}->{$o}->{'mode'} $o\n");
|
---|
436 | } else {
|
---|
437 | &$func("sudo chown $cbp->{$k}->{$type}->{$o}->{'uid'}:$cbp->{$k}->{$type}->{$o}->{'gid'} $o");
|
---|
438 | &$func("sudo chmod $cbp->{$k}->{$type}->{$o}->{'mode'} $o");
|
---|
439 | }
|
---|
440 | }
|
---|
441 | }
|
---|
442 | }
|
---|
443 | if (defined $cbp->{$k}->{'reloadscript'}) {
|
---|
444 | if ($debug) {
|
---|
445 | pb_log(1,"INFO: Executing (on $mac) $cbp->{$k}->{'reloadscript'}\n");
|
---|
446 | } else {
|
---|
447 | &$func("$cbp->{$k}->{'reloadscript'}");
|
---|
448 | }
|
---|
449 | }
|
---|
450 | }
|
---|
451 |
|
---|
452 | if (defined $machine) {
|
---|
453 | # Remote cleanup
|
---|
454 | $chan->exec("rm -rf $ENV{'TMPDIR'}");
|
---|
455 | $ssh2->disconnect();
|
---|
456 | }
|
---|
457 |
|
---|
458 | # Cleanup
|
---|
459 | if (not $debug) {
|
---|
460 | unlink("$tarfile");
|
---|
461 | } else {
|
---|
462 | pb_log(0,"DEBUG: Please remove manually with rm -f $tarfile\n")
|
---|
463 | }
|
---|
464 | pb_log(2,"Exiting cb_distribute\n");
|
---|
465 | }
|
---|
466 |
|
---|
467 | sub cb_add_to_cbp {
|
---|
468 |
|
---|
469 | pb_log(3,"Entering into cb_addto_cbp\n");
|
---|
470 | my $type = 'files';
|
---|
471 | if (-d $File::Find::name) {
|
---|
472 | $type = 'dirs';
|
---|
473 | }
|
---|
474 |
|
---|
475 | my $destname = $File::Find::name;
|
---|
476 | # Target name is without the $dest part
|
---|
477 | $destname =~ s|^$dest||;
|
---|
478 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$File::Find::name") || die "Unable to stat $File::Find::name: $!";
|
---|
479 | $cbp->{"cb.full"}->{$type}->{$destname}->{'uid'} = $uid;
|
---|
480 | $cbp->{"cb.full"}->{$type}->{$destname}->{'gid'} = $gid;
|
---|
481 | $cbp->{"cb.full"}->{$type}->{$destname}->{'mode'} = $mode;
|
---|
482 | $cbp->{"cb.full"}->{$type}->{$destname}->{'mtime'} = $mtime;
|
---|
483 | pb_log(2,"Adding $destname ($uid,$gid,$mode) to cbp\n");
|
---|
484 | }
|
---|