:
#	@(#) cleanlck.sh 23.3 91/09/28 
#
#	Copyright (C) 1990-1991 The Santa Cruz Operation, Inc.
#		All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#
# Clean up lockfiles
#

echo "Cleaning mail locks...\c"

TAILOR=/usr/mmdf/mmdftailor
PASSWD=/etc/passwd

#
# Get some info out of the tailor file: MDLVRDIR, MMBXNAME, MLCKTYPE,
# MTBLDIR, MQUEDIR
#

eval `nawk '
$1 ~ /^[Mm][Dd][Ll][Vv][Rr][Dd][Ii][Rr]$/ {
	gsub("\"", "", $2)
	printf("MDLVRDIR=\"%s\"\n", $2)
}
$1 ~ /^[Mm][Mm][Bb][Xx][Nn][Aa][Mm][Ee]$/ {
	gsub("\"", "", $2)
	printf("MMBXNAME=\"%s\"\n", $2)
}
$1 ~ /^[Mm][Ll][Cc][Kk][Tt][Yy][Pp][Ee]$/ {
	gsub("\"", "", $0)
	printf("MLCKTYPE=\"%s\"\n", $0)
}
$1 ~ /^[Mm][Tt][Bb][Ll][Dd][Ii][Rr]$/ {
	gsub("\"", "", $2)
	printf("MTBLDIR=\"%s\"\n", $2)
}
$1 ~ /^[Mm][Qq][Uu][Ee][Dd][Ii][Rr]$/ {
	gsub("\"", "", $2)
	printf("MLCKTYPE=\"%s\"\n", $2)
}' $TAILOR`

MDLVRDIR=${MDLVRDIR:-/usr/spool/mail}
MLCKTYPE=${MLCKTYPE:-"advisory xenix v7"}
MTBLDIR=${MTBLDIR:-/usr/mmdf/table}
MQUEDIR=${MQUEDIR:-/usr/spool/mmdf/lock/home}

#
# Remove XENIX-style locks in /tmp
#

case "$MLCKTYPE" in
*[Xx][Ee][Nn][Ii][Xx]*)
	echo "XENIX-style locks...\c"
	rm -f /tmp/*.mlk
	;;
esac

#
# Remove v7 style locks wherever
#

case "$MLCKTYPE" in
*[Vv]7*)
echo "V7-style locks...\c"

#
# Remove mailbox locks
#

awk -F: '{ print $1, $6 }' $PASSWD |
while read user home ; do
	dir=${MDLVRDIR:-$home}
	if [ "$dir" = "/" ] ; then
		dir=			# Prevents "//mbox.lck" for Micnet
	fi
	mbox=${MMBXNAME:-$user}
	lock=${mbox}.lck
	choplock=`expr "$lock" : '^\(..............\).*'`
	chopmbox=`expr "$mbox" : '^\(..............\).*'`

	if [ "$choplock" != "${chopmbox:-$mbox}" ] ; then
		rm -f $dir/$lock
		if [ -n "$choplock" ] ; then
			rm -f $dir/$choplock
		fi
	fi
done

#
# Remove system locks
#

rm -f $MTBLDIR/mmdfdbm.lck.lck $MTBLDIR/mmdfdbm.lck.lc
( cd $MQUEDIR ; rm -f */msg.*.l* )
	
;;
esac

echo "done."

exit
