source: trunk/third/top/Configure @ 9084

Revision 9084, 12.9 KB checked in by ghudson, 28 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r9083, which included commits to RCS files with non-trunk default branches.
  • Property svn:executable set to *
Line 
1#!/bin/csh -f
2#
3# Configuration script for top.
4#
5# Use with version 3.0 and higher.
6#
7set PRIME = "/usr/games/primes"
8set vars = (module LoadMax topn NominalTopn delay owner group mode random \
9        TableSize bindir mandir manext mansty \
10        Cmdshell Cmdcc Cmdawk Cmdinstall cdefs)
11set fastrack = 0
12set yesno = (no yes)
13
14onintr byebye
15
16# make sure that getans is there and ready
17if (! -e getans) then
18   echo 'This package is not complete.  The shell file "getans" is missing.'
19   exit 10
20endif
21chmod +x getans
22
23if ($#argv > 0) then
24# fast track configuration
25   set fastrack = 1
26else
27cat <<'EOF'
28Configuration for top, version 3.4
29
30One moment....
31'EOF'
32endif
33
34# collect file names and module names
35ls machine/m_*.c >$$.f
36ls machine/m_*.man >$$.m
37sed -e 's@^machine/m_@@' -e 's/.c$//' $$.f >$$.n
38
39# build Make.desc
40set descs = `sed -e 's@\.c$@.desc@' $$.f`
41sed -e "s@%descs%@$descs@" Make.desc.X >Make.desc
42
43# build desc files and SYNOPSIS as needed
44make -f Make.desc >/dev/null
45
46if (-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
54else
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
77endif
78echo ""
79
80if ($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
90Using 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
102Random 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
112EOF
113   goto fast
114endif
115
116cat <<'EOF'
117You will be asked a series of questions.  Each question will have a
118default answer enclosed in brackets, such as "[5.0]".  In most cases,
119the default answer will work well.  To use that value, merely press
120return.
121
122'EOF'
123
124# display synopses
125
126getmod:
127cat <<'EOF'
128
129The following machine-dependent modules are available:
130'EOF'
131awk -F: ' { printf "%-8s %s\n", $1, $2 }' SYNOPSIS
132echo ''
133./getans "What module is appropriate for this machine? " string "$module" .$$
134set module = `cat .$$`
135
136if ("$module" == "") then
137    echo "Please specify a valid module name."
138    goto getmod
139endif
140
141# is it a valid one?
142grep -s "$module" $$.n >/dev/null
143if ($status != 0) then
144    echo "That is not a recognized module name."
145    goto getmod
146endif
147
148# display a full description
149sed -e '1,/DESCRIPTION:/d' -e '/^$/,$d' machine/m_${module}.desc
150
151# verify it
152echo ""
153./getans "Is this what you want to use?" yesno 1 .$$
154if (`cat .$$` == 0) then
155   goto getmod
156endif
157endif
158
159cat <<'EOF'
160
161First we need to find out a little bit about the executables needed to
162compile top.
163
164'EOF'
165./getans "What is the full path name for the Bourne shell" file "$Cmdshell" .$$
166set Cmdshell = `cat .$$`
167
168cat <<'EOF'
169
170Please supply the name of the appropriate command.  It need not be a
171full path name, but the named command does need to exist somewhere on
172the current path.
173
174'EOF'
175./getans "AWK Interpreter" path "$Cmdawk" .$$
176set Cmdawk = `cat .$$`
177./getans "C Compiler" path "$Cmdcc" .$$
178set Cmdcc = `cat .$$`
179
180cat <<'EOF'
181
182The installer command needs to understand Berkeley-esque arguments:
183"-o" for owner, "-g" for group, and "-m" for mode.  A shell script
184called "install" is distributed with top and is suitable for use by
185top.  You can specify a different program here if you like, or use
186the shell script (the default).
187
188'EOF'
189./getans "Installer" path "$Cmdinstall" .$$
190set Cmdinstall = `cat .$$`
191
192cat <<EOF
193
194What other options should be used with the $Cmdcc command (use "none" to
195specify no options)?
196EOF
197./getans "Compiler options" string "$cdefs" .$$
198set cdefs = `cat .$$`
199if ("$cdefs" == "none") then
200    set cdefs = ""
201endif
202
203cat <<'EOF'
204
205Now you need to answer some questions concerning the configuration of
206top itself.
207
208The space command forces an immediate update.  Sometimes, on loaded
209systems, this update will take a significant period of time (because all
210the 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
212is pressed before the next update is attempted.  This serves as a visual
213acknowledgement of the command.  "LoadMax" should always be specified as a
214floating point number.
215
216'EOF'
217./getans "LoadMax" number "$LoadMax" .$$
218set LoadMax = `cat .$$`
219
220cat <<'EOF'
221
222"Default TOPN" is the default number of processes to show.  This is the
223number that will be used when the user does not specify the number of
224processes to show.  If you want "all" (or infinity) as the default, use
225the value "-1".
226
227'EOF'
228
229./getans "Default TOPN" neginteger "$topn" .$$
230set topn = `cat .$$`
231
232cat <<'EOF'
233
234"Nominal_TOPN" is used as the default TOPN when Default_TOPN is Infinity
235and the output is a dumb terminal.  If we didn't do this, then
236installations who use a default TOPN of Infinity will get every process in
237the system when running top on a dumb terminal (or redirected to a file).
238Note that Nominal_TOPN is a default: it can still be overridden on the
239command line, even with the value "infinity".
240
241'EOF'
242
243./getans "Nominal TOPN" integer "$NominalTopn" .$$
244set NominalTopn = `cat .$$`
245
246cat <<'EOF'
247
248Default Delay is the default number of seconds to wait between screen
249updates.
250
251'EOF'
252
253./getans "Default Delay" integer "$delay" .$$
254set delay = `cat .$$`
255
256echo ""
257
258set rand = 0
259ypwhich >&/dev/null
260if ($status == 0 || -e /etc/passwd.dir || -e /etc/pwd.db) then
261   set rand = 1
262endif
263
264if ($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'
267else
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'
272endif
273
274if ($nodefaults == 1) then
275   set random = $rand
276endif
277
278./getans "${pr}?" yesno $random .$$
279set random = `cat .$$`
280
281echo ""
282echo "Compiling prime.c"
283$Cmdcc $cdefs -o prime prime.c -lm
284if ($status != 0) then
285    echo "Oh well."
286    rm -f prime
287endif
288
289echo ""
290
291ypcat passwd.byname >&/tmp/$$.a
292if ($status == 0) then
293   set cnt = `wc -l </tmp/$$.a`
294   set mapfile = "NIS map"
295else
296   set cnt = `wc -l </etc/passwd`
297   set mapfile = "file"
298endif
299rm /tmp/$$.a
300set double = `expr $cnt \* 2`
301echo "I found $cnt entries in your passwd $mapfile.  Top hashes the username to"
302echo "uid mappings as it goes along and it needs a good guess on the size of"
303echo "that hash table.  This number should be the next highest prime number"
304echo "after $double."
305echo ""
306if (-e prime) then
307   set pr = `./prime $double`
308   echo "I have calculated that to be $pr."
309else if (-e $PRIME) then
310   set pr = `$PRIME $double | head -1`
311   echo "I have calculated that to be $pr."
312else
313   set pr = $double
314   echo "I cannot calculate that prime number, so you will need to provide it for me."
315endif
316
317if ($TableSize == 0) then
318   set TableSize = $pr
319endif
320
321./getans "Enter the hash table size" integer "$TableSize" .$$
322set TableSize = `cat .$$`
323
324echo ""
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
329set ls = "ls -l"
330if (`$ls getans | wc -w` < 9) then
331   set ls = "ls -lg"
332endif
333
334set t_owner = root
335set t_group = `$ls -d /usr/bin | awk ' { print $4 }'`
336if (-e /proc) then
337   cat <<EOF
338Uh oh!  I see /proc out there.  Some new Unix variants provide the /proc
339file system as a mechanism to get to a process's address space.  This
340directory is typically only accessible by root.  However, there are a few
341systems (such as DG/UX) on which this directory exists, but isn't used.
342I'm going to assume that top needs to run setuid to root, but you should
343double check and use mode 2755 (set group id) if top doesn't really need
344root access.  If you are running SunOS 5.x then you will need to install
345top setuid root (owner root and mode 4711).
346
347EOF
348   set t_mode = 4711
349   set mode = 4711
350else 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
367else
368   echo "It looks like there are no memory device special files."
369   set t_mode = 755
370endif
371if ($nodefaults) then
372   set owner = $t_owner
373   set group = $t_group
374   set mode =  $t_mode
375endif
376echo "Tell me how to set the following when top is installed:"
377./getans "Owner" user "$owner" .$$
378set owner = `cat .$$`
379./getans "Group owner" group "$group" .$$
380set group = `cat .$$`
381./getans "Mode" integer "$mode" .$$
382set mode = `cat .$$`
383rm -f /tmp/$$.b
384
385echo ""
386./getans "Install the executable in this directory" file "$bindir" .$$
387set bindir = `cat .$$`
388
389echo ""
390./getans "Install the manual page in this directory" file "$mandir" .$$
391set mandir = `cat .$$`
392
393echo ""
394./getans "Install the manual page with this extension" string "$manext" .$$
395set manext = `cat .$$`
396
397echo ""
398./getans "Install the manual page as 'man' or 'catman'" string "$mansty" .$$
399set mansty = `cat .$$`
400
401echo ""
402echo "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
408if ($status == 1) then
409   echo "Can't save configuration (nonfatal)"
410else
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
418endif
419
420fast:
421
422# set variables which contain module lists
423set modules = `cat $$.f`
424set manmodules = `cat $$.m`
425
426# clean up
427rm -f $$.f $$.m $$.n
428
429# set the link for machine.c
430rm -f machine.c machine.o
431ln -s machine/m_${module}.c machine.c
432
433# get definitions out of the module file
434set libs = `grep LIBS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
435set cflgs = `grep CFLAGS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
436set tcap = `grep TERMCAP: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
437
438# default for tcap (termcap)
439if ("$tcap" == "") then
440    set tcap="-ltermcap"
441endif
442
443if ( { grep -s SIGKILL /usr/include/signal.h } ) then
444    set signal="/usr/include/signal.h"
445else
446    set signal="/usr/include/sys/signal.h"
447endif
448
449
450echo "Building Makefile..."
451sed -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
474echo "Building top.local.h..."
475sed -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
483echo "Building top.1..."
484sed -e "s|%topn%|$topn|" \
485    -e "s|%delay%|$delay|" \
486        top.X >top.1
487if (-e machine/m_${module}.man ) then
488    cat machine/m_${module}.man >>top.1
489endif
490
491# clean up
492rm -f .$$
493
494echo 'Doing a "make clean".'
495make clean
496
497echo 'To create the executable, type "make".'
498echo 'To install the executable, type "make install".'
499exit 0
500
501byebye:
502rm -f .$$ $$.[fmn] /tmp/$$.[ab]
503exit 1
Note: See TracBrowser for help on using the repository browser.