Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / get_info
1 #! /bin/ksh
2 #
3 #   Usage       get_info { all_projects         |
4 #                          all_members          |
5 #                          all_project_members  |
6 #                          member_project     { asok | dgross } |
7 #                          project_attribute  { Codegen vwstation} |
8 #                          member_attribute   { asok phone }    |
9 #                          server_names       {
10 #                                               buildserver |
11 #                                               mailserver  |
12 #                                               viewserver |
13 #                                               virtualws  |
14 #                                               vobserver  |
15 #                                               webserver  } |
16 #                          is_project
17 #                          emit_error   { error_code returned by get_info()
18 }
19 #                        }
20 #
21 #
22 # Set me to command name
23 me=$(basename $0)
24
25 # Set adm_base
26 adm_base=${adm_base:-//sonscentral/Corporate/Software/adm}
27
28 # Set adm_fpath
29 adm_fpath=${adm_fpath:-$adm_base/functions}
30
31 # Set machines
32 machines=${machines:-$adm_base/data/machines}
33
34 # Source functions
35 . $adm_fpath/common
36
37 DBDIR=$adm_base/data/db/get_info
38 alias grep='grep -i'
39
40 #
41 trap "cleanup"  1 2 3 8 15
42
43 #######  Begin error message catalog. #############
44 typeset MSG
45 MSG[0]="get_info:LDAP CONNECTION SUCCESSFUL"
46 MSG[1]="get_info:LDAP OPERATIONS ERROR"
47 MSG[2]="get_info:LDAP PROTOCOL ERROR"
48 MSG[3]="get_info:LDAP TIMELIMIT EXCEEDED"
49 MSG[4]="get_info:LDAP SIZELIMIT EXCEEDED"
50 MSG[5]="get_info:LDAP COMPARE FALSE"
51 MSG[6]="get_info:LDAP COMPARE TRUE"
52 MSG[7]="get_info:LDAP STRONG AUTH NOT SUPPORTED"
53 MSG[8]="get_info:LDAP STRONG AUTH REQUIRED"
54 MSG[9]="get_info:LDAP PARTIAL RESULTS"
55
56 MSG[16]="get_info:LDAP NO SUCH ATTRIBUTE"
57 MSG[17]="get_info:LDAP UNDEFINED TYPE"
58 MSG[18]="get_info:LDAP INAPPROPRIATE MATCHING "
59 MSG[19]="get_info:LDAP CONSTRAINT VIOLATION "
60 MSG[20]="get_info:LDAP TYPE OR VALUE EXISTS "
61 MSG[21]="get_info:LDAP INVALID SYNTAX "
62
63 MSG[32]="get_info:LDAP NO SUCH OBJECT "
64 MSG[33]="get_info:LDAP ALIAS PROBLEM "
65 MSG[34]="get_info:LDAP INVALID DN SYNTAX "
66 MSG[35]="get_info:LDAP IS LEAF "
67 MSG[36]="get_info:LDAP ALIAS DEREF PROBLEM "
68 MSG[37]="NAME ERROR(n) ((n & 0xf0) == 0x20)"
69
70 MSG[48]="get_info:LDAP INAPPROPRIATE AUTH "
71 MSG[49]="get_info:LDAP INVALID CREDENTIALS "
72 MSG[50]="get_info:LDAP INSUFFICIENT ACCESS "
73 MSG[51]="get_info:LDAP BUSY "
74 MSG[52]="get_info:LDAP UNAVAILABLE "
75 MSG[53]="get_info:LDAP UNWILLING TO PERFORM "
76 MSG[54]="get_info:LDAP LOOP DETECT "
77
78 MSG[64]="get_info:LDAP NAMING VIOLATION "
79 MSG[65]="get_info:LDAP OBJECT CLASS VIOLATION "
80 MSG[66]="get_info:LDAP NOT ALLOWED ON NONLEAF "
81 MSG[67]="get_info:LDAP NOT ALLOWED ON RDN "
82 MSG[68]="get_info:LDAP ALREADY EXISTS "
83 MSG[69]="get_info:LDAP NO OBJECT CLASS MODS "
84 MSG[70]="get_info:LDAP RESULTS TOO LARGE "
85
86 MSG[80]="get_info:LDAP OTHER "
87 MSG[81]="get_info:LDAP SERVER DOWN "
88 MSG[82]="get_info:LDAP LOCAL ERROR "
89 MSG[83]="get_info:LDAP ENCODING ERROR "
90 MSG[84]="get_info:LDAP DECODING ERROR "
91 MSG[85]="get_info:LDAP TIMEOUT "
92 MSG[86]="get_info:LDAP AUTH UNKNOWN "
93 MSG[87]="get_info:LDAP FILTER ERROR "
94 MSG[88]="get_info:LDAP USER CANCELLED "
95 MSG[89]="get_info:LDAP PARAM ERROR "
96 MSG[90]="get_info:LDAP NO MEMORY "
97 MSG[91]="get_info:LDAP CONNECT ERROR "
98 #
99 # errors related to remsh or OS interface.
100 MSG[201]="get_info:ERROR while fixing .rhosts file in preparation for
101 remsh."
102 MSG[202]="get_info:ERROR remsh failed while invoking get_info on CLLWEB"
103 MSG[203]="get_info:ERROR uname returned un-supported OS."
104 #
105 #   User interface errors while using get_info()
106 MSG[210]="get_info:ERROR insufficient arguments to get_info()"
107 MSG[211]="get_info:ERROR requested member project not found in data-base."
108 MSG[212]="get_info:ERROR requested project not found in data-base."
109 MSG[213]="get_info:ERROR database directory not found."
110 MSG[214]="get_info:ERROR gven member not found in data-base."
111 #
112 #
113 MSG[500]="get_info:ERROR BAD/un-implemented Error number"
114 #######  End error message catalog. #############
115
116 print_error_msg()
117 {
118 [ -z "${MSG[$1]}" ] && echo ${MSG[500]} || echo ${MSG[$1]}
119 exit 0
120 }
121
122 function cleanup
123 {
124 exit $1
125 }
126
127 #######################################################
128 # Start processing questions . . .
129 # Get member project name for a given member name.
130 # usage# save_get_info member_project amitp
131 #
132 #  This function will save information from data-base in
133 #  a temporary file, so that cleanup can prefix this
134 #  output with error code. This is done to pass error
135 #  code returned by the command passed to remsh.
136 #
137 #  Ex: remsh "get_info member_project amitp"
138 #
139 #    remsh returns status of itself(remsh) not the status
140 #    of "get_info".
141 #
142 save_get_info()
143 {
144 case "$1" in
145 all_project_members)
146         # Get all members for a given project.
147         [ $# -ne 2 ] && cleanup 210
148         [ ! -f $2.proj ] && cleanup 212
149         RESULT=`grep "^project:$2" *.mem | awk -F. '{print $1}'`
150         ;;
151
152 member_project)
153         # Get member project name for a given member name.
154         [ $# -ne 2 ] && cleanup 210
155         [ ! -f $2.mem ] && cleanup 214
156         RESULT=`grep "^project:" $2.mem | awk -F: '{print $2}'`
157         ;;
158
159 project_attribute)
160         # Get project attribute for a given project name.
161         [ ! -f $2.proj ] && cleanup 212
162         [ $# -eq 3 ] && RESULT=`grep "^$3:" $2.proj | awk -F: '{print $2}'`
163 || RESULT=`awk -F: '{printf "%s= %s\n", $1, $2}' $2.proj`
164         ;;
165
166 member_attribute)
167         # Get member attribute for a given member name.
168         [ ! -f $2.mem ] && cleanup 212
169         [ $# -eq 3 ] && RESULT=`grep "^$3:" $2.mem | awk -F: '{print $2}'`
170 || RESULT=`awk -F: '{printf "%s = %s\n", $1, $2}' $2.mem`
171         ;;
172
173 machine_attribute)
174         # Get machine attribute for a given machine name.
175         [ ! -f $2.mach ] && cleanup 212
176         [ $# -eq 3 ] && RESULT=`grep "^$3:" $2.mach | awk -F: '{print $2}'`
177 || RESULT=`awk -F: '{printf "%s = %s\n", $1, $2}' $2.mach`
178         ;;
179
180 is_project)
181         # Get project attribute for a given project name.
182         [ $# -ne 2 ] && cleanup 210
183         [ ! -f $2.proj ] && cleanup 212
184         RESULT=`grep "^project:" $2.proj | awk -d: '{print $2}'`
185         ;;
186
187 all_projects)
188         RESULT=`/bin/ls *.proj | awk -F. '{print $1}'`
189         ;;
190
191 all_members)
192         RESULT=`/bin/ls *.mem | awk -F. '{print $1}'`
193         ;;
194
195 server_names)
196         [ $# -ne 2 ] && cleanup 210
197         case $2 in
198                 buildserver)
199                 grepfor="Build Server"
200                 ;;
201                 mailserver)
202                 grepfor="Mail Server"
203                 ;;
204                 viewserver)
205                 grepfor="View Server"
206                 ;;
207                 virtualws)
208                 grepfor="Virtual Workstation"
209                 ;;
210                 vobserver)
211                 grepfor="Vob Server"
212                 ;;
213                 webserver)
214                 grepfor="Web Server"
215                 ;;
216                 *)
217                 cleanup 210
218                 ;;
219         esac
220 #       RESULT=`grep "^server:$2" *.mach | awk -F. '{print $1}'`
221         RESULT=`grep -v "^#" $machines | grep ":Infrastructure:" | grep
222 "$grepfor" | awk -F: '{print $1}'`
223         ;;
224 *)
225         # Error in input argument.
226         cleanup 210
227         ;;
228 esac
229 }
230
231 ########################  Main starts here ############
232 #
233
234 case $1 in
235 -qldap)
236         shift
237         typeset integer MULTILINE=1
238         ;;
239 noloop)
240         shift
241         # old version compatibility
242         ;;
243
244 emit_error)
245         [ $# -eq 2 ] && print_error_msg $2 || exit 210 # Incorrect argument
246 list.
247         ;;
248 *)
249         # go to processing  outside case block
250         ;;
251 esac
252
253 [ ! -d $DBDIR ] && cleanup 213
254 cd $DBDIR
255 save_get_info $@
256 [ $MULTILINE ] && echo "$RESULT" || echo $RESULT
257 cleanup 0