#! /bin/sh
#
# @(#)rmfilecheck	1.3   LPS_UNX_COM     02/19/95
#
# Copyright 1994   Digital Equipment Corporation, Maynard, MA
#
# rmfilecheck filepath
#
# Return a boolean indication whether the specified path represents
# a file that is "safe" to remove.  Intended to be used to safely
# remove log and accounting files associated with an LPS object.
#
# Parameters:
#    $1 - Path of file to check
#
# Global variables:
#    LPSDEBUG
#
# Exit values:
#    0 - Yes, the file appears to be a "regular" file and may be removed,
#        or the file does not exist
#    1 - No, the file does NOT appear to be a regular file, so it had
#        better not be removed.
#    2 - Invalid command line specified.
###

FILE=$1
type=UNKNOWN

candelete=false

if [ $# -ne 1 ]
then
    echo "usage:  $0 filepath"
    exit 2
fi

# Test for a "regular file" LAST due to System V compatibility requirements

if [ -d $FILE ]
then
    type=directory
elif [ -c $FILE ]
then
    type="character special file"
elif [ -b $FILE ]
then
    type="block special file"
#
# The following commented-out tests aren't available on all systems,
# such as OSF/1 1.3 and AIX 3.2.
#
#elif [ -h $FILE ]
#then
#    type="symbolic link"
#elif [ -p $FILE ]
#then
#    type="named pipe file"
#
elif [ -f $FILE ]
then
    type="normal file"
    candelete=true
else
    if cat $FILE > /dev/null 2>&1
    then
	:
    else
	# File doesn't appear to exist, so return an "OK" condition

	exit 0
    fi
fi

if $candelete
then
    if [ "$LPSDEBUG" ]
    then
	echo "    [$FILE is a \"$type\" ... OK to delete the file]"
    fi
    rc=0
else
    if [ "$LPSDEBUG" ]
    then
	echo "    [$FILE is a \"$type\" ... NOT WISE to delete the file]"
    fi
    rc=1
fi

exit $rc
