Initial commit
[clearscm.git] / cc / triggers / Protect.pl
1 ################################################################################
2 #
3 # File:         Protect.pl,v
4 # Revision:     1.1.1.1
5 # Description:  When new elements are created in the VOB change the elements
6 #               ownership to the owner of the VOB and change element permissions
7 #               to appropiate for element_type.
8 #
9 #               NOTE: If a particular file_type is not implemented in
10 #               your VOB then comment it out.  Unspecified file_types
11 #               will have origional permissions, but will have
12 #               ownership changed.
13 # Assumptions:  Clearprompt is in the users PATH
14 # Author:       Andrew@DeFaria.com
15 # Created:      April 20, 2003
16 # Modified:     2007/05/17 07:45:48
17 # Language:     Perl
18 #
19 ################################################################################
20 use strict;
21 use warnings;
22
23 # What do we set the owner and group to?
24 my $owner  = "vobadm";
25 my $group  = "ccadmin";
26
27 # Get CLEARCASE_PN
28 my $pname = $ENV {CLEARCASE_PN};
29
30 # Let's get the real owner from the real output of describe
31 my @output = `cleartool describe vob:$pname`;
32
33 foreach (@output) {
34   if (/owner\s*\w*\\(.*)/) {
35     $owner = $1;
36     chop $owner if $owner =~ /\r/; # any carriage return
37     last;
38   } # if
39 } # foreach
40
41 # Let's get the real group from the real output of describe
42 foreach (@output) {
43   if (/group\s*\w*\\(.*)/) {
44     $group = $1;
45     chop $group if $group =~ /\r/; # any carriage return
46     last;
47   } # if
48 } # foreach
49
50 # Get what element type we are dealing with
51 my $eltype = $ENV {CLEARCASE_ELTYPE};
52
53 if (($eltype eq "directory") ||
54     ($eltype =~ /.*script/)  ||
55     ($eltype =~ /.*program/)) {
56   # All element types that are known to be 775 should be placed here.
57   `cleartool protect -chmod 775 -chown $owner -chgrp $group $pname`;
58 } elsif (($eltype eq "makefile")  ||
59          ($eltype =~ /.*include/) ||
60          ($eltype =~ /.*source/)) {
61   # All element types that are known to be 664 should be placed here.
62   `cleartool protect -chmod 664 -chown $owner -chgrp $group $pname`;
63 } elsif ($eltype eq "report") {
64   # All element types that are known to be 644 should be placed here.
65   `cleartool protect -chmod 644 -chown $owner -chgrp $group $pname`;
66 } else {
67   # All other element types should just have the ownership changed.
68   `cleartool protect -chown $owner -chgrp $group $pname`;
69 } # if
70
71 exit 0