#!/usr/local/bin/perl # This script was written for www.philforhumanity.com. # If you have any questions, issues, or enhancement requests, please contact us via the website. # Use this script at your own risk. # Variable declarations my $CP = "/bin/cp"; my $CT = "/usr/atria/bin/cleartool"; my @directories = (); my @elements = (); my @files = (); my $FIND = "/bin/find"; my $line; my $MV = "/bin/mv"; my $RM = "/bin/rm"; # If no arguments, then display error if ($#ARGV == -1) { die "\nERROR: You must specify at least one file or directory to recursively mkelem.\n\n"; } # For each user argument, get recursive list of new elements to be created for ( ; @ARGV; shift(@ARGV)) { if (-e $ARGV[0]) { @elements = (@elements, `$FIND \"$ARGV[0]\" -print`); } else { die "\nERROR: File or directory \"$ARGV[0]\" does not exist.\n\n"; } } # Sort the list of new elements @elements = sort @elements; # We may want to sort uniquely # We must process all the directories first, then do the files, so separate elements between directories and files foreach $line (@elements) { chomp $line; if (-d "$line") { @directories = (@directories, $line); } else { @files = (@files, $line); } } # Check out the current directory print "1) Checking out the parent directory.\n"; print `$CT co -nc .`; # Add directories to source control first print "2) Processing each directory.\n"; foreach $line (@directories) { # Back up directory print `$MV \"$line\" \"$line.tmp\"`; # Make a directory element, but leave it checkedout print `$CT mkelem -eltype directory -nc \"$line\"`; # Copy all the contents of the directory back in the original directory print `$CP -r \"$line.tmp\"/\* \"$line/\"`; # Ignore errors from empty directories # Delete tmp folder print `$RM -rf \"$line.tmp\"`; } # Add files to source control next print "3) Processing each file.\n"; foreach $line (@files) { # Make a directory element, but leave it checkedout print `$CT mkelem -nc -ci \"$line\"`; } # Finally, check in all directories now that all elements have been added to source control print "4) Checking in each directory.\n"; foreach $line (@directories) { print `$CT ci -nc \"$line\"`; } # Check in the current directory print "5) Checking in the parent directory.\n"; print `$CT ci -nc .`; # Exit exit 0;