1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
|
#!/bin/csh -f
#
# Configuration script for top.
#
# Use with version 3.0 and higher.
#
set PRIME = "/usr/games/primes"
set vars = (module LoadMax topn NominalTopn delay owner group mode random \
TableSize bindir mandir manext mansty \
Cmdshell Cmdcc Cmdawk Cmdinstall cdefs)
set fastrack = 0
set yesno = (no yes)
onintr byebye
# make sure that getans is there and ready
if (! -e getans) then
echo 'This package is not complete. The shell file "getans" is missing.'
exit 10
endif
chmod +x getans
if ($#argv > 0) then
# fast track configuration
set fastrack = 1
else
cat <<'EOF'
Configuration for top, version 3.4
One moment....
'EOF'
endif
# collect file names and module names
ls machine/m_*.c >$$.f
ls machine/m_*.man >$$.m
sed -e 's@^machine/m_@@' -e 's/.c$//' $$.f >$$.n
# build Make.desc
set descs = `sed -e 's@\.c$@.desc@' $$.f`
sed -e "s@%descs%@$descs@" Make.desc.X >Make.desc
# build desc files and SYNOPSIS as needed
make -f Make.desc >/dev/null
if (-e .defaults) then
echo ""
echo "Reading configuration from last time..."
source .defaults
set nodefaults = 0
if ($fastrack == 1) then
set module = $1
endif
else
if ($fastrack == 1) then
echo "No previous configuration was found."
set fastrack = 0
set module = $1
else
set module = ""
endif
set LoadMax = 5.0
set topn = 15
set NominalTopn = 18
set delay = 5
set TableSize = 0
set bindir = /usr/local/bin
set mandir = /usr/man/manl
set manext = l
set mansty = man
set nodefaults = 1
set Cmdshell = /bin/sh
set Cmdawk = awk
set Cmdinstall = ./install
set Cmdcc = cc
set cdefs = -O
endif
echo ""
if ($fastrack == 1) then
grep -s $module $$.n >/dev/null
if ($status != 0) then
echo "$module is not recognized. To see a list of available modules"
echo 'run "Configure" with no arguments.'
rm -f $$.[fmn]
exit 1
endif
set random1 = `expr $random + 1`
cat <<EOF
Using these settings:
Bourne Shell $Cmdshell
C compiler $Cmdcc
Compiler options $cdefs
Awk command $Cmdawk
Install command $Cmdinstall
Module $module
LoadMax $LoadMax
Default TOPN $topn
Nominal TOPN $NominalTopn
Default Delay $delay
Random passwd access $yesno[$random1]
Table Size $TableSize
Owner $owner
Group Owner $group
Mode $mode
bin directory $bindir
man directory $mandir
man extension $manext
man style $mansty
EOF
goto fast
endif
cat <<'EOF'
You will be asked a series of questions. Each question will have a
default answer enclosed in brackets, such as "[5.0]". In most cases,
the default answer will work well. To use that value, merely press
return.
'EOF'
# display synopses
getmod:
cat <<'EOF'
The following machine-dependent modules are available:
'EOF'
awk -F: ' { printf "%-8s %s\n", $1, $2 }' SYNOPSIS
echo ''
./getans "What module is appropriate for this machine? " string "$module" .$$
set module = `cat .$$`
if ("$module" == "") then
echo "Please specify a valid module name."
goto getmod
endif
# is it a valid one?
grep -s "$module" $$.n >/dev/null
if ($status != 0) then
echo "That is not a recognized module name."
goto getmod
endif
# display a full description
sed -e '1,/DESCRIPTION:/d' -e '/^$/,$d' machine/m_${module}.desc
# verify it
echo ""
./getans "Is this what you want to use?" yesno 1 .$$
if (`cat .$$` == 0) then
goto getmod
endif
endif
cat <<'EOF'
First we need to find out a little bit about the executables needed to
compile top.
'EOF'
./getans "What is the full path name for the Bourne shell" file "$Cmdshell" .$$
set Cmdshell = `cat .$$`
cat <<'EOF'
Please supply the name of the appropriate command. It need not be a
full path name, but the named command does need to exist somewhere on
the current path.
'EOF'
./getans "AWK Interpreter" path "$Cmdawk" .$$
set Cmdawk = `cat .$$`
./getans "C Compiler" path "$Cmdcc" .$$
set Cmdcc = `cat .$$`
cat <<'EOF'
The installer command needs to understand Berkeley-esque arguments:
"-o" for owner, "-g" for group, and "-m" for mode. A shell script
called "install" is distributed with top and is suitable for use by
top. You can specify a different program here if you like, or use
the shell script (the default).
'EOF'
./getans "Installer" path "$Cmdinstall" .$$
set Cmdinstall = `cat .$$`
cat <<EOF
What other options should be used with the $Cmdcc command (use "none" to
specify no options)?
EOF
./getans "Compiler options" string "$cdefs" .$$
set cdefs = `cat .$$`
if ("$cdefs" == "none") then
set cdefs = ""
endif
cat <<'EOF'
Now you need to answer some questions concerning the configuration of
top itself.
The space command forces an immediate update. Sometimes, on loaded
systems, this update will take a significant period of time (because all
the output is buffered). So, if the short-term load average is above
"LoadMax", then top will put the cursor home immediately after the space
is pressed before the next update is attempted. This serves as a visual
acknowledgement of the command. "LoadMax" should always be specified as a
floating point number.
'EOF'
./getans "LoadMax" number "$LoadMax" .$$
set LoadMax = `cat .$$`
cat <<'EOF'
"Default TOPN" is the default number of processes to show. This is the
number that will be used when the user does not specify the number of
processes to show. If you want "all" (or infinity) as the default, use
the value "-1".
'EOF'
./getans "Default TOPN" neginteger "$topn" .$$
set topn = `cat .$$`
cat <<'EOF'
"Nominal_TOPN" is used as the default TOPN when Default_TOPN is Infinity
and the output is a dumb terminal. If we didn't do this, then
installations who use a default TOPN of Infinity will get every process in
the system when running top on a dumb terminal (or redirected to a file).
Note that Nominal_TOPN is a default: it can still be overridden on the
command line, even with the value "infinity".
'EOF'
./getans "Nominal TOPN" integer "$NominalTopn" .$$
set NominalTopn = `cat .$$`
cat <<'EOF'
Default Delay is the default number of seconds to wait between screen
updates.
'EOF'
./getans "Default Delay" integer "$delay" .$$
set delay = `cat .$$`
echo ""
set rand = 0
ypwhich >&/dev/null
if ($status == 0 || -e /etc/passwd.dir || -e /etc/pwd.db) then
set rand = 1
endif
if ($rand == 1) then
echo "It looks like you have a passwd file that can be accessed at random."
set pr = 'Do you want top to take advantage of this'
else
echo "It looks like you have conventional passwd file access. Top can take"
echo "advantage of a random access passwd mechanism if such exists. Do"
echo "you want top to assume that accesses to the file /etc/passwd are done"
set pr = 'with random access rather than sequential'
endif
if ($nodefaults == 1) then
set random = $rand
endif
./getans "${pr}?" yesno $random .$$
set random = `cat .$$`
echo ""
echo "Compiling prime.c"
$Cmdcc $cdefs -o prime prime.c -lm
if ($status != 0) then
echo "Oh well."
rm -f prime
endif
echo ""
ypcat passwd.byname >&/tmp/$$.a
if ($status == 0) then
set cnt = `wc -l </tmp/$$.a`
set mapfile = "NIS map"
else
set cnt = `wc -l </etc/passwd`
set mapfile = "file"
endif
rm /tmp/$$.a
set double = `expr $cnt \* 2`
echo "I found $cnt entries in your passwd $mapfile. Top hashes the username to"
echo "uid mappings as it goes along and it needs a good guess on the size of"
echo "that hash table. This number should be the next highest prime number"
echo "after $double."
echo ""
if (-e prime) then
set pr = `./prime $double`
echo "I have calculated that to be $pr."
else if (-e $PRIME) then
set pr = `$PRIME $double | head -1`
echo "I have calculated that to be $pr."
else
set pr = $double
echo "I cannot calculate that prime number, so you will need to provide it for me."
endif
if ($TableSize == 0) then
set TableSize = $pr
endif
./getans "Enter the hash table size" integer "$TableSize" .$$
set TableSize = `cat .$$`
echo ""
# !!! I need to fix this: /dev/kmem might not exist on some machines !!!
# determine the right way to invoke ls to get full output
set ls = "ls -l"
if (`$ls getans | wc -w` < 9) then
set ls = "ls -lg"
endif
set t_owner = root
set t_group = `$ls -d /usr/bin | awk ' { print $4 }'`
if (-e /proc) then
cat <<EOF
Uh oh! I see /proc out there. Some new Unix variants provide the /proc
file system as a mechanism to get to a process's address space. This
directory is typically only accessible by root. However, there are a few
systems (such as DG/UX) on which this directory exists, but isn't used.
I'm going to assume that top needs to run setuid to root, but you should
double check and use mode 2755 (set group id) if top doesn't really need
root access. If you are running SunOS 5.x then you will need to install
top setuid root (owner root and mode 4711).
EOF
set t_mode = 4711
set mode = 4711
else if (-e /dev/kmem) then
$ls /dev/kmem >/tmp/$$.b
grep '^....r..r..' /tmp/$$.b >&/dev/null
if ($status == 1) then
grep '^....r..-..' /tmp/$$.b >&/dev/null
if ($status == 0) then
set t_group = `awk ' { print $4 }' /tmp/$$.b`
set t_mode = 2755
echo "It looks like only group $t_group can read the memory devices."
else
set t_mode = 4755
echo "It looks like only root can read the memory devices."
endif
else
set t_mode = 755
echo "It looks like anybody can read the memory devices."
endif
else
echo "It looks like there are no memory device special files."
set t_mode = 755
endif
if ($nodefaults) then
set owner = $t_owner
set group = $t_group
set mode = $t_mode
endif
echo "Tell me how to set the following when top is installed:"
./getans "Owner" user "$owner" .$$
set owner = `cat .$$`
./getans "Group owner" group "$group" .$$
set group = `cat .$$`
./getans "Mode" integer "$mode" .$$
set mode = `cat .$$`
rm -f /tmp/$$.b
echo ""
./getans "Install the executable in this directory" file "$bindir" .$$
set bindir = `cat .$$`
echo ""
./getans "Install the manual page in this directory" file "$mandir" .$$
set mandir = `cat .$$`
echo ""
./getans "Install the manual page with this extension" string "$manext" .$$
set manext = `cat .$$`
echo ""
./getans "Install the manual page as 'man' or 'catman'" string "$mansty" .$$
set mansty = `cat .$$`
echo ""
echo "We are done with the questions."
# Some Unix environments are so poor that their csh doesn't even support
# the "eval" builtin. Check for this before relying on its use to save
# the current configuration.
/bin/csh -c "eval echo foo" >&/dev/null
if ($status == 1) then
echo "Can't save configuration (nonfatal)"
else
echo "Saving configuration..."
# save settings to use as defaults the next time
rm -f .defaults
foreach v ($vars)
set tmp = `eval echo \$$v`
echo set $v = "'$tmp'" >>.defaults
end
endif
fast:
# set variables which contain module lists
set modules = `cat $$.f`
set manmodules = `cat $$.m`
# clean up
rm -f $$.f $$.m $$.n
# set the link for machine.c
rm -f machine.c machine.o
ln -s machine/m_${module}.c machine.c
# get definitions out of the module file
set libs = `grep LIBS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
set cflgs = `grep CFLAGS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
set tcap = `grep TERMCAP: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
# default for tcap (termcap)
if ("$tcap" == "") then
set tcap="-ltermcap"
endif
if ( { grep -s SIGKILL /usr/include/signal.h } ) then
set signal="/usr/include/signal.h"
else
set signal="/usr/include/sys/signal.h"
endif
echo "Building Makefile..."
sed -e "s|%topn%|$topn|" \
-e "s|%delay%|$delay|" \
-e "s|%owner%|$owner|" \
-e "s|%group%|$group|" \
-e "s|%mode%|$mode|" \
-e "s|%bindir%|$bindir|" \
-e "s|%mandir%|$mandir|" \
-e "s|%manext%|$manext|" \
-e "s|%mansty%|$mansty|" \
-e "s|%tablesize%|$TableSize|" \
-e "s|%libs%|$libs|" \
-e "s|%cflgs%|$cflgs|" \
-e "s|%termcap%|$tcap|" \
-e "s|%cdefs%|$cdefs|" \
-e "s|%modules%|$modules|" \
-e "s|%manmodules%|$manmodules|" \
-e "s|%signal%|$signal|" \
-e "s|%cc%|$Cmdcc|" \
-e "s|%awk%|$Cmdawk|" \
-e "s|%install%|$Cmdinstall|" \
-e "s|%shell%|$Cmdshell|" \
Makefile.X >Makefile
echo "Building top.local.h..."
sed -e "s|%LoadMax%|$LoadMax|" \
-e "s|%TableSize%|$TableSize|" \
-e "s|%NominalTopn%|$NominalTopn|" \
-e "s|%topn%|$topn|" \
-e "s|%delay%|$delay|" \
-e "s|%random%|$random|" \
top.local.H >top.local.h
echo "Building top.1..."
sed -e "s|%topn%|$topn|" \
-e "s|%delay%|$delay|" \
top.X >top.1
if (-e machine/m_${module}.man ) then
cat machine/m_${module}.man >>top.1
endif
# clean up
rm -f .$$
echo 'Doing a "make clean".'
make clean
echo 'To create the executable, type "make".'
echo 'To install the executable, type "make install".'
exit 0
byebye:
rm -f .$$ $$.[fmn] /tmp/$$.[ab]
exit 1
|