Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / add_postnote
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         add_postnote
5 # RCS:          $Header: add_postnote,v 1.1 97/05/27 15:35:32 defaria Exp $
6 # Description:  This script adds a new person to the postnote 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_postnote {
35   cd $postnote_dir
36   check_out_file=$postnote_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   print "S:$fullname = Phone: $phonenumber =
47 ($hostname,$displayname:0,$username@cup.hp.com,F,$xterm)" >> $check_out_file
48
49   if [ $? -ne 0 ]; then
50     error "Unable to add entry to $check_out_file"
51     exit $?
52   fi
53
54   ci -u -q -m"Added $fullname" $check_out_file
55   if [ $? -ne 0 ]; then
56     error "Unable to check in $check_out_file!"
57     exit $?
58   fi
59
60   trap INT ERR
61
62   cd $OLDPWD
63 } # add_to_postnote
64
65 function cancel_checkout {
66   info "Canceling checkout"
67   rcs -q -u $check_out_file
68   chmod -w $check_out_file
69   co -q $check_out_file
70   exit 1
71 } # cancel_checkout
72
73 # Find AppServer's data directory
74 if [ -d /net/bismol/app/data ]; then
75   appserver_data=/net/bismol/app/data
76 elif [ -d /net/hpclbis/app/data ]; then
77   appserver_data=/net/hpclbis/app/data
78 elif [ -d /nfs/bismol/app/data ]; then
79   appserver_data=/nfs/bismol/app/data
80 elif [ -d /nfs/hpclbis/app/data ]; then
81   appserver_data=/nfs/hpclbis/app/data
82 elif [ -d /nfs/hpclbis/root/app/data ]; then
83   appserver_data=/nfs/hpclbis/root/app/data
84 else
85   error "Internal error: Unable to ascertain appserver_data!"
86   exit 1
87 fi
88
89 postnote_dir=$appserver_data
90 postnote_addressbook=$postnote_dir/pn_addressbook
91 username=
92 fullname=
93 phonenumber="????"
94 hostname=
95 displayserver=
96 xterm=
97 check_out_file=
98
99 while [ $# -ge 1 ]; do
100   case "$1" in
101     -usage)
102       usage
103       ;;
104
105     -username)
106       if [ $# -le 1 ]; then
107         error "Username not specified!"
108         usage
109       fi
110       shift
111       username="$1"
112       ;;
113
114     -fullname)
115       if [ $# -le 1 ]; then
116         error "Full name not specified!"
117         usage
118       fi
119       shift
120       fullname="$1"
121       ;;
122     -phone)
123       if [ $# -le 1 ]; then
124         error "Phone not specified!"
125         usage
126       fi
127       shift
128       phonenumber="$1"
129       ;;
130
131     -hostname)
132       if [ $# -le 1 ]; then
133         error "Hostname not specified!"
134         usage
135       fi
136       shift
137       hostname="$1"
138       ;;
139
140     -displayname)
141       if [ $# -le 1 ]; then
142         error "Displayname not specified!"
143         usage
144       fi
145       shift
146       displayname="$1"
147       ;;
148
149     *)
150       error "Unknown parameter encounter: \"$1\""
151       usage
152       ;;
153   esac
154   shift
155 done
156
157 if [ "_$username" = "_" -o \
158  "_$fullname" = "_" -o \
159  "_$hostname"    = "_" ]; then
160   error "Missing parameter"
161   usage
162 fi
163
164 if [ "_$displayname" = "_" ]; then
165   displayname=$hostname:0.0
166 elif [ "$displayname" != "$hostname" ]; then
167   xterm="T"
168 else
169   xterm="F"
170 fi
171
172 add_to_postnote
173
174 if [ $? -eq 0 ]; then
175   info "$fullname has been added to PostNote addressbook"
176   if [ "$xterm" = "T" ]; then
177     info "X Terminal Server: $hostname; X Terminal Display Name:
178 $displayname"
179   fi
180 else
181   error "Problems encountered trying to create PostNote entry for $fullname"
182 fi