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