home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / cops_104.zip / cops_104 / reconfig < prev    next >
Text File  |  1992-03-10  |  6KB  |  210 lines

  1. :
  2. #
  3. #  Usage: reconfig [file]
  4. #
  5. #   This replaces the program paths (e.g. /bin/awk) in COPS with an
  6. # alternate path that is found in the file "file.paths".  Alternately,
  7. # you can specify a single file to reconfig.
  8. #   All programs are renamed "name.old", and the new version replaces
  9. # the original name.  It then uses sed to replace all occurances of
  10. # the target strings.
  11. #   Basically, the program looks through all directories listed in
  12. # $all_dirs for the list of programs in $all_commands and when it finds
  13. # them, puts them in a sed source file.  It then goes to all of the
  14. # shell files COPS uses ($shell_scripts) and replaces all occurances of
  15. # the variables found with the new value.  It goes through some
  16. # contortions trying to look for test (it has to find test without
  17. # using test), and does some other not so smart things, but it seems
  18. # to get the job done.
  19.  
  20. # shell is always here, isn't it?
  21. SH=/bin/sh
  22.  
  23. # need these later
  24. TEST=
  25. AWK=
  26. SED=
  27. TR=
  28.  
  29. # various types of awks; I'd really like to get gawk or mawk,
  30. # but even nawk would be great.  In order:
  31. all_awks="gawk mawk nawk awk"
  32.  
  33. #  Potential directories to find commands:
  34. all_dirs='/bin /usr/bin /usr/ucb /usr/local/bin /usr/bsd'
  35.  
  36. #   First things first; are test and echo built-in shell commands?
  37. # Theory.  If test is executed correctly and not found in the path
  38. # I set, then they should be built into the shell, right?
  39. PATH=/bin:/usr/bin
  40. for dir in $all_dirs
  41.     do
  42.     if test -f $dir/test
  43.         then
  44.         TEST=$dir/test
  45.         break
  46.     fi
  47.     done
  48. # if not set, then set to default
  49. if test -z "$TEST"
  50.     then
  51.     TEST=test
  52.     fi
  53.  
  54. for dir in $all_dirs
  55.     do
  56.     if $TEST -f "$dir/echo"
  57.         then
  58.         ECHO=$dir/echo
  59.         break
  60.     fi
  61.     done
  62.  
  63. # if not set, then set to default
  64. if $TEST -z "$ECHO"
  65.     then
  66.     ECHO=echo
  67.     fi
  68.  
  69. # The sed filter file
  70. location=./file.paths
  71.  
  72. #  Target shell scripts in question:
  73. if $TEST $# -ne 0 ; then
  74.     shell_scripts="$*"
  75. else
  76.     doc_make=docs/makefile
  77.     shell_scripts="makefile $doc_make chk_strings cops crc.chk \
  78.         misc.chk dev.chk ftp.chk is_able.chk cron.chk group.chk \
  79.         passwd.chk rc.chk root.chk suid.chk kuang init_kuang \
  80.         res_diff pass_diff.chk yp_pass.chk"
  81.     fi
  82.  
  83. #  Target commands in question, sans those checked above:
  84. all_commands='cc nroff cat chmod cmp comm cp date diff egrep expr find grep ls mail mkdir mv rm sed sh sort tftp touch uniq uudecode ypcat strings'
  85.  
  86. $ECHO checking to make sure all the target\(s\) are here...
  87. #  make sure everything is here:
  88. for i in $shell_scripts
  89.     do
  90.     if $TEST ! -s $i
  91.         then
  92.         $ECHO  ERROR -- $i not found!
  93.         exit
  94.     fi
  95. done
  96.  
  97. #   This finds the paths to any program used in COPS, then prints out
  98. # a sed filter to the file "file.paths" that is used by this shell
  99. # script to change all occurances of that command in the COPS system.
  100. #
  101. #   For example, if sed is in /usr/bin, it will create a line that looks
  102. # like this:
  103. #
  104. # s.SED=*$.SED=/usr/bin/sed.
  105. #
  106. #  This corresponds to the sed command substitute ("-" is used as a
  107. # delineator instead of "/" because the strings will be containing
  108. # "/"'s) /usr/bin/sed in place of whatever was to the right of the
  109. # equal sign.  This works because all commands are accessed by the
  110. # variable "$XYZ", where "XYZ" corresponds to the lowercase command
  111. # "xyz".  And, of course, all command variables are set at the top
  112. # of each command file.
  113. #
  114.  
  115. # First we need awk and sed if this shell script will work....
  116. for dir in $all_dirs ; do
  117.     if $TEST -f $dir/sed ; then
  118.         SED=$dir/sed
  119.         fi
  120.     for awk in $all_awks ; do
  121.         if $TEST -z "$AWK" ; then
  122.             if $TEST -x $dir/$awk ; then
  123.                 AWK=$dir/$awk
  124.                 break
  125.                 fi
  126.             fi
  127.         done
  128.     if $TEST -f $dir/tr ; then
  129.         TR=$dir/tr
  130.         fi
  131.     done
  132.  
  133. if $TEST -z "$AWK" ; then
  134.     $ECHO "Cannot find awk; awk is needed to run this shell script"
  135.     exit 1
  136.     fi
  137.  
  138. if $TEST -z "$SED" ; then
  139.     $ECHO "Cannot find sed; sed is needed to run this shell script"
  140.     exit 1
  141.     fi
  142.  
  143. if $TEST -z "$TR" ; then
  144.     $ECHO "Cannot find tr; tr is needed to run this shell script"
  145.     exit 1
  146.     fi
  147.  
  148. # zero out the file, then put in the real locations...
  149. $ECHO > $location
  150.  
  151. $ECHO So far so good...
  152. $ECHO Looking for all the commands now...
  153.  
  154. for command in $all_commands ; do
  155.     found=false
  156.     for dir in $all_dirs ; do
  157.         # if find the command in one of the directories, print string
  158.         if $TEST -f $dir/$command ; then
  159.             # this converts to upper case
  160.             upper=`$ECHO $command | $TR '[a-z]' '[A-Z]'`
  161.         $ECHO "s-^$upper=.*\$-$upper=$dir/$command-" >> $location
  162.             found=true
  163.             break
  164.             fi
  165.         done
  166.     if $TEST "$found" = "false" ; then
  167.         if $TEST $command = "strings" ; then
  168.             $ECHO Warning!  $command not found!  chk_strings will not work as planned.
  169.         elif $TEST $command = tftp ; then
  170.             $ECHO Warning!  $command not found!  misc.chk will not work as planned.
  171.         elif $TEST $command = uudecode ; then
  172.             $ECHO Warning!  $command not found!  misc.chk will not work as planned.
  173.         elif $TEST $command = ypcat ; then
  174.             :
  175.         elif $TEST $command = nroff ; then
  176.             $ECHO Warning!  $command not found!  docs cannot be formatted.
  177.         else
  178.             $ECHO ERROR!  $command not found!  Change or delete command!
  179.             exit
  180.             fi
  181.         fi
  182.     done
  183.  
  184. $ECHO "s-^AWK=.*\$-AWK=$AWK-" >> $location
  185. $ECHO "s-^ECHO=.*\$-ECHO=$ECHO-" >> $location
  186. $ECHO "s-^TEST=.*\$-TEST=$TEST-" >> $location
  187.  
  188. # almost forgot -- we need chmod & mv to make this reconfig work, too:
  189. for dir in $all_dirs
  190.     do
  191.     if $TEST -f $dir/mv ; then
  192.         MV=$dir/mv
  193.         fi
  194.     if $TEST -f $dir/chmod ; then
  195.         CHMOD=$dir/chmod
  196.         fi
  197.     done
  198.  
  199. $ECHO Ok, now doing substitutions on the shell scripts...
  200. for i in $shell_scripts
  201.     do
  202.     $ECHO "Changing paths in $i..."
  203.     $SED -f $location $i > $i.new
  204.     $MV $i $i.old
  205.     $MV $i.new $i
  206.     # finally, make sure everything is back to executable status
  207.     $CHMOD u+x $i
  208.  
  209. done
  210.