home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume27 / top-3.2 / part03 / Configure
Text File  |  1993-08-08  |  12KB  |  459 lines

  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
  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 = bsd43
  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. # is it a valid one?
  137. grep -s $module $$.n >/dev/null
  138. if ($status != 0) then
  139.     echo "That is not a recognized module name."
  140.     goto getmod
  141. endif
  142.  
  143. # display a full description
  144. sed -e '1,/DESCRIPTION:/d' -e '/^$/,$d' machine/m_${module}.desc
  145.  
  146. # verify it
  147. echo ""
  148. ./getans "Is this what you want to use?" yesno 1 .$$
  149. if (`cat .$$` == 0) then
  150.    goto getmod
  151. endif
  152. endif
  153.  
  154. cat <<'EOF'
  155.  
  156. First we need to find out a little bit about the executables needed to
  157. compile top.
  158.  
  159. 'EOF'
  160. ./getans "What is the full path name for the Bourne shell" file "$Cmdshell" .$$
  161. set Cmdshell = `cat .$$`
  162.  
  163. cat <<'EOF'
  164.  
  165. Please supply the name of the appropriate command.  It need not be a
  166. full path name, but the named command does need to exist somewhere on
  167. the current path.
  168.  
  169. 'EOF'
  170. ./getans "AWK Interpreter" path "$Cmdawk" .$$
  171. set Cmdawk = `cat .$$`
  172. ./getans "Installer" path "$Cmdinstall" .$$
  173. set Cmdinstall = `cat .$$`
  174. ./getans "C Compiler" path "$Cmdcc" .$$
  175. set Cmdcc = `cat .$$`
  176.  
  177. cat <<EOF
  178.  
  179. What other options should be used with the $Cmdcc command (use "none" to
  180. specify no options)?
  181. EOF
  182. ./getans "Compiler options" string "$cdefs" .$$
  183. set cdefs = `cat .$$`
  184. if ($cdefs == "none") then
  185.     set cdefs = ""
  186. endif
  187.  
  188. cat <<'EOF'
  189.  
  190. Now you need to answer some questions concerning the configuration of
  191. top itself.
  192.  
  193. The space command forces an immediate update.  Sometimes, on loaded
  194. systems, this update will take a significant period of time (because all
  195. the output is buffered).  So, if the short-term load average is above
  196. "LoadMax", then top will put the cursor home immediately after the space
  197. is pressed before the next update is attempted.  This serves as a visual
  198. acknowledgement of the command.  "LoadMax" should always be specified as a
  199. floating point number.
  200.  
  201. 'EOF'
  202. ./getans "LoadMax" number "$LoadMax" .$$
  203. set LoadMax = `cat .$$`
  204.  
  205. cat <<'EOF'
  206.  
  207. "Default TOPN" is the default number of processes to show.  This is the
  208. number that will be used when the user does not specify the number of
  209. processes to show.  If you want "all" (or infinity) as the default, use
  210. the value "-1".
  211.  
  212. 'EOF'
  213.  
  214. ./getans "Default TOPN" neginteger "$topn" .$$
  215. set topn = `cat .$$`
  216.  
  217. cat <<'EOF'
  218.  
  219. "Nominal_TOPN" is used as the default TOPN when Default_TOPN is Infinity
  220. and the output is a dumb terminal.  If we didn't do this, then
  221. installations who use a default TOPN of Infinity will get every process in
  222. the system when running top on a dumb terminal (or redirected to a file).
  223. Note that Nominal_TOPN is a default: it can still be overridden on the
  224. command line, even with the value "infinity".
  225.  
  226. 'EOF'
  227.  
  228. ./getans "Nominal TOPN" integer "$NominalTopn" .$$
  229. set NominalTopn = `cat .$$`
  230.  
  231. cat <<'EOF'
  232.  
  233. Default Delay is the default number of seconds to wait between screen
  234. updates.
  235.  
  236. 'EOF'
  237.  
  238. ./getans "Default Delay" integer "$delay" .$$
  239. set delay = `cat .$$`
  240.  
  241. echo ""
  242.  
  243. set rand = 0
  244. ypwhich >&/dev/null
  245. if ($status == 0 || -e /etc/passwd.dir) then
  246.    set rand = 1
  247. endif
  248.  
  249. if ($rand == 1) then
  250.    echo "It looks like you have a passwd file that can be accessed at random."
  251.    set pr = 'Do you want top to take advantage of this'
  252. else
  253.    echo "It looks like you have conventional passwd file access.  Top can take"
  254.    echo "advantage of a random access passwd mechanism if such exists.  Do"
  255.    echo "you want top to assume that accesses to the file /etc/passwd are done"
  256.    set pr = 'with random access rather than sequential'
  257. endif
  258.  
  259. if ($nodefaults == 1) then
  260.    set random = $rand
  261. endif
  262.  
  263. ./getans "${pr}?" yesno $random .$$
  264. set random = `cat .$$`
  265.  
  266. echo ""
  267.  
  268. ypcat passwd.byname >&/tmp/$$.a
  269. if ($status == 0) then
  270.    set cnt = `wc -l </tmp/$$.a`
  271.    set mapfile = "NIS map"
  272. else
  273.    set cnt = `wc -l </etc/passwd`
  274.    set mapfile = "file"
  275. endif
  276. rm /tmp/$$.a
  277. set double = `expr $cnt \* 2`
  278. echo "I found $cnt entries in your passwd $mapfile.  Top hashes the username to"
  279. echo "uid mappings as it goes along and it needs a good guess on the size of"
  280. echo "that hash table.  This number should be the next highest prime number"
  281. echo "after $double."
  282. echo ""
  283. if (-e $PRIME) then
  284.    set pr = `$PRIME $double | head -1`
  285.    echo "I have calculated that to be $pr."
  286. else
  287.    set pr = $double
  288.    echo "I cannot calculate that prime number, so you will need to provide it for me."
  289. endif
  290.  
  291. if ($TableSize == 0) then
  292.    set TableSize = $pr
  293. endif
  294.  
  295. ./getans "Enter the hash table size" integer "$TableSize" .$$
  296. set TableSize = `cat .$$`
  297.  
  298. echo ""
  299.  
  300. # !!! I need to fix this:  /dev/kmem might not exist on some machines !!!
  301.  
  302. # determine the right way to invoke ls to get full output
  303. set ls = "ls -l"
  304. if (`$ls getans | wc -w` < 9) then
  305.    set ls = "ls -lg"
  306. endif
  307.  
  308. set t_owner = root
  309. set t_group = wheel
  310. if (-e /proc) then
  311.    cat <<EOF
  312. Uh oh!  I see /proc out there.  Some new Unix variants provide the /proc
  313. file system as a mechanism to get to a process's address space.  This
  314. directory is typically only accessible by root.  However, there are a few
  315. systems (such as DG/UX) on which this directory exists, but isn't used.
  316. I'm going to assume that top needs to run setuid to root, but you should
  317. double check and use mode 2755 (set group id) if top doesn't really need
  318. root access.  If you are running SunOS 5.x then you will need to install
  319. top setuid root (owner root and mode 4711).
  320.  
  321. EOF
  322.    set t_mode = 4711
  323. else if (-e /dev/kmem) then
  324.    $ls /dev/kmem >/tmp/$$.b
  325.    grep '^....r..r..' /tmp/$$.b >&/dev/null
  326.    if ($status == 1) then
  327.       grep '^....r..-..' /tmp/$$.b >&/dev/null
  328.       if ($status == 0) then
  329.          set t_group = `awk ' { print $4 }' /tmp/$$.b`
  330.          set t_mode = 2755
  331.          echo "It looks like only group $t_group can read the memory devices."
  332.       else
  333.          set t_mode = 4755
  334.          echo "It looks like only root can read the memory devices."
  335.       endif
  336.    else
  337.       set t_mode = 755
  338.       echo "It looks like anybody can read the memory devices."
  339.    endif
  340. else
  341.    echo "It looks like there are no memory device special files."
  342.    set t_mode = 755
  343. endif
  344. if ($nodefaults) then
  345.    set owner = $t_owner
  346.    set group = $t_group
  347.    set mode =  $t_mode
  348. endif
  349. echo "Tell me how to set the following when top is installed:"
  350. ./getans "Owner" user "$owner" .$$
  351. set owner = `cat .$$`
  352. ./getans "Group owner" group "$group" .$$
  353. set group = `cat .$$`
  354. ./getans "Mode" integer "$mode" .$$
  355. set mode = `cat .$$`
  356. rm -f /tmp/$$.b
  357.  
  358. echo ""
  359. ./getans "Install the executable in this directory" file "$bindir" .$$
  360. set bindir = `cat .$$`
  361.  
  362. echo ""
  363. ./getans "Install the manual page in this directory" file "$mandir" .$$
  364. set mandir = `cat .$$`
  365.  
  366. echo ""
  367. ./getans "Install the manual page with this extension" string "$manext" .$$
  368. set manext = `cat .$$`
  369.  
  370. echo ""
  371. ./getans "Install the manual page as 'man' or 'catman'" string "$mansty" .$$
  372. set mansty = `cat .$$`
  373.  
  374. echo ""
  375. echo "We are done with the questions."
  376.  
  377. echo "Saving configuration..."
  378. # save settings to use as defaults the next time
  379. rm -f .defaults
  380. foreach v ($vars)
  381.    set tmp = `eval echo \$$v`
  382.    echo set $v = "'$tmp'" >>.defaults
  383. end
  384.  
  385. fast:
  386.  
  387. # set variables which contain module lists
  388. set modules = `cat $$.f`
  389. set manmodules = `cat $$.m`
  390.  
  391. # clean up
  392. rm -f $$.f $$.m $$.n
  393.  
  394. # set the link for machine.c
  395. rm -f machine.c machine.o
  396. ln -s machine/m_${module}.c machine.c
  397. set libs = `grep LIBS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
  398. set cflgs = `grep CFLAGS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
  399.  
  400. if ( { grep -s SIGINT /usr/include/signal.h } ) then
  401.     set signal="/usr/include/signal.h"
  402. else
  403.     set signal="/usr/include/sys/signal.h"
  404. endif
  405.  
  406.  
  407. echo "Building Makefile..."
  408. sed -e "s|%topn%|$topn|" \
  409.     -e "s|%delay%|$delay|" \
  410.     -e "s|%owner%|$owner|" \
  411.     -e "s|%group%|$group|" \
  412.     -e "s|%mode%|$mode|" \
  413.     -e "s|%bindir%|$bindir|" \
  414.     -e "s|%mandir%|$mandir|" \
  415.     -e "s|%manext%|$manext|" \
  416.     -e "s|%mansty%|$mansty|" \
  417.     -e "s|%tablesize%|$TableSize|" \
  418.     -e "s|%libs%|$libs|" \
  419.     -e "s|%cflgs%|$cflgs|" \
  420.     -e "s|%cdefs%|$cdefs|" \
  421.     -e "s|%modules%|$modules|" \
  422.     -e "s|%manmodules%|$manmodules|" \
  423.     -e "s|%signal%|$signal|" \
  424.     -e "s|%cc%|$Cmdcc|" \
  425.     -e "s|%awk%|$Cmdawk|" \
  426.     -e "s|%install%|$Cmdinstall|" \
  427.     -e "s|%shell%|$Cmdshell|" \
  428.     Makefile.X >Makefile
  429.  
  430. echo "Building top.local.h..."
  431. sed -e "s|%LoadMax%|$LoadMax|" \
  432.     -e "s|%TableSize%|$TableSize|" \
  433.     -e "s|%NominalTopn%|$NominalTopn|" \
  434.     -e "s|%topn%|$topn|" \
  435.     -e "s|%delay%|$delay|" \
  436.     -e "s|%random%|$random|" \
  437.     top.local.H >top.local.h
  438.  
  439. echo "Building top.1..."
  440. sed -e "s|%topn%|$topn|" \
  441.     -e "s|%delay%|$delay|" \
  442.     top.X >top.1
  443. if (-e machine/m_${module}.man ) then
  444.     cat machine/m_${module}.man >>top.1
  445. endif
  446.  
  447. # clean up
  448. rm -f .$$
  449.  
  450. echo 'Doing a "make clean".'
  451. make clean
  452.  
  453. echo 'To create the executable, type "make".'
  454. exit 0
  455.  
  456. byebye:
  457. rm -f .$$ $$.[fmn] /tmp/$$.[ab]
  458. exit 1
  459.