Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / add_synchronize
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         add_synchronize
5 # RCS:          $Header: add_synchronize,v 1.2 97/05/27 15:35:51 defaria Exp
6 $
7 # Description:  This script adds a new person to synchronize
8 # Author:       Andrew DeFaria, California Language Labs
9 # Created:      Mon May 19 15:56:06 PDT 1997
10 # Modified:
11 # Language:     Korn Shell
12 #
13 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
14 #
15 ################################################################################
16 # Set me to command name
17 me=$(basename $0)
18
19 # Set adm_base
20 adm_base=${adm_base:-//sonscentral/Corporate/Software/adm}
21
22 # Set adm_fpath
23 adm_fpath=${adm_fpath:-$adm_base/functions}
24
25 # Source functions
26 . $adm_fpath/common
27
28 function usage {
29   print -u2 "Usage: $me -username <username> -fullname <fullname>"
30   print -u2 "\t-groupname <groupname>"
31   exit 1
32 } # usage
33
34 function add_to_synchronize {
35   cd $synchro_db
36   check_out_file=$synchro_users
37   co -q -l $check_out_file
38
39   if [ $? -ne 0 ]; then
40     error "Unable to checkout $check_out_file"
41     exit $?
42   fi
43
44   trap cancel_checkout INT ERR
45
46   print "$fullname,\t$username,\t$username@cup.hp.com" >> $check_out_file
47
48   if [ $? -ne 0 ]; then
49     error "Unable to add entry to $check_out_file"
50     exit $?
51   fi
52
53   ci -u -q -m"Added $fullname" $check_out_file
54   if [ $? -ne 0 ]; then
55     error "Unable to check in $check_out_file!"
56     exit $?
57   fi
58
59   trap INT ERR
60
61   cd $OLDPWD
62 } # add_to_synchronize
63
64 function add_to_synchronize_group {
65   cd $synchro_db/GroupTemplates
66   check_out_file=$groupname
67   co -q -l $check_out_file
68
69   if [ $? -ne 0 ]; then
70     error "Unable to checkout $check_out_file"
71     exit $?
72   fi
73
74   trap cancel_checkout INT ERR
75
76   print "$fullname" >> $check_out_file
77
78   if [ $? -ne 0 ]; then
79     error "Unable to add entry to $check_out_file"
80     exit $?
81   fi
82
83   ci -u -q -m"Added $fullname to $check_out_file" $check_out_file
84   if [ $? -ne 0 ]; then
85     error "Unable to check in $check_out_file!"
86     exit $?
87   fi
88
89   trap INT ERR
90
91   make > make.out 2>&1
92
93   if [ $? -ne 0 ]; then
94     error "Rebuilding of Synchronize groups failed"
95     exit $?
96   fi
97
98   cd $OLDPWD
99 } # add_to_synchronize_group
100
101 function cancel_checkout {
102   info "Canceling checkout"
103   rcs -q -u $check_out_file
104   chmod -w $check_out_file
105   co -q $check_out_file
106   exit 1
107 } # cancel_checkout
108
109 function user_exists {
110   grep -ve "^#" $synchro_users | cut -f1 -d',' |
111     grep "^$username$" >/dev/null 2>&1
112   return $?
113 } # user_exists
114
115 # Find synchro_dir
116 if [ -d /net/cllapp/opt/synchronize ]; then
117   synchro_dir=/net/cllapp/opt/synchronize
118 else
119   error "Internal error: Unable to ascertain synchro_dir!"
120   exit 1
121 fi
122
123 synchro_db=$synchro_dir/db
124 synchro_users=$synchro_db/users
125 username=
126 fullname=
127 groupname=
128 check_out_file=
129
130 while [ $# -ge 1 ]; do
131   case "$1" in
132     -usage)
133       usage
134       ;;
135
136     -username)
137       if [ $# -le 1 ]; then
138         error "Username not specified!"
139         usage
140       fi
141       shift
142       username="$1"
143       ;;
144
145     -fullname)
146       if [ $# -le 1 ]; then
147         error "Full name not specified!"
148         usage
149       fi
150       shift
151       fullname="$1"
152       ;;
153     -groupname)
154       if [ $# -le 1 ]; then
155         error "Groupname not specified!"
156         usage
157       fi
158       shift
159       groupname="$1"
160       ;;
161
162     *)
163       error "Unknown parameter encounter: \"$1\""
164       usage
165       ;;
166   esac
167   shift
168 done
169
170 if [ "_$username" = "_" -o \
171  "_$fullname" = "_" -o \
172  "_$groupname"    = "_" ]; then
173   error "Missing parameter"
174   usage
175 fi
176
177 if $(user_exists); then
178   error "$username already exists in the Synchronize database"
179 elif [ ! -f $synchro_db/GroupTemplates/$groupname ]; then
180   error "Unknown Synchronize group $groupname"
181 else
182   add_to_synchronize
183   if [ $? -eq 0 ]; then
184     info "$fullname has been added as a Synchronize user"
185   else
186     error "Problems encountered trying to create Synchronize user for
187 $fullname"
188   fi
189   add_to_synchronize_group
190   if [ $? -eq 0 ]; then
191     info "$fullname has been successfully added to $groupname"
192   else
193     error "Problems encountered trying to add $fullname to $groupname"
194   fi
195 fi