Configure revision 24139
124139Sjoerg#!/bin/csh -f 224139Sjoerg# 324139Sjoerg# Configuration script for top. 424139Sjoerg# 524139Sjoerg# Use with version 3.0 and higher. 624139Sjoerg# 724139Sjoergset PRIME = "/usr/games/primes" 824139Sjoergset vars = (module LoadMax topn NominalTopn delay owner group mode random \ 924139Sjoerg TableSize bindir mandir manext mansty \ 1024139Sjoerg Cmdshell Cmdcc Cmdawk Cmdinstall cdefs) 1124139Sjoergset fastrack = 0 1224139Sjoergset yesno = (no yes) 1324139Sjoerg 1424139Sjoergonintr byebye 1524139Sjoerg 1624139Sjoerg# make sure that getans is there and ready 1724139Sjoergif (! -e getans) then 1824139Sjoerg echo 'This package is not complete. The shell file "getans" is missing.' 1924139Sjoerg exit 10 2024139Sjoergendif 2124139Sjoergchmod +x getans 2224139Sjoerg 2324139Sjoergif ($#argv > 0) then 2424139Sjoerg# fast track configuration 2524139Sjoerg set fastrack = 1 2624139Sjoergelse 2724139Sjoergcat <<'EOF' 2824139SjoergConfiguration for top, version 3.4 2924139Sjoerg 3024139SjoergOne moment.... 3124139Sjoerg'EOF' 3224139Sjoergendif 3324139Sjoerg 3424139Sjoerg# collect file names and module names 3524139Sjoergls machine/m_*.c >$$.f 3624139Sjoergls machine/m_*.man >$$.m 3724139Sjoergsed -e 's@^machine/m_@@' -e 's/.c$//' $$.f >$$.n 3824139Sjoerg 3924139Sjoerg# build Make.desc 4024139Sjoergset descs = `sed -e 's@\.c$@.desc@' $$.f` 4124139Sjoergsed -e "s@%descs%@$descs@" Make.desc.X >Make.desc 4224139Sjoerg 4324139Sjoerg# build desc files and SYNOPSIS as needed 4424139Sjoergmake -f Make.desc >/dev/null 4524139Sjoerg 4624139Sjoergif (-e .defaults) then 4724139Sjoerg echo "" 4824139Sjoerg echo "Reading configuration from last time..." 4924139Sjoerg source .defaults 5024139Sjoerg set nodefaults = 0 5124139Sjoerg if ($fastrack == 1) then 5224139Sjoerg set module = $1 5324139Sjoerg endif 5424139Sjoergelse 5524139Sjoerg if ($fastrack == 1) then 5624139Sjoerg echo "No previous configuration was found." 5724139Sjoerg set fastrack = 0 5824139Sjoerg set module = $1 5924139Sjoerg else 6024139Sjoerg set module = "" 6124139Sjoerg endif 6224139Sjoerg set LoadMax = 5.0 6324139Sjoerg set topn = 15 6424139Sjoerg set NominalTopn = 18 6524139Sjoerg set delay = 5 6624139Sjoerg set TableSize = 0 6724139Sjoerg set bindir = /usr/local/bin 6824139Sjoerg set mandir = /usr/man/manl 6924139Sjoerg set manext = l 7024139Sjoerg set mansty = man 7124139Sjoerg set nodefaults = 1 7224139Sjoerg set Cmdshell = /bin/sh 7324139Sjoerg set Cmdawk = awk 7424139Sjoerg set Cmdinstall = ./install 7524139Sjoerg set Cmdcc = cc 7624139Sjoerg set cdefs = -O 7724139Sjoergendif 7824139Sjoergecho "" 7924139Sjoerg 8024139Sjoergif ($fastrack == 1) then 8124139Sjoerg grep -s $module $$.n >/dev/null 8224139Sjoerg if ($status != 0) then 8324139Sjoerg echo "$module is not recognized. To see a list of available modules" 8424139Sjoerg echo 'run "Configure" with no arguments.' 8524139Sjoerg rm -f $$.[fmn] 8624139Sjoerg exit 1 8724139Sjoerg endif 8824139Sjoerg set random1 = `expr $random + 1` 8924139Sjoerg cat <<EOF 9024139SjoergUsing these settings: 9124139Sjoerg Bourne Shell $Cmdshell 9224139Sjoerg C compiler $Cmdcc 9324139Sjoerg Compiler options $cdefs 9424139Sjoerg Awk command $Cmdawk 9524139Sjoerg Install command $Cmdinstall 9624139Sjoerg 9724139Sjoerg Module $module 9824139Sjoerg LoadMax $LoadMax 9924139Sjoerg Default TOPN $topn 10024139Sjoerg Nominal TOPN $NominalTopn 10124139Sjoerg Default Delay $delay 10224139SjoergRandom passwd access $yesno[$random1] 10324139Sjoerg Table Size $TableSize 10424139Sjoerg Owner $owner 10524139Sjoerg Group Owner $group 10624139Sjoerg Mode $mode 10724139Sjoerg bin directory $bindir 10824139Sjoerg man directory $mandir 10924139Sjoerg man extension $manext 11024139Sjoerg man style $mansty 11124139Sjoerg 11224139SjoergEOF 11324139Sjoerg goto fast 11424139Sjoergendif 11524139Sjoerg 11624139Sjoergcat <<'EOF' 11724139SjoergYou will be asked a series of questions. Each question will have a 11824139Sjoergdefault answer enclosed in brackets, such as "[5.0]". In most cases, 11924139Sjoergthe default answer will work well. To use that value, merely press 12024139Sjoergreturn. 12124139Sjoerg 12224139Sjoerg'EOF' 12324139Sjoerg 12424139Sjoerg# display synopses 12524139Sjoerg 12624139Sjoerggetmod: 12724139Sjoergcat <<'EOF' 12824139Sjoerg 12924139SjoergThe following machine-dependent modules are available: 13024139Sjoerg'EOF' 13124139Sjoergawk -F: ' { printf "%-8s %s\n", $1, $2 }' SYNOPSIS 13224139Sjoergecho '' 13324139Sjoerg./getans "What module is appropriate for this machine? " string "$module" .$$ 13424139Sjoergset module = `cat .$$` 13524139Sjoerg 13624139Sjoergif ("$module" == "") then 13724139Sjoerg echo "Please specify a valid module name." 13824139Sjoerg goto getmod 13924139Sjoergendif 14024139Sjoerg 14124139Sjoerg# is it a valid one? 14224139Sjoerggrep -s "$module" $$.n >/dev/null 14324139Sjoergif ($status != 0) then 14424139Sjoerg echo "That is not a recognized module name." 14524139Sjoerg goto getmod 14624139Sjoergendif 14724139Sjoerg 14824139Sjoerg# display a full description 14924139Sjoergsed -e '1,/DESCRIPTION:/d' -e '/^$/,$d' machine/m_${module}.desc 15024139Sjoerg 15124139Sjoerg# verify it 15224139Sjoergecho "" 15324139Sjoerg./getans "Is this what you want to use?" yesno 1 .$$ 15424139Sjoergif (`cat .$$` == 0) then 15524139Sjoerg goto getmod 15624139Sjoergendif 15724139Sjoergendif 15824139Sjoerg 15924139Sjoergcat <<'EOF' 16024139Sjoerg 16124139SjoergFirst we need to find out a little bit about the executables needed to 16224139Sjoergcompile top. 16324139Sjoerg 16424139Sjoerg'EOF' 16524139Sjoerg./getans "What is the full path name for the Bourne shell" file "$Cmdshell" .$$ 16624139Sjoergset Cmdshell = `cat .$$` 16724139Sjoerg 16824139Sjoergcat <<'EOF' 16924139Sjoerg 17024139SjoergPlease supply the name of the appropriate command. It need not be a 17124139Sjoergfull path name, but the named command does need to exist somewhere on 17224139Sjoergthe current path. 17324139Sjoerg 17424139Sjoerg'EOF' 17524139Sjoerg./getans "AWK Interpreter" path "$Cmdawk" .$$ 17624139Sjoergset Cmdawk = `cat .$$` 17724139Sjoerg./getans "C Compiler" path "$Cmdcc" .$$ 17824139Sjoergset Cmdcc = `cat .$$` 17924139Sjoerg 18024139Sjoergcat <<'EOF' 18124139Sjoerg 18224139SjoergThe installer command needs to understand Berkeley-esque arguments: 18324139Sjoerg"-o" for owner, "-g" for group, and "-m" for mode. A shell script 18424139Sjoergcalled "install" is distributed with top and is suitable for use by 18524139Sjoergtop. You can specify a different program here if you like, or use 18624139Sjoergthe shell script (the default). 18724139Sjoerg 18824139Sjoerg'EOF' 18924139Sjoerg./getans "Installer" path "$Cmdinstall" .$$ 19024139Sjoergset Cmdinstall = `cat .$$` 19124139Sjoerg 19224139Sjoergcat <<EOF 19324139Sjoerg 19424139SjoergWhat other options should be used with the $Cmdcc command (use "none" to 19524139Sjoergspecify no options)? 19624139SjoergEOF 19724139Sjoerg./getans "Compiler options" string "$cdefs" .$$ 19824139Sjoergset cdefs = `cat .$$` 19924139Sjoergif ("$cdefs" == "none") then 20024139Sjoerg set cdefs = "" 20124139Sjoergendif 20224139Sjoerg 20324139Sjoergcat <<'EOF' 20424139Sjoerg 20524139SjoergNow you need to answer some questions concerning the configuration of 20624139Sjoergtop itself. 20724139Sjoerg 20824139SjoergThe space command forces an immediate update. Sometimes, on loaded 20924139Sjoergsystems, this update will take a significant period of time (because all 21024139Sjoergthe output is buffered). So, if the short-term load average is above 21124139Sjoerg"LoadMax", then top will put the cursor home immediately after the space 21224139Sjoergis pressed before the next update is attempted. This serves as a visual 21324139Sjoergacknowledgement of the command. "LoadMax" should always be specified as a 21424139Sjoergfloating point number. 21524139Sjoerg 21624139Sjoerg'EOF' 21724139Sjoerg./getans "LoadMax" number "$LoadMax" .$$ 21824139Sjoergset LoadMax = `cat .$$` 21924139Sjoerg 22024139Sjoergcat <<'EOF' 22124139Sjoerg 22224139Sjoerg"Default TOPN" is the default number of processes to show. This is the 22324139Sjoergnumber that will be used when the user does not specify the number of 22424139Sjoergprocesses to show. If you want "all" (or infinity) as the default, use 22524139Sjoergthe value "-1". 22624139Sjoerg 22724139Sjoerg'EOF' 22824139Sjoerg 22924139Sjoerg./getans "Default TOPN" neginteger "$topn" .$$ 23024139Sjoergset topn = `cat .$$` 23124139Sjoerg 23224139Sjoergcat <<'EOF' 23324139Sjoerg 23424139Sjoerg"Nominal_TOPN" is used as the default TOPN when Default_TOPN is Infinity 23524139Sjoergand the output is a dumb terminal. If we didn't do this, then 23624139Sjoerginstallations who use a default TOPN of Infinity will get every process in 23724139Sjoergthe system when running top on a dumb terminal (or redirected to a file). 23824139SjoergNote that Nominal_TOPN is a default: it can still be overridden on the 23924139Sjoergcommand line, even with the value "infinity". 24024139Sjoerg 24124139Sjoerg'EOF' 24224139Sjoerg 24324139Sjoerg./getans "Nominal TOPN" integer "$NominalTopn" .$$ 24424139Sjoergset NominalTopn = `cat .$$` 24524139Sjoerg 24624139Sjoergcat <<'EOF' 24724139Sjoerg 24824139SjoergDefault Delay is the default number of seconds to wait between screen 24924139Sjoergupdates. 25024139Sjoerg 25124139Sjoerg'EOF' 25224139Sjoerg 25324139Sjoerg./getans "Default Delay" integer "$delay" .$$ 25424139Sjoergset delay = `cat .$$` 25524139Sjoerg 25624139Sjoergecho "" 25724139Sjoerg 25824139Sjoergset rand = 0 25924139Sjoergypwhich >&/dev/null 26024139Sjoergif ($status == 0 || -e /etc/passwd.dir || -e /etc/pwd.db) then 26124139Sjoerg set rand = 1 26224139Sjoergendif 26324139Sjoerg 26424139Sjoergif ($rand == 1) then 26524139Sjoerg echo "It looks like you have a passwd file that can be accessed at random." 26624139Sjoerg set pr = 'Do you want top to take advantage of this' 26724139Sjoergelse 26824139Sjoerg echo "It looks like you have conventional passwd file access. Top can take" 26924139Sjoerg echo "advantage of a random access passwd mechanism if such exists. Do" 27024139Sjoerg echo "you want top to assume that accesses to the file /etc/passwd are done" 27124139Sjoerg set pr = 'with random access rather than sequential' 27224139Sjoergendif 27324139Sjoerg 27424139Sjoergif ($nodefaults == 1) then 27524139Sjoerg set random = $rand 27624139Sjoergendif 27724139Sjoerg 27824139Sjoerg./getans "${pr}?" yesno $random .$$ 27924139Sjoergset random = `cat .$$` 28024139Sjoerg 28124139Sjoergecho "" 28224139Sjoergecho "Compiling prime.c" 28324139Sjoerg$Cmdcc $cdefs -o prime prime.c -lm 28424139Sjoergif ($status != 0) then 28524139Sjoerg echo "Oh well." 28624139Sjoerg rm -f prime 28724139Sjoergendif 28824139Sjoerg 28924139Sjoergecho "" 29024139Sjoerg 29124139Sjoergypcat passwd.byname >&/tmp/$$.a 29224139Sjoergif ($status == 0) then 29324139Sjoerg set cnt = `wc -l </tmp/$$.a` 29424139Sjoerg set mapfile = "NIS map" 29524139Sjoergelse 29624139Sjoerg set cnt = `wc -l </etc/passwd` 29724139Sjoerg set mapfile = "file" 29824139Sjoergendif 29924139Sjoergrm /tmp/$$.a 30024139Sjoergset double = `expr $cnt \* 2` 30124139Sjoergecho "I found $cnt entries in your passwd $mapfile. Top hashes the username to" 30224139Sjoergecho "uid mappings as it goes along and it needs a good guess on the size of" 30324139Sjoergecho "that hash table. This number should be the next highest prime number" 30424139Sjoergecho "after $double." 30524139Sjoergecho "" 30624139Sjoergif (-e prime) then 30724139Sjoerg set pr = `./prime $double` 30824139Sjoerg echo "I have calculated that to be $pr." 30924139Sjoergelse if (-e $PRIME) then 31024139Sjoerg set pr = `$PRIME $double | head -1` 31124139Sjoerg echo "I have calculated that to be $pr." 31224139Sjoergelse 31324139Sjoerg set pr = $double 31424139Sjoerg echo "I cannot calculate that prime number, so you will need to provide it for me." 31524139Sjoergendif 31624139Sjoerg 31724139Sjoergif ($TableSize == 0) then 31824139Sjoerg set TableSize = $pr 31924139Sjoergendif 32024139Sjoerg 32124139Sjoerg./getans "Enter the hash table size" integer "$TableSize" .$$ 32224139Sjoergset TableSize = `cat .$$` 32324139Sjoerg 32424139Sjoergecho "" 32524139Sjoerg 32624139Sjoerg# !!! I need to fix this: /dev/kmem might not exist on some machines !!! 32724139Sjoerg 32824139Sjoerg# determine the right way to invoke ls to get full output 32924139Sjoergset ls = "ls -l" 33024139Sjoergif (`$ls getans | wc -w` < 9) then 33124139Sjoerg set ls = "ls -lg" 33224139Sjoergendif 33324139Sjoerg 33424139Sjoergset t_owner = root 33524139Sjoergset t_group = `$ls -d /usr/bin | awk ' { print $4 }'` 33624139Sjoergif (-e /proc) then 33724139Sjoerg cat <<EOF 33824139SjoergUh oh! I see /proc out there. Some new Unix variants provide the /proc 33924139Sjoergfile system as a mechanism to get to a process's address space. This 34024139Sjoergdirectory is typically only accessible by root. However, there are a few 34124139Sjoergsystems (such as DG/UX) on which this directory exists, but isn't used. 34224139SjoergI'm going to assume that top needs to run setuid to root, but you should 34324139Sjoergdouble check and use mode 2755 (set group id) if top doesn't really need 34424139Sjoergroot access. If you are running SunOS 5.x then you will need to install 34524139Sjoergtop setuid root (owner root and mode 4711). 34624139Sjoerg 34724139SjoergEOF 34824139Sjoerg set t_mode = 4711 34924139Sjoerg set mode = 4711 35024139Sjoergelse if (-e /dev/kmem) then 35124139Sjoerg $ls /dev/kmem >/tmp/$$.b 35224139Sjoerg grep '^....r..r..' /tmp/$$.b >&/dev/null 35324139Sjoerg if ($status == 1) then 35424139Sjoerg grep '^....r..-..' /tmp/$$.b >&/dev/null 35524139Sjoerg if ($status == 0) then 35624139Sjoerg set t_group = `awk ' { print $4 }' /tmp/$$.b` 35724139Sjoerg set t_mode = 2755 35824139Sjoerg echo "It looks like only group $t_group can read the memory devices." 35924139Sjoerg else 36024139Sjoerg set t_mode = 4755 36124139Sjoerg echo "It looks like only root can read the memory devices." 36224139Sjoerg endif 36324139Sjoerg else 36424139Sjoerg set t_mode = 755 36524139Sjoerg echo "It looks like anybody can read the memory devices." 36624139Sjoerg endif 36724139Sjoergelse 36824139Sjoerg echo "It looks like there are no memory device special files." 36924139Sjoerg set t_mode = 755 37024139Sjoergendif 37124139Sjoergif ($nodefaults) then 37224139Sjoerg set owner = $t_owner 37324139Sjoerg set group = $t_group 37424139Sjoerg set mode = $t_mode 37524139Sjoergendif 37624139Sjoergecho "Tell me how to set the following when top is installed:" 37724139Sjoerg./getans "Owner" user "$owner" .$$ 37824139Sjoergset owner = `cat .$$` 37924139Sjoerg./getans "Group owner" group "$group" .$$ 38024139Sjoergset group = `cat .$$` 38124139Sjoerg./getans "Mode" integer "$mode" .$$ 38224139Sjoergset mode = `cat .$$` 38324139Sjoergrm -f /tmp/$$.b 38424139Sjoerg 38524139Sjoergecho "" 38624139Sjoerg./getans "Install the executable in this directory" file "$bindir" .$$ 38724139Sjoergset bindir = `cat .$$` 38824139Sjoerg 38924139Sjoergecho "" 39024139Sjoerg./getans "Install the manual page in this directory" file "$mandir" .$$ 39124139Sjoergset mandir = `cat .$$` 39224139Sjoerg 39324139Sjoergecho "" 39424139Sjoerg./getans "Install the manual page with this extension" string "$manext" .$$ 39524139Sjoergset manext = `cat .$$` 39624139Sjoerg 39724139Sjoergecho "" 39824139Sjoerg./getans "Install the manual page as 'man' or 'catman'" string "$mansty" .$$ 39924139Sjoergset mansty = `cat .$$` 40024139Sjoerg 40124139Sjoergecho "" 40224139Sjoergecho "We are done with the questions." 40324139Sjoerg 40424139Sjoerg# Some Unix environments are so poor that their csh doesn't even support 40524139Sjoerg# the "eval" builtin. Check for this before relying on its use to save 40624139Sjoerg# the current configuration. 40724139Sjoerg/bin/csh -c "eval echo foo" >&/dev/null 40824139Sjoergif ($status == 1) then 40924139Sjoerg echo "Can't save configuration (nonfatal)" 41024139Sjoergelse 41124139Sjoerg echo "Saving configuration..." 41224139Sjoerg# save settings to use as defaults the next time 41324139Sjoerg rm -f .defaults 41424139Sjoerg foreach v ($vars) 41524139Sjoerg set tmp = `eval echo \$$v` 41624139Sjoerg echo set $v = "'$tmp'" >>.defaults 41724139Sjoerg end 41824139Sjoergendif 41924139Sjoerg 42024139Sjoergfast: 42124139Sjoerg 42224139Sjoerg# set variables which contain module lists 42324139Sjoergset modules = `cat $$.f` 42424139Sjoergset manmodules = `cat $$.m` 42524139Sjoerg 42624139Sjoerg# clean up 42724139Sjoergrm -f $$.f $$.m $$.n 42824139Sjoerg 42924139Sjoerg# set the link for machine.c 43024139Sjoergrm -f machine.c machine.o 43124139Sjoergln -s machine/m_${module}.c machine.c 43224139Sjoerg 43324139Sjoerg# get definitions out of the module file 43424139Sjoergset libs = `grep LIBS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'` 43524139Sjoergset cflgs = `grep CFLAGS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'` 43624139Sjoergset tcap = `grep TERMCAP: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'` 43724139Sjoerg 43824139Sjoerg# default for tcap (termcap) 43924139Sjoergif ("$tcap" == "") then 44024139Sjoerg set tcap="-ltermcap" 44124139Sjoergendif 44224139Sjoerg 44324139Sjoergif ( { grep -s SIGKILL /usr/include/signal.h } ) then 44424139Sjoerg set signal="/usr/include/signal.h" 44524139Sjoergelse 44624139Sjoerg set signal="/usr/include/sys/signal.h" 44724139Sjoergendif 44824139Sjoerg 44924139Sjoerg 45024139Sjoergecho "Building Makefile..." 45124139Sjoergsed -e "s|%topn%|$topn|" \ 45224139Sjoerg -e "s|%delay%|$delay|" \ 45324139Sjoerg -e "s|%owner%|$owner|" \ 45424139Sjoerg -e "s|%group%|$group|" \ 45524139Sjoerg -e "s|%mode%|$mode|" \ 45624139Sjoerg -e "s|%bindir%|$bindir|" \ 45724139Sjoerg -e "s|%mandir%|$mandir|" \ 45824139Sjoerg -e "s|%manext%|$manext|" \ 45924139Sjoerg -e "s|%mansty%|$mansty|" \ 46024139Sjoerg -e "s|%tablesize%|$TableSize|" \ 46124139Sjoerg -e "s|%libs%|$libs|" \ 46224139Sjoerg -e "s|%cflgs%|$cflgs|" \ 46324139Sjoerg -e "s|%termcap%|$tcap|" \ 46424139Sjoerg -e "s|%cdefs%|$cdefs|" \ 46524139Sjoerg -e "s|%modules%|$modules|" \ 46624139Sjoerg -e "s|%manmodules%|$manmodules|" \ 46724139Sjoerg -e "s|%signal%|$signal|" \ 46824139Sjoerg -e "s|%cc%|$Cmdcc|" \ 46924139Sjoerg -e "s|%awk%|$Cmdawk|" \ 47024139Sjoerg -e "s|%install%|$Cmdinstall|" \ 47124139Sjoerg -e "s|%shell%|$Cmdshell|" \ 47224139Sjoerg Makefile.X >Makefile 47324139Sjoerg 47424139Sjoergecho "Building top.local.h..." 47524139Sjoergsed -e "s|%LoadMax%|$LoadMax|" \ 47624139Sjoerg -e "s|%TableSize%|$TableSize|" \ 47724139Sjoerg -e "s|%NominalTopn%|$NominalTopn|" \ 47824139Sjoerg -e "s|%topn%|$topn|" \ 47924139Sjoerg -e "s|%delay%|$delay|" \ 48024139Sjoerg -e "s|%random%|$random|" \ 48124139Sjoerg top.local.H >top.local.h 48224139Sjoerg 48324139Sjoergecho "Building top.1..." 48424139Sjoergsed -e "s|%topn%|$topn|" \ 48524139Sjoerg -e "s|%delay%|$delay|" \ 48624139Sjoerg top.X >top.1 48724139Sjoergif (-e machine/m_${module}.man ) then 48824139Sjoerg cat machine/m_${module}.man >>top.1 48924139Sjoergendif 49024139Sjoerg 49124139Sjoerg# clean up 49224139Sjoergrm -f .$$ 49324139Sjoerg 49424139Sjoergecho 'Doing a "make clean".' 49524139Sjoergmake clean 49624139Sjoerg 49724139Sjoergecho 'To create the executable, type "make".' 49824139Sjoergecho 'To install the executable, type "make install".' 49924139Sjoergexit 0 50024139Sjoerg 50124139Sjoergbyebye: 50224139Sjoergrm -f .$$ $$.[fmn] /tmp/$$.[ab] 50324139Sjoergexit 1 504