#!/bin/sh
# ck_prc	Written by Jerry Rains 11/26/00
# 		This is a wrapper for Bob Stockler's ck.prc.
#		It runs ck.prc on all filepro files.
#               Modified to work on Linux 01/17/01.  This consisted of:
#               Adding 2>&1 to type commands.
#               Changed back to ls -xd for listing files.
#               Changed [ -f ./$j/prc.* ] to ls $j/prc.* > $tmpdir/tst
#               [ -s $tmpdir/tst ] && { - to get around "too many arguments".

# Determine form of echo to use.
if [ `echo "x\c"` = "x" ]
then
    # Then the standard command will work just fine.
    ECHO="echo"
else
    # Otherwise we need to enable the 'backslash' processing.
    ECHO="echo -e"
fi
export ECHO

usrid=`id -un`
owner=`ls -ld $PFDATA$PFDIR | awk '{print $3}'`
[ "$owner" != "filepro" -a "$usrid" != "root" ] && {
    $ECHO "\n		ck_prc requires $PFDATA$PFDIR to be owned by filepro."
    $ECHO "\n			    Press Enter to continue. \c"
    read key
    exit
    }
[ "$instdir" ] || instdir=/usr/bin
[ $tmpdir ] || tmpdir=/tmp
[ "$1" = "-q" ] && quiet=yes
hash -r
cd /
is_less=`type less 2>&1 | sed -e "s,less is ,,"`
tis_less=`echo $is_less | grep '/'`
if [ -n "$tis_less" ]
then
    pager=`basename $is_less`
elif [ "$PAGER" ]
then
    pager=$PAGER
else
    pager=more
fi
cd $PFDATA$PFDIR
[ "$quiet" = "yes" ] && {
    echo "ASCII" > ASCII_ENCODED
    > ENCODED
    chmod 666 ASCII_ENCODED ENCODED
    }
cd filepro
until [ -d "$file" -o "$file" = "all" ]
do
    if [ "$quiet" ]
    then
        file=all
    else
        ls -xd $file* 2>/dev/null
        $ECHO
        $ECHO "Check Encrypted status of which file? (all) \c"
        read file
        $ECHO
    fi
done
[ "$file" = "all" ] && file=""
if [ "$file" ]
then
    $ECHO
    [ "$quiet" ] && $instdir/ck.prc $file -q || $instdir/ck.prc $file
    $ECHO
    $ECHO "Press Enter to continue. \c"
    read key
else
    if [ "$quiet" ] 
    then
        $ECHO
        $ECHO "Checking for ENCODED prc.'s.  ... Please Wait ... \c"
    else
        $ECHO
        $ECHO "Generating output.  ... Please Wait ... \c"
    fi
    for j in `echo $file*`
    do
        ls $j/prc.* 2>/dev/null > $tmpdir/tst
        [ -s $tmpdir/tst ] && {
            $ECHO
            $ECHO
            $ECHO $PFDIR/filepro/$j
            [ "$quiet" ] && $instdir/ck.prc $j -q || $instdir/ck.prc $j
        }
    done > $tmpdir/ckprc.log
    if [ "$quiet" ]
    then
        :
    else
        clear
        $instdir/viewprt $tmpdir/ckprc.log
    fi
fi
chmod 666 $PFDATA$PFDIR/ASCII_ENCODED $PFDATA$PFDIR/ENCODED
err=$?
[ $err = 0 ] || {
    $ECHO "Press Enter to continue: \c"
    read key
    exit $err
    }
