:
#!/bin/sh
# $Id: policy.sh,v 5.3.2.5 91/09/03 09:56:03 policy USENET $
#
# Copyright (c) 1989, 1990, 1991 by Bergen B. Hovell, Jr.
# You may not distribute or otherwise use this work for any profit-making
# purpose without the express permission of the author, but this work is
# otherwise freely distributable so long as this header remains attached.
#############################################################################
# Revision 4.6.2.2  91/04/04  12:30:18  bbh
# Use variable substitution for differences in BSD vs. SYSV 'sh' commands.
# By Andy Linton <Andy.Linton@comp.vuw.ac.nz>.
#################### edit these in the Makefile! ############################
PATH=
poldir=
pager=
myname=
is3b1=
#############################################################################
# Note: any policy file must be named identically to the first word of the
# 	first line in the file itself. Consider the file "logins", with
#	this as line one:
#  
#	logins  - responsibilities of users
#
#	.....where the word "logins" begins at character one of line
#       one of the file named "logins". This first line will then be
#       extracted to the ad-hoc menu file to provide the menu item for
#       the user to select the "logins" policy file.
#
#	Optionally, you may show an RCS header or id as the last item
#	on line 1, and it will be stripped away so as not to show up on
#	the menu listing. It will, however, show up when the file is
#	paged up onto the screen, so the user can see what the last date
#	of change (or perhaps just the Revision number) exists for that
#	policy file. This is a recommended approach, if you have RCS to
#	maintain these files. (SCCS could be used similarly, which would
#	necessitate only minor changes in the sed statement below).
############################################################################
export PATH

# Some variables:
host=`$myname | tr [a-z] [A-Z]`       
menu=$poldir/polmenu

# Are we a 3B1?:
if [ "$is3b1" = "yes" ]
then c='\c'
     nl='\n'
     n=
else # Andy's sort for bsd vs. sysv:
     nl=`echo \\\\n`
     if [ ${nl} ]
     then nl='
'
     else nl='\n'
     fi
     c=`echo \\\\c`
     if [ ${c} ]
     then n='-n'
          c=
     else c='\c'
     fi
fi

# Do we have a "clear" function?
if [ -x /bin/clear -o -x /usr/bin/clear -o -x /usr/ucb/clear ]
then clear=`clear`
# ....or curses?
elif  [ -x /usr/bin/tput ]
then clear=`tput clear`
else clear=
fi
    
# Any files newer than menu?
cd $poldir 
new=`find . -newer $menu -print`

# If so, menu needs to be updated:
if [ "$new" ]
then echo "${nl}Ooops...hold on while I build a new menu for '$0'...${nl}" 
     > $menu
     filelist=`ls | sed -e 's/polmenu//g' \
 			-e 's/^[ 	]$//g' \
                        -e 's/$//g'; echo "${nl}"`
     for file in $filelist
     do
          echo ${n} "               ${c}"                          >> $menu
          # This will read out all of line 1 into the user menu,
          # except for any trailing Id or Header stuff for RCS
    	  # (if you show your revision info on line one):
          cat $file | sed -n '1p' | sed 's/[$].*$//g'              >> $menu
     done
fi
    
# Re-run the menu until 'quit' from user:
i=x
until [ $i = "q|Q|quit|Quit" ]; do
     echo $clear
     echo "${nl}               DIRECTORY OF LOCAL POLICY FOR HOST '$host'${nl}"
     cat $menu
     echo "${nl}               .....or 'q'uit"
     echo ${n} "${nl}               To review a policy, type in subject: > ${c}"
     read i
     case $i in
           q|Q|quit|Quit) # Wants to quit
                echo "${nl}               Policy review concluded.  Thanks for your interest.${nl}"
                break ;;
           "")  # No entry
                i=x
                echo "${nl}               You must provide a name or 'q'uit.\007"
                sleep 2
                continue ;;
           *)   # Wants another
                if [ -r $poldir/$i ]
                then echo $clear
		     $pager $poldir/$i
    	             i=x
                else echo "${nl}               You must provide a name or 'q'uit.\007"
    	             sleep 2
    	             i=x
                fi
                continue ;;
     esac
done
