Subversion Repositories sysadmin_scripts

Rev

Rev 19 | Rev 21 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19 Rev 20
Line 57... Line 57...
57
use File::Basename;
57
use File::Basename;
58
use File::stat;
58
use File::stat;
59
 
59
 
60
our $VERSION = '1.0';
60
our $VERSION = '1.0';
61
 
61
 
62
my $DEBUG = 0;
62
my $DEBUG = 3;
63
 
63
 
64
my %config;
64
my %config;
65
 
65
 
66
my @DirectoriesToMove;
66
my @DirectoriesToMove;
67
 
67
 
Line 83... Line 83...
83
 
83
 
84
# simply read the entire file into a string
84
# simply read the entire file into a string
85
sub slurpFile {
85
sub slurpFile {
86
   my $filename = shift;
86
   my $filename = shift;
87
   return '' unless -e $filename;
87
   return '' unless -e $filename;
88
   open TEMP, "<'$filename'" or die "could not read $filename: $!\n";
88
   open TEMP, "<$filename" or die "could not read $filename: $!\n";
89
   my @contents = <TEMP>;
89
   my @contents = <TEMP>;
90
   close TEMP;
90
   close TEMP;
91
   return join( '', @contents );
91
   return join( '', @contents );
92
}
92
}
93
 
93
 
Line 171... Line 171...
171
# with the same name, but a .md5sum suffix
171
# with the same name, but a .md5sum suffix
172
sub moveToStaging {
172
sub moveToStaging {
173
   my ( $directory, $fullPath, $staging ) = @_;
173
   my ( $directory, $fullPath, $staging ) = @_;
174
   # and let's get the md5 file name also
174
   # and let's get the md5 file name also
175
   my $md5File = $fullPath . ".$config{'md5 suffix'}";
175
   my $md5File = $fullPath . ".$config{'md5 suffix'}";
176
   mkdir $staging unless -d $staging;
176
   mkdir( $staging ) unless -d $staging;
177
   return 'Directory already exists in staging' if -e "$staging/$directory";
177
   return 'Directory already exists in staging' if -e "$staging/$directory";
178
   move( $fullPath, "$staging/$directory" ) or die "Error moving $fullPath to $staging/$directory: $!\n";
178
   move( $fullPath, "$staging/$directory" ) or die "Error moving $fullPath to $staging/$directory: $!\n";
179
   move( $md5File, $staging ) or die "Error moving $md5File to $staging: $!\n";
179
   move( $md5File, $staging ) or die "Error moving $md5File to $staging: $!\n";
180
   return '';
180
   return '';
181
}
181
}
Line 262... Line 262...
262
      $thisDir = $1;
262
      $thisDir = $1;
263
      qx/rm -fR '$thisDir' '$thisDir.$md5Suffix'/;
263
      qx/rm -fR '$thisDir' '$thisDir.$md5Suffix'/;
264
   }
264
   }
265
}
265
}
266
 
266
 
-
 
267
sub makeDirectories {
-
 
268
   my $directory = shift;
-
 
269
   my $permissions = shift;
-
 
270
   $permissions = '777' unless $permissions;
-
 
271
   unless ( -d $directory ) {
-
 
272
      print "Making directory $directory\n" if $DEBUG > 1;
-
 
273
      `mkdir -p $directory`; 
-
 
274
      `chmod $permissions $directory`;
-
 
275
   }
-
 
276
}
-
 
277
         
267
 
278
 
268
 
279
 
269
###############################################################################
280
###############################################################################
270
# Main
281
# Main
271
###############################################################################
282
###############################################################################
Line 273... Line 284...
273
&loadConfig();
284
&loadConfig();
274
#use Data::Dumper;
285
#use Data::Dumper;
275
#print Dumper( \%config );
286
#print Dumper( \%config );
276
#die;
287
#die;
277
 
288
 
278
unless ( -d $config{'local root dir'} ) {
289
foreach my $dirsToMake ( 'local root dir', 'local trash dir', 'local staging area' ) {
279
   `mkdir -p $config{'local root dir'}`;
290
   &makeDirectories( $config{$dirsToMake} );
280
   `chmod 777 $config{'local root dir'}`;
-
 
281
}
291
}
-
 
292
 
282
# clean the trash if $config{ 'trash cleanup' } is non-zero
293
# clean the trash if $config{ 'trash cleanup' } is non-zero
283
&cleanTrash( $config{'local trash dir'}, $config{ 'trash cleanup' } ) if $config{ 'trash cleanup' };
294
&cleanTrash( $config{'local trash dir'}, $config{ 'trash cleanup' } ) if $config{ 'trash cleanup' };
284
 
295
 
285
# Check if we have any directories which are ready to be moved.
296
# Check if we have any directories which are ready to be moved.
286
@DirectoriesToMove = &getDirectories( $config{'local root dir'} );
297
@DirectoriesToMove = &getDirectories( $config{'local root dir'} );