Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / add_sharedx
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         add_sharedx
5 # RCS:          $Header: add_sharedx,v 1.1 97/05/27 15:35:33 defaria Exp $
6 # Description:  This script adds a new person to the SharedX addressbook
7 # Author:       Andrew DeFaria, California Language Labs
8 # Created:      Mon May 19 15:56:06 PDT 1997
9 # Modified:
10 # Language:     Korn Shell
11 #
12 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
13 #
14 ################################################################################
15 # Set me to command name
16 me=$(basename $0)
17
18 # Set adm_base
19 adm_base=${adm_base:-//sonscentral/Corporate/Software/adm}
20
21 # Set adm_fpath
22 adm_fpath=${adm_fpath:-$adm_base/functions}
23
24 # Source functions
25 . $adm_fpath/common
26
27 function usage {
28   print -u2 "Usage: $me -username <username> -fullname <fullname>"
29   print -u2 "\t-phone <phonenumber> -hostname <hostname>"
30   print -u2 "\t-displayname <displayname>"
31   exit 1
32 } # usage
33
34 function add_to_sharedx {
35   cd $sharedx_dir
36   check_out_file=$sharedx_addressbook
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   if [ "$xterm" = "T" ]; then
47     print "$displayname:0\t$fullname\t$phonenumber $username\t$hostname" >>
48 $check_out_file
49   else
50     print "$displayname:0\t$fullname\t$phonenumber $username" >>
51 $check_out_file
52   fi
53
54   if [ $? -ne 0 ]; then
55     error "Unable to add entry to $check_out_file"
56     exit $?
57   fi
58
59   ci -u -q -m"Added $fullname" $check_out_file
60   if [ $? -ne 0 ]; then
61     error "Unable to check in $check_out_file!"
62     exit $?
63   fi
64
65   trap INT ERR
66
67   cd $OLDPWD
68 } # add_to_sharedx
69
70 function cancel_checkout {
71   info "Canceling checkout"
72   rcs -q -u $check_out_file
73   chmod -w $check_out_file
74   co -q $check_out_file
75   exit 1
76 } # cancel_checkout
77
78 # Find AppServer's data directory
79 if [ -d /net/bismol/app/data ]; then
80   appserver_data=/net/bismol/app/data
81 elif [ -d /net/hpclbis/app/data ]; then
82   appserver_data=/net/hpclbis/app/data
83 elif [ -d /nfs/bismol/app/data ]; then
84   appserver_data=/nfs/bismol/app/data
85 elif [ -d /nfs/hpclbis/app/data ]; then
86   appserver_data=/nfs/hpclbis/app/data
87 elif [ -d /nfs/hpclbis/root/app/data ]; then
88   appserver_data=/nfs/hpclbis/root/app/data
89 else
90   error "Internal error: Unable to ascertain appserver_data!"
91   exit 1
92 fi
93
94 sharedx_dir=$appserver_data/SharedX/address_books
95 sharedx_addressbook=$sharedx_dir/CLL
96 username=
97 fullname=
98 phonenumber="????"
99 hostname=
100 displayserver=
101 xterm=
102 check_out_file=
103
104 while [ $# -ge 1 ]; do
105   case "$1" in
106     -usage)
107       usage
108       ;;
109
110     -username)
111       if [ $# -le 1 ]; then
112         error "Username not specified!"
113         usage
114       fi
115       shift
116       username="$1"
117       ;;
118
119     -fullname)
120       if [ $# -le 1 ]; then
121         error "Full name not specified!"
122         usage
123       fi
124       shift
125       fullname="$1"
126       ;;
127     -phone)
128       if [ $# -le 1 ]; then
129         error "Phone not specified!"
130         usage
131       fi
132       shift
133       phonenumber="$1"
134       ;;
135
136     -hostname)
137       if [ $# -le 1 ]; then
138         error "Hostname not specified!"
139         usage
140       fi
141       shift
142       hostname="$1"
143       ;;
144
145     -displayname)
146       if [ $# -le 1 ]; then
147         error "Displayname not specified!"
148         usage
149       fi
150       shift
151       displayname="$1"
152       ;;
153
154     *)
155       error "Unknown parameter encounter: \"$1\""
156       usage
157       ;;
158   esac
159   shift
160 done
161
162 if [ "_$username" = "_" -o \
163  "_$fullname" = "_" -o \
164  "_$displayname"    = "_" ]; then
165   error "Missing parameter"
166   usage
167 fi
168
169 if [ "_$hostname" = "_" ]; then
170   hostname=$displayname
171 elif [ "$displayname" != "$hostname" ]; then
172   xterm="T"
173 else
174   xterm="F"
175 fi
176
177 add_to_sharedx
178
179 if [ $? -eq 0 ]; then
180   info "$fullname has been added to Shared/X addressbook"
181   if [ "$xterm" = "T" ]; then
182     info "X Terminal Server: $hostname; X Terminal Display Name:
183 $displayname"
184   fi
185 else
186   error "Problems encountered trying to create Shared/X entry for $fullname"
187 fi