#!/bin/sh -

maildirs='/var		/usr	      /var/spool	  /usr/spool'
#	  /nfs/mail/var /nfs/mail/usr /nfs/mail/var/spool /nfs/mail/usr/spool'

# dailyl - routine host check
# Steve Kinzler, steve@kinzler.com, Jan 94/Oct 08
# https://kinzler.com/me/home.html#homedir

case "$1,$#" in
,0|[0-9]*,1)	inode="$1";;
*)		echo "usage: $0 [ inode ]" 1>&2; exit 1;;
esac

host=${HOST-${HOSTNAME-`(hostname) 2> /dev/null`}}
case "$host" in
'')	host=`uname -n`;;
esac
case "$host" in
'')	echo "$0: cannot determine hostname" 1>&2; exit 2;;
esac
host=`echo "$host" | sed 's/\..*//'`

case "$host" in
hm-sas-meta)		host=transi2;;
hmrc-web)		host=$CH;;
HMRC-SECURITYONION1)	host=seconion1;;
vkinzler)		host=kinzler;;	# .homeunix.com
esac

set `hosts -l | grep -i "^[ 	]*$host[.	]" | sed 1q |
	awk '{ print $(NF - 1), $NF }'` '' ''
archit=`archit`
case "$archit" in
"$1")	;;
*)	echo "archit ($archit) != hosts ($1)";;
esac
opsys=`opsys`
case "$opsys" in
"$2")	;;
*)	echo "opsys ($opsys) != hosts ($2)";;
esac

#perl=/usr/local/bin/perl
perl=/usr/bin/perl
test -f "$perl" || echo "No $perl file"

# Note that there should always be a mail spool file, even if empty,
# in order to avoid some systems' security holes (eg, sunos4).

USER=${USER-$LOGNAME}
for dir in $maildirs
do
	(chmod 600 "$dir/mail/$USER" >> "$dir/mail/$USER") 2> /dev/null
done

#case "$MAILHOST,$MAILHOST2,$MAILHOST3" in
case "$MAILHOST" in
"$host".*|*,"$host".*)	chmod 600 "${MAIL-/var/spool/mail/$USER}";;
*)			for dir in $maildirs
			do
			#	fwd="$HOME"/.forward
			#	test -e "$fwd" -a ! -s "$fwd"	&& continue
				mbox="$dir/mail/$USER"
				test -s "$mbox"			|| continue
				i=`ls -i "$mbox" | awk '{ print $1 }'`
				test -z "$inode" && inode=-1
				test "$inode" -ne "$i"		|| continue
				ls -dl "$mbox"
			done
			(imapcheck) 2> /dev/null;;
esac

if test -d /win?/[Ww]ork
then
	ls -al /win?/[Ww]ork | sed '/^total /d; / \.$/d; / \.\.$/d; /^$/d
				    s/:[0-9][0-9] /&\/win\?\/\[Ww\]ork\//'
fi
