# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.
#ident	"$Header: RMTMPFILES 1.6 90/08/26 $@(#)initpkg:init.d/RMTMPFILES	1.1.1.4"
#	Clean up temporary files.

set `who -r`
if [ $9 != "S" ]
then
	exit
fi

#  clean up /tmp 
#  if /tmp or any of its subdirectories are mount points do not remove /tmp
M=`mount | egrep '^/tmp(/| )' | wc -l`
ls=`ls -ld /tmp`
link=`expr "$ls" : '\(.\)'`
if [ $M -eq 0 -a "$link" != "l" ]
then
	rm -rf /tmp
	mkdir /tmp
else
	rm -rf /tmp/*
fi
	chmod 1777 /tmp
	chgrp sys /tmp
	chown sys /tmp

#  clean up /usr/tmp
if [ -d /usr/tmp  -o  -d /usr/bin ]
then	#	Conditional, so we won't make /usr/tmp if /usr file system
	#	did not mount successfully.  We check for /usr/bin in case
	#	/usr/tmp disappeared unexpectedly.
	# 	if /usr/tmp or any of its subdirectories
	# 	is a mount point do not remove it.
	M=`mount | egrep '^/usr/tmp(/| )' | wc -l`
	ls=`ls -ld /usr/tmp`
	link=`expr "$ls" : '\(.\)'`
	if [ $M -eq 0 -a "$link" != "l" ]
	then
		rm -rf /usr/tmp
		mkdir /usr/tmp
	else
		rm -rf /usr/tmp/*
	fi
		chmod 1777 /usr/tmp
		chgrp sys /usr/tmp
		chown sys /usr/tmp
fi
#  remove the ckpacct lock if it exists.
rm -f /usr/adm/cklock
