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