📄 configure
字号:
#!/bin/csh -f## Configuration script for top.## Use with version 3.0 and higher.#set PRIME = "/usr/games/primes"set vars = (module LoadMax topn NominalTopn delay owner group mode random \ TableSize bindir mandir manext mansty \ Cmdshell Cmdcc Cmdawk Cmdinstall cdefs)set fastrack = 0set yesno = (no yes)onintr byebye# make sure that getans is there and readyif (! -e getans) then echo 'This package is not complete. The shell file "getans" is missing.' exit 10endifchmod +x getansif ($#argv > 0) then# fast track configuration set fastrack = 1elsecat <<'EOF'Configuration for top, version 3.5One moment....'EOF'endif# collect file names and module namesls machine/m_*.c >$$.fls machine/m_*.man >$$.msed -e 's@^machine/m_@@' -e 's/.c$//' $$.f >$$.n# build Make.descsed -e 's@\.c@.desc\\@' $$.f | sed -e '$s/\\//' >$$.ased -e "/^DESCS/r $$.a" Make.desc.X >Make.desc# build desc files and SYNOPSIS as neededmake -f Make.desc >/dev/nullif ($status != 0) then echo "Unable to build the synopsis." echo 'Make sure the command "make" is on your path and try' echo 'running Configure again.' exit 1endifif (-e .defaults) then echo "" echo "Reading configuration from last time..." source .defaults set nodefaults = 0 if ($fastrack == 1) then set module = $1 endifelse if ($fastrack == 1) then echo "No previous configuration was found." set fastrack = 0 set module = $1 else set module = "" endif set LoadMax = 5.0 set topn = 15 set NominalTopn = 18 set delay = 5 set TableSize = 0 set bindir = /usr/local/bin set mandir = /usr/man/manl set manext = l set mansty = man set nodefaults = 1 set Cmdshell = /bin/sh set Cmdawk = awk set Cmdinstall = ./install set Cmdcc = cc set cdefs = -Oendifecho ""if ($fastrack == 1) then grep -s $module $$.n >/dev/null if ($status != 0) then echo "$module is not recognized. To see a list of available modules" echo 'run "Configure" with no arguments.' rm -f $$.[fmna] exit 1 endif set random1 = `expr $random + 1` cat <<EOFUsing these settings: Bourne Shell $Cmdshell C compiler $Cmdcc Compiler options $cdefs Awk command $Cmdawk Install command $Cmdinstall Module $module LoadMax $LoadMax Default TOPN $topn Nominal TOPN $NominalTopn Default Delay $delayRandom passwd access $yesno[$random1] Table Size $TableSize Owner $owner Group Owner $group Mode $mode bin directory $bindir man directory $mandir man extension $manext man style $manstyEOF goto fastendifcat <<'EOF'You will be asked a series of questions. Each question will have adefault answer enclosed in brackets, such as "[5.0]". In most cases,the default answer will work well. To use that value, merely pressreturn.'EOF'# display synopsesgetmod:cat <<'EOF'The following machine-dependent modules are available:'EOF'awk -F: ' { printf "%-10s %s\n", $1, $2 }' SYNOPSISecho ''./getans "What module is appropriate for this machine? " string "$module" .$$set module = `cat .$$`if ("$module" == "") then echo "Please specify a valid module name." goto getmodendif# is it a valid one?grep -s "$module" $$.n >/dev/nullif ($status != 0) then echo "That is not a recognized module name." goto getmodendif# display a full descriptionsed -e '1,/DESCRIPTION:/d' -e '/^$/,$d' machine/m_${module}.desc# verify itecho ""./getans "Is this what you want to use?" yesno 1 .$$if (`cat .$$` == 0) then goto getmodendifendifcat <<'EOF'First we need to find out a little bit about the executables needed tocompile top.'EOF'./getans "What is the full path name for the Bourne shell" file "$Cmdshell" .$$set Cmdshell = `cat .$$`cat <<'EOF'Please supply the name of the appropriate command. It need not be afull path name, but the named command does need to exist somewhere onthe current path.'EOF'./getans "AWK Interpreter" path "$Cmdawk" .$$set Cmdawk = `cat .$$`./getans "C Compiler" path "$Cmdcc" .$$set Cmdcc = `cat .$$`cat <<'EOF'The installer command needs to understand Berkeley-esque arguments:"-o" for owner, "-g" for group, and "-m" for mode. A shell scriptcalled "install" is distributed with top and is suitable for use bytop. You can specify a different program here if you like, or usethe shell script (the default).'EOF'./getans "Installer" path "$Cmdinstall" .$$set Cmdinstall = `cat .$$`cat <<EOFWhat other options should be used with the $Cmdcc command (use "none" tospecify no options)?EOF./getans "Compiler options" string "$cdefs" .$$set cdefs = `cat .$$`if ("$cdefs" == "none") then set cdefs = ""endifcat <<'EOF'Now you need to answer some questions concerning the configuration oftop itself.The space command forces an immediate update. Sometimes, on loadedsystems, this update will take a significant period of time (because allthe output is buffered). So, if the short-term load average is above"LoadMax", then top will put the cursor home immediately after the spaceis pressed before the next update is attempted. This serves as a visualacknowledgement of the command. "LoadMax" should always be specified as afloating point number.'EOF'./getans "LoadMax" number "$LoadMax" .$$set LoadMax = `cat .$$`cat <<'EOF'"Default TOPN" is the default number of processes to show. This is thenumber that will be used when the user does not specify the number ofprocesses to show. If you want "all" (or infinity) as the default, usethe value "-1".'EOF'./getans "Default TOPN" neginteger "$topn" .$$set topn = `cat .$$`cat <<'EOF'"Nominal_TOPN" is used as the default TOPN when Default_TOPN is Infinityand the output is a dumb terminal. If we didn't do this, theninstallations who use a default TOPN of Infinity will get every process inthe system when running top on a dumb terminal (or redirected to a file).Note that Nominal_TOPN is a default: it can still be overridden on thecommand line, even with the value "infinity".'EOF'./getans "Nominal TOPN" integer "$NominalTopn" .$$set NominalTopn = `cat .$$`cat <<'EOF'Default Delay is the default number of seconds to wait between screenupdates.'EOF'./getans "Default Delay" integer "$delay" .$$set delay = `cat .$$`echo ""set rand = 0if (-e /etc/nsswitch.conf) then set rand = `grep '^passwd:.*nis' /etc/nsswitch.conf | wc -l` if ($rand > 1) then set rand = 1 endifelse ypwhich >&/dev/null if ($status == 0 || -e /etc/passwd.dir || -e /etc/pwd.db) then set rand = 1 endifendifif ($rand == 1) then echo "It looks like you have a passwd file that can be accessed at random." set pr = 'Do you want top to take advantage of this'else echo "It looks like you have conventional passwd file access. Top can take" echo "advantage of a random access passwd mechanism if such exists. Do" echo "you want top to assume that accesses to the file /etc/passwd are done" set pr = 'with random access rather than sequential'endifif ($nodefaults == 1) then set random = $randendif./getans "${pr}?" yesno $random .$$set random = `cat .$$`echo ""echo "Compiling prime.c"$Cmdcc $cdefs -o prime prime.c -lmif ($status != 0) then echo "Oh well." rm -f primeendifecho ""ypcat passwd.byname >&/tmp/$$.aif ($status == 0) then set cnt = `wc -l </tmp/$$.a` set mapfile = "NIS map"else rm /tmp/$$.a niscat passwd.org_dir >&/tmp/$$.a if ($status == 0) then set cnt = `wc -l </tmp/$$.a` set mapfile = "NISPLUS map" else set cnt = `wc -l </etc/passwd` set mapfile = "file" endifendifrm /tmp/$$.aset double = `expr $cnt \* 2`echo "I found $cnt entries in your passwd $mapfile. Top hashes the username to"echo "uid mappings as it goes along and it needs a good guess on the size of"echo "that hash table. This number should be the next highest prime number"echo "after $double."echo ""if (-e prime) then set pr = `./prime $double` echo "I have calculated that to be $pr."else if (-e $PRIME) then set pr = `$PRIME $double | head -1` echo "I have calculated that to be $pr."else set pr = $double echo "I cannot calculate that prime number, so you will need to provide it for me."endifif ($TableSize == 0) then set TableSize = $prendif./getans "Enter the hash table size" integer "$TableSize" .$$set TableSize = `cat .$$`echo ""# !!! I need to fix this: /dev/kmem might not exist on some machines !!!# determine the right way to invoke ls to get full outputset ls = "ls -l"if (`$ls getans | wc -w` < 9) then set ls = "ls -lg"endifset t_owner = rootset t_group = `$ls -d /usr/bin | awk ' { print $4 }'`if (-e /proc) then cat <<EOFI see /proc out there. Many Unix variants provide the /proc filesystem as a mechanism to get to a process's address space. Thisdirectory is typically only accessible by root. However, there are afew systems (such as DG/UX) on which this directory exists, but isn'tused.EOF if (-r /proc/0/psinfo) then set t_mode = 2711 set mode = 2711 set t_group = sys set group = sys cat <<EOFIt looks like this system is running Solaris 2.6 or greater. If thisis the case, then top can function just fine installed set group id tosys. It does not need to be installed set-uid to root.EOF else set t_mode = 4711 set mode = 4711 cat <<EOFI'm going to assume that top needs to run setuid to root, but youshould double check and use mode 2755 (set group id) if top doesn'treally need root access. If you are running SunOS 5.0 through SunOS5.5.1 (that's Solaris 2.0 through Solaris 2.5.1) then you will need toinstall top setuid root (owner root and mode 4711). In SunOS 5.6 and higher top only requires set group id sys permissions.EOF endifelse if (-e /dev/kmem) then $ls /dev/kmem >/tmp/$$.b grep '^....r..r..' /tmp/$$.b >&/dev/null if ($status == 1) then grep '^....r..-..' /tmp/$$.b >&/dev/null if ($status == 0) then set t_group = `awk ' { print $4 }' /tmp/$$.b` set t_mode = 2755 echo "It looks like only group $t_group can read the memory devices." else set t_mode = 4755 echo "It looks like only root can read the memory devices." endif else set t_mode = 755 echo "It looks like anybody can read the memory devices." endifelse echo "It looks like there are no memory device special files." set t_mode = 755endifif ($nodefaults) then set owner = $t_owner set group = $t_group set mode = $t_modeendifecho "Tell me how to set the following when top is installed:"./getans "Owner" user "$owner" .$$set owner = `cat .$$`./getans "Group owner" group "$group" .$$set group = `cat .$$`./getans "Mode" integer "$mode" .$$set mode = `cat .$$`rm -f /tmp/$$.becho ""./getans "Install the executable in this directory" file "$bindir" .$$set bindir = `cat .$$`echo ""./getans "Install the manual page in this directory" file "$mandir" .$$set mandir = `cat .$$`echo ""./getans "Install the manual page with this extension" string "$manext" .$$set manext = `cat .$$`echo ""./getans "Install the manual page as 'man' or 'catman'" string "$mansty" .$$set mansty = `cat .$$`echo ""echo "We are done with the questions."# Some Unix environments are so poor that their csh doesn't even support# the "eval" builtin. Check for this before relying on its use to save# the current configuration./bin/csh -fc "eval echo foo" >&/dev/nullif ($status == 1) then echo "Can't save configuration (nonfatal)"else echo "Saving configuration..."# save settings to use as defaults the next time rm -f .defaults touch .defaults foreach v ($vars) set tmp = `eval echo \$$v` echo set $v = "'$tmp'" >>.defaults endendiffast:# clean uprm -f $$.[fmna]# set the link for machine.crm -f machine.c machine.oln -s machine/m_${module}.c machine.c# get definitions out of the module fileset libs = `grep LIBS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`set cflgs = `grep CFLAGS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`set tcap = `grep TERMCAP: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`set math = `grep MATH: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`# get osrev defition, if we canset uname=""if (-e /usr/bin/uname) then set uname=/usr/bin/unameelse if (-e /bin/uname) then set uname=/bin/unameendifif ("$uname" != "") then# different versions of tr can't agree on the way to specify ranges, so# we will have to give the range explicitly.....sigh. set osrev="-DOSREV=`$uname -r | tr -cd ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`"else set osrev=""endif# default for tcap (termcap)if ("$tcap" == "") then set tcap="-ltermcap"else if ("$tcap" == "none") then set tcap=""endif# allow for the module to override or remove -lmif ("$math" == "") then set math="-lm"else if ("$math" == "none") then set math=""endifif ( { grep -s SIGKILL /usr/include/signal.h } ) then set signal="/usr/include/signal.h"else set signal="/usr/include/sys/signal.h"endifecho "Building Makefile..."sed -e "s|%topn%|$topn|" \ -e "s|%delay%|$delay|" \ -e "s|%owner%|$owner|" \ -e "s|%group%|$group|" \ -e "s|%mode%|$mode|" \ -e "s|%bindir%|$bindir|" \ -e "s|%mandir%|$mandir|" \ -e "s|%manext%|$manext|" \ -e "s|%mansty%|$mansty|" \ -e "s|%tablesize%|$TableSize|" \ -e "s|%libs%|$libs|" \ -e "s|%cflgs%|$cflgs|" \ -e "s|%termcap%|$tcap|" \ -e "s|%math%|$math|" \ -e "s|%cdefs%|$cdefs|" \ -e "s|%signal%|$signal|" \ -e "s|%cc%|$Cmdcc|" \ -e "s|%awk%|$Cmdawk|" \ -e "s|%install%|$Cmdinstall|" \ -e "s|%shell%|$Cmdshell|" \ -e "s|%osrev%|$osrev|" \ Makefile.X >Makefileecho "Building top.local.h..."sed -e "s|%LoadMax%|$LoadMax|" \ -e "s|%TableSize%|$TableSize|" \ -e "s|%NominalTopn%|$NominalTopn|" \ -e "s|%topn%|$topn|" \ -e "s|%delay%|$delay|" \ -e "s|%random%|$random|" \ top.local.H >top.local.hecho "Building top.1..."sed -e "s|%topn%|$topn|" \ -e "s|%delay%|$delay|" \ top.X >top.1if (-e machine/m_${module}.man ) then cat machine/m_${module}.man >>top.1endif# clean uprm -f .$$echo 'Doing a "make clean".'make cleanecho 'To create the executable, type "make".'echo 'To install the executable, type "make install".'exit 0byebye:rm -f .$$ $$.[fmna] /tmp/$$.[ab]exit 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -