home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / policy / part01 / scripts / policy.sh < prev   
Encoding:
Linux/UNIX/POSIX Shell Script  |  1992-02-28  |  4.1 KB  |  126 lines

  1. :
  2. #!/bin/sh
  3. # $Id: policy.sh,v 5.3.2.5 91/09/03 09:56:03 policy USENET $
  4. #
  5. # Copyright (c) 1989, 1990, 1991 by Bergen B. Hovell, Jr.
  6. # You may not distribute or otherwise use this work for any profit-making
  7. # purpose without the express permission of the author, but this work is
  8. # otherwise freely distributable so long as this header remains attached.
  9. #############################################################################
  10. # Revision 4.6.2.2  91/04/04  12:30:18  bbh
  11. # Use variable substitution for differences in BSD vs. SYSV 'sh' commands.
  12. # By Andy Linton <Andy.Linton@comp.vuw.ac.nz>.
  13. #################### edit these in the Makefile! ############################
  14. PATH=
  15. poldir=
  16. pager=
  17. myname=
  18. is3b1=
  19. #############################################################################
  20. # Note: any policy file must be named identically to the first word of the
  21. #     first line in the file itself. Consider the file "logins", with
  22. #    this as line one:
  23. #  
  24. #    logins  - responsibilities of users
  25. #
  26. #    .....where the word "logins" begins at character one of line
  27. #       one of the file named "logins". This first line will then be
  28. #       extracted to the ad-hoc menu file to provide the menu item for
  29. #       the user to select the "logins" policy file.
  30. #
  31. #    Optionally, you may show an RCS header or id as the last item
  32. #    on line 1, and it will be stripped away so as not to show up on
  33. #    the menu listing. It will, however, show up when the file is
  34. #    paged up onto the screen, so the user can see what the last date
  35. #    of change (or perhaps just the Revision number) exists for that
  36. #    policy file. This is a recommended approach, if you have RCS to
  37. #    maintain these files. (SCCS could be used similarly, which would
  38. #    necessitate only minor changes in the sed statement below).
  39. ############################################################################
  40. export PATH
  41.  
  42. # Some variables:
  43. host=`$myname | tr [a-z] [A-Z]`       
  44. menu=$poldir/polmenu
  45.  
  46. # Are we a 3B1?:
  47. if [ "$is3b1" = "yes" ]
  48. then c='\c'
  49.      nl='\n'
  50.      n=
  51. else # Andy's sort for bsd vs. sysv:
  52.      nl=`echo \\\\n`
  53.      if [ ${nl} ]
  54.      then nl='
  55. '
  56.      else nl='\n'
  57.      fi
  58.      c=`echo \\\\c`
  59.      if [ ${c} ]
  60.      then n='-n'
  61.           c=
  62.      else c='\c'
  63.      fi
  64. fi
  65.  
  66. # Do we have a "clear" function?
  67. if [ -x /bin/clear -o -x /usr/bin/clear -o -x /usr/ucb/clear ]
  68. then clear=`clear`
  69. # ....or curses?
  70. elif  [ -x /usr/bin/tput ]
  71. then clear=`tput clear`
  72. else clear=
  73. fi
  74.     
  75. # Any files newer than menu?
  76. cd $poldir 
  77. new=`find . -newer $menu -print`
  78.  
  79. # If so, menu needs to be updated:
  80. if [ "$new" ]
  81. then echo "${nl}Ooops...hold on while I build a new menu for '$0'...${nl}" 
  82.      > $menu
  83.      filelist=`ls | sed -e 's/polmenu//g' \
  84.              -e 's/^[     ]$//g' \
  85.                         -e 's/$//g'; echo "${nl}"`
  86.      for file in $filelist
  87.      do
  88.           echo ${n} "               ${c}"                          >> $menu
  89.           # This will read out all of line 1 into the user menu,
  90.           # except for any trailing Id or Header stuff for RCS
  91.           # (if you show your revision info on line one):
  92.           cat $file | sed -n '1p' | sed 's/[$].*$//g'              >> $menu
  93.      done
  94. fi
  95.     
  96. # Re-run the menu until 'quit' from user:
  97. i=x
  98. until [ $i = "q|Q|quit|Quit" ]; do
  99.      echo $clear
  100.      echo "${nl}               DIRECTORY OF LOCAL POLICY FOR HOST '$host'${nl}"
  101.      cat $menu
  102.      echo "${nl}               .....or 'q'uit"
  103.      echo ${n} "${nl}               To review a policy, type in subject: > ${c}"
  104.      read i
  105.      case $i in
  106.            q|Q|quit|Quit) # Wants to quit
  107.                 echo "${nl}               Policy review concluded.  Thanks for your interest.${nl}"
  108.                 break ;;
  109.            "")  # No entry
  110.                 i=x
  111.                 echo "${nl}               You must provide a name or 'q'uit.\007"
  112.                 sleep 2
  113.                 continue ;;
  114.            *)   # Wants another
  115.                 if [ -r $poldir/$i ]
  116.                 then echo $clear
  117.              $pager $poldir/$i
  118.                      i=x
  119.                 else echo "${nl}               You must provide a name or 'q'uit.\007"
  120.                      sleep 2
  121.                      i=x
  122.                 fi
  123.                 continue ;;
  124.      esac
  125. done
  126.