installCDE.src: remove duplicate code
[oweals/cde.git] / cde / admin / IntegTools / post_install / hp / configTT
1 #! /bin/ksh
2 ########
3 #  Product: CDE
4 #  Fileset: CDE-TT
5 #  configure
6 #  @(#) $XConsortium: configTT /main/2 1996/03/06 19:09:08 barstow $
7 ########
8 #
9 # (c) Copyright Hewlett-Packard Company, 1993
10 #
11 ########
12
13
14
15 FixInetdDotConf()
16 {
17 FILE=/etc/inetd.conf
18 TMPFILE=/tmp/inetd.conf
19
20     TTDBSERVERD=/usr/dt/bin/rpc.ttdbserver
21     OLDTTDBSERVERD=/usr/dt/bin/rpc.ttdbserverd
22
23     awk -v ttdb=$TTDBSERVERD -v oldttdb=$OLDTTDBSERVERD '{
24           if ($6 == ttdb || $6 == oldttdb)
25                 ;
26           else
27                 print $0
28          }' $FILE >$TMPFILE
29
30     mv $FILE $FILE.old
31     mv $TMPFILE $FILE
32
33     echo "rpc stream tcp swait root $TTDBSERVERD 100083 1 $TTDBSERVERD -m /nfs/" >>$FILE
34 }
35
36
37 UnfixInetdDotConf()
38 {
39 FILE="/etc/inetd.conf"
40 TMPFILE="/tmp/inetd.conf"
41 TTDBSERVERD=/usr/dt/bin/rpc.ttdbserver
42
43     awk -v ttdb=$TTDBSERVERD \
44         '{if ($7 == "100083" && $6 == ttdb)
45                 ;
46           else
47                 print $0
48          }' $FILE >$TMPFILE
49
50     mv $TMPFILE $FILE
51
52     awk '{if ($1 == "#cde") {
53                 $1 = $2;
54                 $2 = ""
55              }
56              print $0
57          }' $FILE >$TMPFILE
58
59     mv $TMPFILE $FILE
60 }
61
62
63 FixEtcRpc()
64 {
65 FILE=/etc/rpc
66 TMPFILE=/tmp/etc-rpc
67
68     if [ ! -f $FILE ]
69     then
70         echo "ttdbserver     100083" >$FILE
71     else
72         awk '{if ($1 == "ttdbserver" && $2 == "100083")
73                 print $0 > "/tmp/etc-rpc-already-there"
74              }' $FILE >/dev/null
75
76         if [ ! -f /tmp/etc-rpc-already-there ]
77         then
78             awk '{if ($1 == "ttdbserver" || $2 == "100083")
79                         print $0 > "/tmp/etc-rpc-already-there"
80                  }' $FILE >/dev/null
81
82             if [ ! -f /tmp/etc-rpc-already-there ]
83             then
84                 echo "ttdbserver     100083" >>$FILE
85             else
86                 awk '{if ($1 == "ttdbserver" || $2 == "100083")
87                         print "#cde " $0; else print $0
88                      }' $FILE >$TMPFILE
89
90                 echo "ttdbserver     100083" >>$TMPFILE
91
92                 mv $TMPFILE $FILE
93                 rm /tmp/etc-rpc-already-there
94             fi
95         else
96             rm /tmp/etc-rpc-already-there
97         fi
98     fi
99 }
100
101 UnfixEtcRpc()
102 {
103 FILE="/etc/rpc"
104 TMPFILE="/tmp/etc-rpc"
105
106     awk '{if ($1 == "ttdbserver" && $2 == "100083")
107                 ;
108           else
109                 print $0
110          }' $FILE >$TMPFILE
111
112     mv $TMPFILE $FILE
113
114     awk '{if ($1 == "#cde") {
115                 $1 = $2;
116                 $2 = ""
117              }
118           print $0
119          }' $FILE >$TMPFILE
120
121     mv $TMPFILE $FILE
122 }
123
124 EstablishDtMountPoint()
125 {
126 FILE="/etc/src.sh"
127 TMPFILE="/tmp/etcsrcsh.$$"
128
129 #
130 #  Ensure that the DTMOUNTPOINT environment variable will be set
131 #  when anybody logs in.
132 #
133
134     if [[ -d /nfs && ! -d /net ]]
135     then
136         sed '/DTMOUNTPOINT=/d' $FILE >$TMPFILE
137
138         echo "DTMOUNTPOINT=/nfs/ ; export DTMOUNTPOINT" >>$TMPFILE
139
140         if [ ! -f ${FILE}.pre-cde ]
141         then
142             mv $FILE ${FILE}.pre-cde
143         fi
144
145         mv $TMPFILE $FILE
146     fi
147 }
148
149 DeestablishDtMountPoint()
150 {
151 FILE="/etc/src.sh"
152 TMPFILE="/tmp/etc-src.sh"
153
154     if [ -f ${FILE}.pre-cde ]
155     then
156         mv ${FILE}.pre-cde $FILE
157     else
158         sed '/DTMOUNTPOINT=/d' $FILE >$TMPFILE
159         mv $TMPFILE $FILE
160     fi
161 }
162
163 KillIt()
164 {
165     ps -ef | fgrep $1 | grep -v grep >/tmp/tmppsout
166     if [ -s /tmp/tmppsout ]
167     then
168         awk '{print "kill " $2}' /tmp/tmppsout | /bin/ksh
169         sleep 2
170         ps -ef | fgrep $1 | grep -v grep >/tmp/tmppsout
171         if [ -s /tmp/tmppsout ]
172         then
173             awk '{print "kill -TERM " $2}' /tmp/tmppsout | /bin/ksh
174             sleep 2
175             ps -ef | fgrep $1 | grep -v grep >/tmp/tmppsout
176             if [ -s /tmp/tmppsout ]
177             then
178                 awk '{print "kill -9 " $2}' /tmp/tmppsout | /bin/ksh
179                 sleep 2
180             fi
181         fi
182     fi
183     rm /tmp/tmppsout
184 }
185
186 RemoveTTFiles()
187 {
188     while read SRC
189     do
190       if [ "$SRC" != "" ]
191       then
192         rm -f $SRC
193         dirname=${SRC%/*}
194         if [ -d $dirname ]
195         then
196           cd $dirname
197           while [ "$dirname" != "$CDE_TOP" ]
198           do
199             cd ..
200             rmdir ${dirname##*/} >/dev/null 2>/dev/null
201             dirname=${dirname%/*}
202           done
203         fi
204       fi
205     done <<-EOF
206 /usr/dt/bin/rpc.ttdbserver
207 /usr/dt/bin/rpc.ttdbserverd
208 /usr/dt/bin/rpc.ttdbserverd
209 /usr/dt/bin/tt_type_comp
210 /usr/dt/bin/ttcp
211 /usr/dt/bin/ttdbck
212 /usr/dt/bin/ttmv
213 /usr/dt/bin/ttrm
214 /usr/dt/bin/ttrmdir
215 /usr/dt/bin/ttsession
216 /usr/dt/bin/tttrace
217 /usr/dt/bin/tttar
218 /usr/dt/bin/ttsnoop
219 /usr/dt/lib/libtt.a
220 /usr/dt/appconfig/tttypes/types.xdr
221         EOF
222 }
223
224 VerifyInstalledFiles()
225 {
226     echo "Status   mode    owner   group   filename"
227     echo "-----------------------------------------"
228 #         exists  correct correct correct  /usr/dt/foo1
229 #         MISSING  WRONG   WRONG   WRONG   /usr/dt/foo2
230 #        exists    the link is correct    /usr/dt/link
231
232     while read SRC
233     do
234       if [ "$SRC" != "" ]
235       then
236         set -A tokens $SRC
237         if [ "${tokens[3]}" = "file" ]
238         then
239           if [ -f ${tokens[0]} ]
240           then
241             echo "exists  \c"
242           else
243             echo "MISSING or REMOVED               \c"
244             echo "${tokens[0]}"
245             continue
246           fi
247         elif [ "${tokens[3]}" = "sym_link" ]
248         then
249           if [ -L ${tokens[0]} ]
250           then
251             echo "exists  \c"
252           else
253             echo "MISSING or REMOVED               \c"
254             echo "${tokens[0]}"
255             continue
256           fi
257         fi
258
259         if [ "${tokens[3]}" = "file" ]
260         then
261           touch /tmp/config-test
262           chmod ${tokens[1]} /tmp/config-test
263           tmpperms=`ls -l /tmp/config-test | awk '{print $1}'`
264           realperms=`ls -l ${tokens[0]} | awk '{print $1}'`
265
266           if [ "$tmpperms" = "$realperms" ]
267           then
268             echo "correct \c"
269           else
270             echo " WRONG  \c"
271           fi
272
273           owner=`ls -l ${tokens[0]} | awk '{print $3}'`
274
275           if [ "$owner" = "${tokens[4]}" ]
276           then
277             echo "correct \c"
278           else
279             echo " WRONG  \c"
280           fi
281
282           group=`ls -l ${tokens[0]} | awk '{print $4}'`
283
284           if [ "$group" = "${tokens[5]}" ]
285           then
286             echo "correct  \c"
287           else
288             echo " WRONG   \c"
289           fi
290         elif [ "${tokens[3]}" = "sym_link" ]
291         then
292           linkto=`ls -l ${tokens[0]} | awk '{print $11}'`
293           if [ "${tokens[2]}" = "$linkto" ]
294           then
295             echo "  the link is correct    \c"
296           else
297             echo "  the link is WRONG      \c"
298           fi
299         fi
300         echo "${tokens[0]}"
301       fi
302     done <<-EOF
303 /usr/dt/bin/rpc.ttdbserver 0555 lib/tt/bin/ttdbserverd/rpc.ttdbserver file bin bin di---- 378 cde_dt
304 /usr/dt/bin/tt_type_comp 0555 lib/tt/bin/tt_type_comp/tt_type_comp file bin bin di---- 378 cde_dt
305 /usr/dt/bin/ttcp 0555 lib/tt/bin/shell/ttcp file bin bin di---- 378 cde_dt
306 /usr/dt/bin/ttdbck 0555 lib/tt/bin/dbck/ttdbck file bin bin di---- 378 cde_dt
307 /usr/dt/bin/ttmv 0555 lib/tt/bin/shell/ttmv file bin bin di---- 378 cde_dt
308 /usr/dt/bin/ttrm 0555 lib/tt/bin/shell/ttrm file bin bin di---- 378 cde_dt
309 /usr/dt/bin/ttrmdir 0444 /usr/dt/bin/ttrm sym_link bin bin di---- 378 cde_dt
310 /usr/dt/bin/ttsession 0555 lib/tt/bin/ttsession/ttsession file bin bin di---- 378 cde_dt
311 /usr/dt/bin/tttrace 0555 lib/tt/bin/tttrace/tttrace file bin bin di---- 378 cde_dt
312 /usr/dt/bin/tttar 0555 lib/tt/bin/tttar/tttar file bin bin di---- 378 cde_dt
313 /usr/dt/bin/ttsnoop 0555 lib/tt/bin/ttsnoop/gui/ttsnoop file bin bin di---- 378 cde_dt
314 /usr/dt/appconfig/tttypes/types.xdr 0444 cde1/tttypes/types.xdr file bin bin di---- 378 cde_dt
315         EOF
316 }
317
318 ShowSize()
319 {
320     typeset -i total;
321     let total=0
322
323     echo "Size\t\tfilename"
324     echo "-----------------------------------------"
325
326     while read SRC
327     do
328       if [ "$SRC" != "" ]
329       then
330         set -A tokens $SRC
331         if [ "${tokens[3]}" = "file" ]
332         then
333           if [ -f ${tokens[0]} ]
334           then
335             filesize=`ls -l ${tokens[0]} | awk '{print $5}'`
336             echo "$filesize\t\t\c"
337             echo "${tokens[0]}"
338             let total=total+filesize
339           fi
340         fi
341       fi
342     done <<-EOF
343 /usr/dt/bin/rpc.ttdbserver 0555 lib/tt/bin/ttdbserverd/rpc.ttdbserver file bin bin di---- 378 cde_dt
344 /usr/dt/bin/tt_type_comp 0555 lib/tt/bin/tt_type_comp/tt_type_comp file bin bin di---- 378 cde_dt
345 /usr/dt/bin/ttcp 0555 lib/tt/bin/shell/ttcp file bin bin di---- 378 cde_dt
346 /usr/dt/bin/ttdbck 0555 lib/tt/bin/dbck/ttdbck file bin bin di---- 378 cde_dt
347 /usr/dt/bin/ttmv 0555 lib/tt/bin/shell/ttmv file bin bin di---- 378 cde_dt
348 /usr/dt/bin/ttrm 0555 lib/tt/bin/shell/ttrm file bin bin di---- 378 cde_dt
349 /usr/dt/bin/ttrmdir 0444 /usr/dt/bin/ttrm sym_link bin bin di---- 378 cde_dt
350 /usr/dt/bin/ttsession 0555 lib/tt/bin/ttsession/ttsession file bin bin di---- 378 cde_dt
351 /usr/dt/bin/tttrace 0555 lib/tt/bin/tttrace/tttrace file bin bin di---- 378 cde_dt
352 /usr/dt/bin/tttar 0555 lib/tt/bin/tttar/tttar file bin bin di---- 378 cde_dt
353 /usr/dt/bin/ttsnoop 0555 lib/tt/bin/ttsnoop/gui/ttsnoop file bin bin di---- 378 cde_dt
354 /usr/dt/appconfig/tttypes/types.xdr 0444 cde1/tttypes/types.xdr file bin bin di---- 378 cde_dt
355         EOF
356     echo "Total fileset size is $total"
357 }
358 HandleOption()
359 {
360   while [ $# -ne 0 ]; do
361     case $1 in
362         -e) OPERATION="configure"
363             shift;
364             ;;
365         -d) OPERATION="deconfigure"
366             shift;
367             ;;
368         -v) OPERATION="verify"
369             shift;
370             ;;
371         -s) OPERATION="size"
372             shift;
373             ;;
374     esac
375   done
376 }
377
378 #################################################################
379 #
380 # Main Body
381 #
382 #################################################################
383 PRODUCT=CDE
384 FILESET=CDE-TT
385 retval=0
386
387   HandleOption $*
388
389   if [ "$OPERATION" = "configure" ]
390   then
391
392     echo "Configuring for CDE-TT"
393
394     FixInetdDotConf
395
396     FixEtcRpc
397
398 #       After adding ToolTalk to the inetd service list the inet
399 #       daemon needs to reread its configuration.
400
401     /etc/inetd -c
402
403     EstablishDtMountPoint
404
405   elif [ "$OPERATION" = "deconfigure" ]
406   then
407
408     echo "de-Configuring CDE-TT"
409
410     /etc/inetd -k
411     KillIt "rpc.ttdbserver"
412     /etc/inetd
413
414     UnfixInetdDotConf
415
416     UnfixEtcRpc
417
418 #       After adding ToolTalk to the inetd service list the inet
419 #       daemon needs to reread its configuration.
420
421     /etc/inetd -c
422
423     DeestablishDtMountPoint
424
425     RemoveTTFiles
426
427     VerifyInstalledFiles
428
429   elif [ "$OPERATION" = "verify" ]
430   then
431
432     VerifyInstalledFiles
433
434   elif [ "$OPERATION" = "size" ]
435   then
436
437     ShowSize
438
439   fi
440
441   return $retval