#!/usr/local/bin/perl -w # Allow knowledgeable users to short-circuit the trigger with this EV. BEGIN { exit 0 if $ENV{CLEARCASE_SKIP_MKELEM_POST} } # Conceptually this is "use constant MSWIN ..." but ccperl can't do that. # Perl 5.005 and above uses MSWin32, prior versions use Windows_NT. sub MSWIN { ($^O || $ENV{OS}) =~ /MSWin32|Windows_NT/i ? 1 : 0 } # On Windows we must rely on PATH to find cleartool. On Unix, # /usr/atria/bin/cleartool is always a valid path so we use it. my $CT = MSWIN() ? 'cleartool' : '/usr/atria/bin/cleartool'; (my $pname = $ENV{CLEARCASE_PN}) =~ s%\\%/%g; my $ptmp = "$pname.mkelem"; # Try to figure out if the file needs to be made executable. my $exe = -x $ptmp || $pname =~ /\.(bat|cmd|exe|dll|com|cgi|.?sh|pl)$/i; if (! $exe && -s $ptmp) { if (-T $ptmp && open(PN, $ptmp)) { $exe = =~ /^:$|^#!/; close(PN); } if (! $exe) { # If all else fails try file(1), forcing it to the C locale and # suppressing errors (we may be on *&^#% Windows without 'file'). local %ENV; delete $ENV{LANG}; open(SAVE_STDERR, '>&STDERR'); close(STDERR) unless $ENV{CLEARCASE_TRACE_TRIGGERS}; $exe = qx(file $ptmp) =~ /executable|bourne|commands text|\bscript/i; open(STDERR, '>&SAVE_STDERR'); close(SAVE_STDERR); } } # Make r and w bits standard for development (umask=002 style), # plus or minus the x bits. my $mode = $exe ? 'a+x,ug+rw,o-w' : 'ug+rw,o-w'; # Protect element name from the &^#% Windows shell. $pname = qq("$pname") if MSWIN(); # Finish by setting the modes appropriately. No need to see the # upcoming verbosity. close(STDOUT) unless $ENV{CLEARCASE_TRACE_TRIGGERS}; exec $CT, qw(protect -chown vobadm -chgrp ccusers -chmod), $mode, $pname; __END__ =head1 DESCRIPTION This trigger forces all new elements to be owned by the vob owner. It also tries to make some guesses about appropriate modes; if a file needs special modes it can be reprotected afterwards by hand. =head1 CAUTION Note: this script hardwires the name of the vob owner. You should change all instances of 'vobadm', including this one, to the name of the local vob owner. Similarly with the group 'ccusers'. =head1 AUTHOR David Boyce (dsb@cleartool.com) =head1 COPYRIGHT Copyright (c) 1998-2002 David Boyce (dsb@cleartool.com), Clear Guidance Consulting. All rights reserved.