Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / bin / clearcase / install_triggers
1 #!/bin/bash
2 #################################################################################
3 # File:         install_triggers
4 # Description:  [Re]Creates Clearcase triggers
5 # Author:       Andrew DeFaria <ADeFaria@Salira.com>
6 # Created:      Tue Mar 12 13:56:31  2002
7 # Modified:     
8 # Language:     Bash
9 #
10 # (c) Copyright 2002, Salira Optical Network Systems, all rights reserved.
11 #
12 ################################################################################
13 # Set me to command name
14 me=$(basename $0)
15
16 # Source /etc/site_parms
17 if [ -f /etc/site_parms ]; then
18   . /etc/site_parms
19 else
20   echo "$me: WARNING: /etc/site_parms does not exist!"
21 fi
22
23 # Set adm_base
24 adm_base="$SITE_TOOLS_PATH/adm"
25
26 # Set adm_fpath
27 adm_fpath=${adm_fpath:-$adm_base/functions}
28
29 # Source functions
30 . $adm_fpath/common
31
32 # trigger_data contains the triggers. The fields are separated by a "%".
33 #
34 # Field 1: Name of trigger (must not contain spaces)
35 # Field 2: Comment for trigger
36 # Field 3: Options. Currently specify one of preop, postop or all. Leading "-" will be
37 #          supplied
38 # Field 4: All modifier. Enter "all" if this is an all element trigger, blank otherwise
39 # Field 5: Operation kind. Things like checkin, checkout (See help for mktrtype for more)
40 # Field 6: Site. This is one of US, CN or all. If this trigger is only supposed to be
41 #          at one site then designate which site, otherwise all
42 # Field 7: What to execute. We assume and supply perl. We also prepend this with
43 #          the path to the Triggers directory.
44 # Field 8: Additional parameters (e.g. NotifyTrigger.pl <path to msg file>). Not that this
45 #          must be the full pathname (e.g. T:/Triggers/Messages/NotifySoftare.msg works fine)
46 trigger_data="\
47 check_in_pre%Check comments on check in%all%preop%checkin%all%CheckinPreop.pl%%\n\
48 check_in_post%Label check in with bug ID label%all%postop%checkin%all%CheckinPostop.pl%%\n\
49 notify_ci_software%Notify Software group of checkins%%postop%checkin%all%NotifyTrigger.pl%NotifySoftware.msg\n\
50 notify_ci_software_china%Notify China Software group of checkins%%postop%checkin%CN%NotifyTrigger.pl%NotifySoftware.msg\n\
51 notify_ci_rli%Notify Rick Li of checkins%all%postop%checkin%all%NotifyTrigger.pl%NotifyRickLi.msg\n\
52 remove_empty_branch%Remove empty branches after uncheckout, rmver, or rmbranch%all%postop%uncheckout,rmver,rmbranch%all%RemoveEmptyBranch.pl%
53 set_ownership%Set ownership to ccadmin%all%postop%mkelem%all%SetOwnershipTrigger.pl%%\
54 "
55
56 # Where perl is
57 perl=$(cygpath -w //$SITE_BUILD_SERVER/Tools/Perl/bin/perl.exe)
58
59 # Where trigger stuff is
60 trigbase=$(cygpath -w //$SITE_VIEW_SERVER/$SITE_VIEW_SHARENAME/$SITE_OFFICIAL_VIEW/$SITE_TOOLS_VOB/bin/clearcase/triggers)
61
62 # Where messages are
63 msgbase=$(cygpath -w $trigbase/messages)
64
65 function create_trigger {
66   name="$1"
67   comment="$2"
68   if [ -z "$3" ]; then
69     op1=""
70   else
71     op1="-$3"
72   fi
73   op2="-$4"
74   opkind="$5"
75
76   execute="$perl $trigbase\\$6"
77
78   if [ ! -z "$7" ]; then
79     execute="$execute $msgbase\\$7"
80   fi
81
82   # Check to see if the trigger already exists
83   cleartool lstype trtype:$name > /dev/null 2>&1
84
85   # If so set $replace with the -replace option
86   if [ $? -eq 0 ]; then
87     replace="-replace"
88   else
89     replace=""
90   fi
91
92   # [Re]Create trigger
93   echo "cleartool mktrtype $replace -element $op1 $op2 $opkind -comment \"$comment\" -execwin \"$execute\" $name" > /tmp/$me
94   cleartool mktrtype    \
95     $replace            \
96     -element            \
97     $op1 $op2 $opkind   \
98     -comment $comment   \
99     -execwin $execute   \
100     $name 1> /dev/null 2>> /tmp/$me
101
102   # Check status and inform the user
103   if [ $? -eq 0 ]; then
104     if [ -z "$replace" ]; then
105       verbose "Created $name trigger"
106     else
107       verbose "Replaced $name trigger"
108     fi
109   else
110     if [ -z "$replace" ]; then
111       warning "Unable to create $name trigger"
112     else
113       warning "Unable to replace $name trigger"
114     fi
115     cat /tmp/$me
116   fi
117
118   # Clean up temp file
119   rm -f /tmp/$me
120 } # create_trigger
121
122 # Get parameters
123 while [ $# -ge 1 ]; do
124   case "$1" in
125     -v|-verbose)
126       verbose=yes
127     ;;    
128
129     -d|-debug)
130       debug=yes
131     ;;
132
133     *)
134       break;
135     ;;
136     
137   esac
138   shift
139 done
140
141 # Need to cd to the vob so that Clearcase can determine which vob this trigger applies to. 
142 # Note that we assume that the view official exists and we are applying triggers to the 
143 # salira vob.
144 cd $SITE_VIEW_STORAGE/$SITE_OFFICIAL_VIEW/salira
145
146 # Process triggers from $trigger_data
147 IFS=% 
148 echo -e "$trigger_data" | while read name comment op1 op2 opkind site execstr parms; do
149   if [ "$parms" = "%" ]; then
150     parms=""
151   fi
152   if [ "$op1" = "%" ]; then
153     op1=""
154   fi
155
156   if [ "$site" = "all" -o "$site" = $SITE_NAME ]; then
157     create_trigger $name $comment "$op1" $op2 $opkind $execstr $parms
158   else
159     verbose "Skipping $name trigger - only appliable to the $site site"
160   fi
161 done