installCDE.src: remove duplicate code
[oweals/cde.git] / cde / admin / IntegTools / post_install / ibm / configTT.src
1 XCOMM! /bin/ksh
2 XCOMM   (c) Copyright 1993, 1994 International Business Machines Corp.
3 XCOMM  @(#) $XConsortium: configTT.src /main/5 1996/04/23 10:36:05 drk $
4
5 XCOMM AIX cpp does not honor the usual requirement that preprocessor
6 XCOMM directives must begin in column one, so we must do more quoting.
7 #define HASH #
8
9 INETD=/etc/inetd.conf
10
11 CheckForttinInetd()
12 {
13 #ifdef _POWER
14     grep "ttdbserverd" $INETD > /dev/null 2>&1 && sed "/ttdbserverd/d" $INETD > /tmp/configTT.$$ && mv /tmp/configTT.$$ $INETD
15     rc=`grep "ttdbserver" $INETD | cut -c1 | grep -xv "#" \
16            1>/dev/null 2>/dev/null;echo $?`
17 #else
18     rc=`inetserv -s -I -v ttdbserver -p tcp 1>/dev/null 2>/dev/null;echo $?`
19 #endif
20     return $rc
21
22 }
23
24
25 XCOMM
26 XCOMM Checks if portmap daemon is already running; if not
27 XCOMM starts the portmap daemon.
28 XCOMM
29 CheckPortmap()
30 {
31     ps -ef | fgrep portmap | grep -v grep 2>/dev/null 1>/dev/null
32     if [ $? -ne 0 ]
33     then
34        startsrc -s portmap
35     fi
36 }
37 StopDaemon()
38 {
39     ps -ef | fgrep $1 | grep -v grep >/tmp/tmppsout
40     if [ -s /tmp/tmppsout ]
41     then
42         awk '{print "kill " $2}' /tmp/tmppsout | /bin/ksh 1>/dev/null
43         sleep 2
44         ps -ef | fgrep $1 | grep -v grep >/tmp/tmppsout
45         if [ -s /tmp/tmppsout ]
46         then
47             awk '{print "kill -TERM " $2}' /tmp/tmppsout | /bin/ksh 1>/dev/null
48             sleep 2
49             ps -ef | fgrep $1 | grep -v grep >/tmp/tmppsout
50             if [ -s /tmp/tmppsout ]
51             then
52                 awk '{print "kill -9 " $2}' /tmp/tmppsout | /bin/ksh 1>/dev/null
53                 sleep 2
54             fi
55         fi
56     fi
57     rm -f /tmp/tmppsout
58 }
59
60 FixEtcRpc()
61 {
62 XCOMM
63 XCOMM now check to see if the proper entry is in /etc/rpc
64 XCOMM
65
66     RPCFILE=/etc/rpc
67     TMPFILE=/tmp/etc-rpc
68
69     if [ ! -f $RPCFILE ]
70     then
71         HASH if the file doesn't exist (highly unlikely), make one
72         HASH with the proper entry
73         HASH
74
75         echo "ttdbserver     100083  tooltalk" >$RPCFILE
76
77     else
78         HASH
79         HASH check to see if the entry is already there
80         HASH
81         grep "ttdbserverd" $RPCFILE > /dev/null 2>&1 && sed "/ttdbserverd/d" $RPCFILE > /tmp/configTTrpc.$$ && mv /tmp/configTTrpc.$$ $RPCFILE
82
83         awk '{if ($1 == "ttdbserver" && $2 == "100083")
84                 print $0 > "/tmp/etc-rpc-already-there"
85              }' $RPCFILE >/dev/null
86
87         if [ ! -f /tmp/etc-rpc-already-there ]
88         then
89         HASH
90         HASH if it isn't, check to see if either term already
91         HASH exists. If either one does they need to be commented
92         HASH out.
93
94             awk '{if (($1 == "ttdbserver" && $2 != "100083") ||
95                       ($2 == "100083" && $1 != "ttdbserver"))
96                         print "#cde " $0;
97                   else
98                         print $0
99                  }' $RPCFILE >$TMPFILE
100
101             echo "ttdbserver     100083  tooltalk" >>$TMPFILE
102             mv $TMPFILE $RPCFILE
103
104         else
105             rm /tmp/etc-rpc-already-there
106         fi
107     fi
108 }
109
110 UnfixEtcRpc()
111 {
112 FILE="/etc/rpc"
113 TMPFILE="/tmp/etc-rpc"
114
115     awk '{if ($1 == "ttdbserver" && $2 == "100083")
116                 ;
117           else if ($1 == "ttdbserverd" && $2 == "100083")
118                 ;
119           else
120                 print $0
121          }' $FILE >$TMPFILE
122
123     mv $TMPFILE $FILE
124
125     awk '{if ($1 == "#cde") {
126                 $1 = $2
127                 $2 = ""
128              }
129           print $0
130          }' $FILE >$TMPFILE
131
132     mv $TMPFILE $FILE
133 }
134
135 RemovettFromInetserv()
136 {
137 TTDB=CDE_INSTALLATION_TOP/bin/rpc.ttdbserver
138
139 #ifdef _POWER
140     /usr/sbin/chsubserver -d -v ttdbserver -t sunrpc_tcp -p tcp -w wait -u root \
141                 -g $TTDB -r inetd rpc.ttdbserver 100083 1  \
142                                                    1>/dev/null 2>/dev/null
143     grep -v "#ttdbserver" $INETD >/tmp/configTT.$$ && cp /tmp/configTT.$$ $INETD
144
145 #else
146
147     inetserv -D -I -v ttdbserver -p tcp 2>/dev/null 1>/dev/null
148
149 #endif
150
151     if [ "$?" -ne "0" ]
152     then
153         exit 1
154     fi
155
156 }
157
158 AddttToInetserv()
159 {
160 INETD=/etc/inetd.conf
161 TTDB=CDE_INSTALLATION_TOP/bin/rpc.ttdbserver
162
163 XCOMM
164 XCOMM check for existence of /etc/inetd.conf
165 XCOMM
166
167     if [ ! -f $INETD ]          # highly unlikely
168     then
169         echo "" >$INETD
170     fi
171
172
173 #ifdef _POWER
174
175     /usr/sbin/chsubserver -a -v ttdbserver -t sunrpc_tcp -p tcp -w wait -u root \
176                 -g $TTDB -r inetd rpc.ttdbserver 100083 1   \
177                                             1>/dev/null  2>/dev/null
178     if [ "$?" -ne "0" ]
179     then
180         exit 1
181     fi
182
183 #else
184
185 XCOMM
186 XCOMM Check if the server exists in the /etc/inetd.conf file.
187 XCOMM
188     rc=`inetserv -s -I -v ttdbserver -p tcp 1>/dev/null 2>/dev/null;echo $?`
189
190     if [ "$rc" -ne "0" ]
191     then
192          inetserv  -a -S -v ttdbserver -p tcp -n 111
193          rc=$?
194          if [ "$rc" -eq "0" ]
195          then
196             inetserv -a -I -v ttdbserver -p tcp -t sunrpc_tcp -w wait -U root \
197                 -r $TTDB -R "rpc.ttdbserver 100083 1"
198             if [ "$?" = "1" ]
199             then
200                exit 1
201             fi
202          else
203             echo "Cannot add entries to inetd.conf..."
204             exit 1
205          fi
206     fi
207
208 #endif
209 }
210
211 HandleOption()
212 {
213   while [ $# -ne 0 ]; do
214     case $1 in
215         -e) DO_CONFIGURATION="yes"
216             shift;
217             ;;
218         -d) DO_CONFIGURATION="no"
219             shift;
220             ;;
221     esac
222   done
223 }
224
225 XCOMM ##################################################################
226 XCOMM
227 XCOMM Main Body
228 XCOMM
229 XCOMM ##################################################################
230 DO_CONFIGURATION=""
231 PRODUCT=CDE
232 FILESET=CDE-TT
233 retval=0
234
235 #ifndef _POWER
236   StopDaemon "rpc.ttdbserver"
237 #endif
238
239   HandleOption $*
240
241   if [ "$DO_CONFIGURATION" = "yes" ]
242   then
243
244     FixEtcRpc
245
246 #ifndef _POWER
247     CheckPortmap
248 #endif
249
250     CheckForttinInetd
251     rc=$?
252     if [ "$rc" = "0" ]
253     then
254         RemovettFromInetserv
255     fi
256
257     AddttToInetserv
258
259   elif [ "$DO_CONFIGURATION" = "no" ]
260   then
261
262     UnfixEtcRpc
263
264 #ifndef _POWER
265     CheckPortmap
266 #endif
267
268     CheckForttinInetd
269     rc=$?
270     if [ "$rc" = "0" ]
271     then
272         RemovettFromInetserv
273     else
274         echo "\nToolTalk is already disabled..\n"
275         exit 0
276     fi
277
278   fi
279
280 #ifndef _POWER
281   if [ "$DO_CONFIGURATION" != "" ]
282   then
283
284 XCOMM   After adding ToolTalk to the inetd service list the inet
285 XCOMM   daemon needs to reread its configuration.
286
287     inetimp
288     refresh -s inetd
289
290   fi
291 #endif