3 # Configuration script for top.
5 # Use with version 3.0 and higher.
7 set PRIME
= "/usr/games/primes"
8 set vars
= (module LoadMax topn NominalTopn delay owner group mode random \
9 TableSize bindir mandir manext mansty \
10 Cmdshell Cmdcc Cmdawk Cmdinstall cdefs
)
16 # make sure that getans is there and ready
18 echo 'This package is not complete. The shell file "getans" is missing.'
24 # fast track configuration
28 Configuration for top, version 3.5
34 # collect file names and module names
35 ls machine/m_*.c >$$.f
36 ls machine/m_*.man >$$.m
37 sed -e 's@^machine
/m_@@
' -e 's
/.c$
//' $$.f >$$.n
40 sed -e 's@\.c@.desc
\\@
' $$.f | sed -e '$s/\\//' >$$.a
41 sed -e "/^DESCS/r $$.a" Make.desc.X >Make.desc
43 # build desc files and SYNOPSIS as needed
44 make -f Make.desc >/dev/null
45 if ($status != 0) then
46 echo "Unable to build the synopsis."
47 echo 'Make sure the
command "make" is on your path and try
'
48 echo 'running Configure again.
'
52 if (-e .defaults) then
54 echo "Reading configuration from last time..."
57 if ($fastrack == 1) then
61 if ($fastrack == 1) then
62 echo "No previous configuration was found."
73 set bindir = /usr/local/bin
74 set mandir = /usr/man/manl
78 set Cmdshell = /bin/sh
80 set Cmdinstall = ./install
86 if ($fastrack == 1) then
87 grep -s $module $$.n >/dev/null
88 if ($status != 0) then
89 echo "$module is not recognized. To see a list of available modules"
90 echo 'run
"Configure" with no arguments.
'
94 set random1 = `expr $random + 1`
97 Bourne Shell $Cmdshell
99 Compiler options $cdefs
101 Install command $Cmdinstall
106 Nominal TOPN $NominalTopn
108 Random passwd access $yesno[$random1]
109 Table Size $TableSize
113 bin directory $bindir
114 man directory $mandir
115 man extension $manext
123 You will be asked a series of questions. Each question will have a
124 default answer enclosed in brackets, such as "[5.0]". In most cases,
125 the default answer will work well. To use that value, merely press
135 The following machine-dependent modules are available:
137 awk -F: ' { printf "%-10s %s\n", $1, $2 }' SYNOPSIS
139 ./getans "What module is appropriate for this machine? " string "$module" .$$
140 set module = `cat .$$`
142 if ("$module" == "") then
143 echo "Please specify a valid module name."
148 grep -s "$module" $$.n >/dev/null
149 if ($status != 0) then
150 echo "That is not a recognized module name."
154 # display a full description
155 sed -e '1,/DESCRIPTION
:/d
' -e '/^$
/,$d' machine/m_${module}.desc
159 ./getans "Is this what you want to use?" yesno 1 .$$
160 if (`cat .$$` == 0) then
167 First we need to find out a little bit about the executables needed to
171 ./getans "What is the full path name for the Bourne shell" file "$Cmdshell" .$$
172 set Cmdshell = `cat .$$`
176 Please supply the name of the appropriate command. It need not be a
177 full path name, but the named command does need to exist somewhere on
181 ./getans "AWK Interpreter" path "$Cmdawk" .$$
182 set Cmdawk = `cat .$$`
183 ./getans "C Compiler" path "$Cmdcc" .$$
184 set Cmdcc = `cat .$$`
188 The installer command needs to understand Berkeley-esque arguments:
189 "-o" for owner, "-g" for group, and "-m" for mode. A shell script
190 called "install" is distributed with top and is suitable for use by
191 top. You can specify a different program here if you like, or use
192 the shell script (the default).
195 ./getans "Installer" path "$Cmdinstall" .$$
196 set Cmdinstall = `cat .$$`
200 What other options should be used with the $Cmdcc command (use "none" to
203 ./getans "Compiler options" string "$cdefs" .$$
204 set cdefs = `cat .$$`
205 if ("$cdefs" == "none") then
211 Now you need to answer some questions concerning the configuration of
214 The space command forces an immediate update. Sometimes, on loaded
215 systems, this update will take a significant period of time (because all
216 the output is buffered). So, if the short-term load average is above
217 "LoadMax", then top will put the cursor home immediately after the space
218 is pressed before the next update is attempted. This serves as a visual
219 acknowledgement of the command. "LoadMax" should always be specified as a
220 floating point number.
223 ./getans "LoadMax" number "$LoadMax" .$$
224 set LoadMax = `cat .$$`
228 "Default TOPN" is the default number of processes to show. This is the
229 number that will be used when the user does not specify the number of
230 processes to show. If you want "all" (or infinity) as the default, use
235 ./getans "Default TOPN" neginteger "$topn" .$$
240 "Nominal_TOPN" is used as the default TOPN when Default_TOPN is Infinity
241 and the output is a dumb terminal. If we didn't
do this
, then
242 installations who use a default TOPN of Infinity will get every process
in
243 the system when running top on a dumb terminal
(or redirected to a
file).
244 Note that Nominal_TOPN is a default
: it can still be overridden on the
245 command line
, even with the value
"infinity".
249 .
/getans
"Nominal TOPN" integer
"$NominalTopn" .$$
250 set NominalTopn
= `cat .$$`
254 Default Delay is the default number of seconds to wait between screen
259 ./getans "Default Delay" integer "$delay" .$$
260 set delay = `cat .$$`
265 if (-e /etc/nsswitch.conf) then
266 set rand = `grep '^passwd
:.
*nis
' /etc/nsswitch.conf | wc -l`
272 if ($status == 0 || -e /etc/passwd.dir || -e /etc/pwd.db) then
278 echo "It looks like you have a passwd file that can be accessed at random."
279 set pr = 'Do you want top to take advantage of this
'
281 echo "It looks like you have conventional passwd file access. Top can take"
282 echo "advantage of a random access passwd mechanism if such exists. Do"
283 echo "you want top to assume that accesses to the file /etc/passwd are done"
284 set pr = 'with random access rather than sequential
'
287 if ($nodefaults == 1) then
291 ./getans "${pr}?" yesno $random .$$
292 set random = `cat .$$`
295 echo "Compiling prime.c"
296 $Cmdcc $cdefs -o prime prime.c -lm
297 if ($status != 0) then
304 ypcat passwd.byname >&/tmp/$$.a
305 if ($status == 0) then
306 set cnt = `wc -l </tmp/$$.a`
307 set mapfile = "NIS map"
310 niscat passwd.org_dir >&/tmp/$$.a
311 if ($status == 0) then
312 set cnt = `wc -l </tmp/$$.a`
313 set mapfile = "NISPLUS map"
315 set cnt = `wc -l </etc/passwd`
320 set double = `expr $cnt \* 2`
321 echo "I found $cnt entries in your passwd $mapfile. Top hashes the username to"
322 echo "uid mappings as it goes along and it needs a good guess on the size of"
323 echo "that hash table. This number should be the next highest prime number"
324 echo "after $double."
327 set pr = `./prime $double`
328 echo "I have calculated that to be $pr."
329 else if (-e $PRIME) then
330 set pr = `$PRIME $double | head -1`
331 echo "I have calculated that to be $pr."
334 echo "I cannot calculate that prime number, so you will need to provide it for me."
337 if ($TableSize == 0) then
341 ./getans "Enter the hash table size" integer "$TableSize" .$$
342 set TableSize = `cat .$$`
346 # !!! I need to fix this: /dev/kmem might not exist on some machines !!!
348 # determine the right way to invoke ls to get full output
350 if (`$ls getans | wc -w` < 9) then
355 set t_group = `$ls -d /usr/bin | awk ' { print
$4 }'`
358 I see /proc out there. Many Unix variants provide the /proc file
359 system as a mechanism to get to a process's address space. This
360 directory is typically only accessible by root. However
, there are a
361 few systems
(such as DG
/UX
) on
which this directory exists
, but isn
't
365 if (-r /proc/0/psinfo) then
371 It looks like this system is running Solaris 2.6 or greater. If this
372 is the case, then top can function just fine installed set group id to
373 sys. It does not need to be installed set-uid to root.
380 I'm going to assume that top needs to run setuid to root
, but you
381 should double check and use mode
2755 (set group id
) if top doesn
't
382 really need root access. If you are running SunOS 5.0 through SunOS
383 5.5.1 (that's Solaris
2.0 through Solaris
2.5.1) then you will need to
384 install top setuid root
(owner root and mode
4711). In SunOS
5.6
385 and higher top only requires
set group id sys permissions.
389 else if (-e /dev
/kmem
) then
390 $ls /dev
/kmem
>/tmp
/$$.b
391 grep '^....r..r..' /tmp
/$$.b
>&/dev
/null
392 if ($status == 1) then
393 grep '^....r..-..' /tmp
/$$.b
>&/dev
/null
394 if ($status == 0) then
395 set t_group
= `awk ' { print $4 }' /tmp/$$.b`
397 echo "It looks like only group $t_group can read the memory devices."
400 echo "It looks like only root can read the memory devices."
404 echo "It looks like anybody can read the memory devices."
407 echo "It looks like there are no memory device special files."
410 if ($nodefaults) then
415 echo "Tell me how to set the following when top is installed:"
416 .
/getans
"Owner" user
"$owner" .$$
417 set owner
= `cat .$$`
418 .
/getans
"Group owner" group
"$group" .$$
419 set group
= `cat .$$`
420 .
/getans
"Mode" integer
"$mode" .$$
425 .
/getans
"Install the executable in this directory" file "$bindir" .$$
426 set bindir
= `cat .$$`
429 .
/getans
"Install the manual page in this directory" file "$mandir" .$$
430 set mandir
= `cat .$$`
433 .
/getans
"Install the manual page with this extension" string
"$manext" .$$
434 set manext
= `cat .$$`
437 .
/getans
"Install the manual page as 'man' or 'catman'" string
"$mansty" .$$
438 set mansty
= `cat .$$`
441 echo "We are done with the questions."
443 # Some Unix environments are so poor that their csh doesn't even support
444 # the "eval" builtin. Check for this before relying on its use to save
445 # the current configuration.
446 /bin
/csh
-fc "eval echo foo" >&/dev
/null
447 if ($status == 1) then
448 echo "Can't save configuration (nonfatal)"
450 echo "Saving configuration..."
451 # save settings to use as defaults the next time
455 set tmp
= `eval echo \$$v`
456 echo set $v = "'$tmp'" >>.defaults
465 # set the link for machine.c
466 rm -f machine.c machine.o
467 ln -s machine
/m_
${module}.c machine.c
469 # get definitions out of the module file
470 set libs
= `grep LIBS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
471 set cflgs
= `grep CFLAGS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
472 set tcap
= `grep TERMCAP: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
473 set math
= `grep MATH: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
475 # get osrev defition, if we can
477 if (-e /usr
/bin
/uname
) then
478 set uname
=/usr
/bin
/uname
479 else if (-e /bin
/uname
) then
483 if ("$uname" != "") then
484 # different versions of tr can't agree on the way to specify ranges, so
485 # we will have to give the range explicitly.....sigh.
486 set osrev
="-DOSREV=`$uname -r | tr -cd ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`"
491 # default for tcap (termcap)
492 if ("$tcap" == "") then
494 else if ("$tcap" == "none") then
498 # allow for the module to override or remove -lm
499 if ("$math" == "") then
501 else if ("$math" == "none") then
505 if ( { grep -s SIGKILL
/usr
/include
/signal.h
} ) then
506 set signal
="/usr/include/signal.h"
508 set signal
="/usr/include/sys/signal.h"
512 echo "Building Makefile..."
513 sed -e "s|%topn%|$topn|" \
514 -e "s|%delay%|$delay|" \
515 -e "s|%owner%|$owner|" \
516 -e "s|%group%|$group|" \
517 -e "s|%mode%|$mode|" \
518 -e "s|%bindir%|$bindir|" \
519 -e "s|%mandir%|$mandir|" \
520 -e "s|%manext%|$manext|" \
521 -e "s|%mansty%|$mansty|" \
522 -e "s|%tablesize%|$TableSize|" \
523 -e "s|%libs%|$libs|" \
524 -e "s|%cflgs%|$cflgs|" \
525 -e "s|%termcap%|$tcap|" \
526 -e "s|%math%|$math|" \
527 -e "s|%cdefs%|$cdefs|" \
528 -e "s|%signal%|$signal|" \
529 -e "s|%cc%|$Cmdcc|" \
530 -e "s|%awk%|$Cmdawk|" \
531 -e "s|%install%|$Cmdinstall|" \
532 -e "s|%shell%|$Cmdshell|" \
533 -e "s|%osrev%|$osrev|" \
536 echo "Building top.local.h..."
537 sed -e "s|%LoadMax%|$LoadMax|" \
538 -e "s|%TableSize%|$TableSize|" \
539 -e "s|%NominalTopn%|$NominalTopn|" \
540 -e "s|%topn%|$topn|" \
541 -e "s|%delay%|$delay|" \
542 -e "s|%random%|$random|" \
543 top.
local.H
>top.
local.h
545 echo "Building top.1..."
546 sed -e "s|%topn%|$topn|" \
547 -e "s|%delay%|$delay|" \
549 if (-e machine
/m_
${module}.man
) then
550 cat machine
/m_
${module}.man
>>top
.1
556 echo 'Doing a "make clean".'
559 echo 'To create the executable, type "make".'
560 echo 'To install the executable, type "make install".'
564 rm -f .$$ $$.
[fmna
] /tmp
/$$.
[ab
]