home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Utilities / top-0.5-MI / Configure < prev    next >
Encoding:
Text File  |  1997-01-22  |  12.5 KB  |  490 lines

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