#! /sbin/sh
#Tag 0x00000f00

# Clean up temporary files.
# "$Revision: 1.25 $"

set `who -r`
if test $9 != "S"; then
	exit 1
fi

# If no reasonable /tmp exists (!?!?!) create one.
if test ! -d /tmp -a ! -l /tmp; then
	rm -f /tmp
	mkdir /tmp
fi

# Preserve any editor scratch files.  If we moved /tmp to /.oldtmp earlier
# on, scratch files may be in /.oldtmp.  To be really thorough, run through
# both /tmp and any /.oldtmp.

# Note that if we moved /tmp to /.oldtmp earlier on, it means we are both
# allowed and expected to delete the entire old /tmp contents.  Since this
# is true, we can delete /.oldtmp when we are done with it.

if test -x /usr/lib/expreserve; then
	if test -d /.oldtmp; then
		/usr/lib/expreserve -d /.oldtmp
		rm -rf /.oldtmp
	fi
	/usr/lib/expreserve -d /tmp
fi

# make /var/tmp exist
if test ! -d /var/tmp -a ! -l /var/tmp; then
	rm -f /var/tmp
	mkdir /var/tmp
fi
if ls -ld /usr/tmp 2>/dev/null | grep "^d" > /dev/null 2>&1 ; then
	rm -rf /usr/TMPOLD > /dev/null 2>&1
	mv /usr/tmp /usr/TMPOLD > /dev/null 2>&1
	rm -rf /usr/tmp > /dev/null 2>&1
	ln -s ../var/tmp /usr/tmp
fi

if chkconfig nostickytmp; then 
	chmod 777 /tmp /var/tmp
else
	chmod 1777 /tmp /var/tmp
fi
chown sys.sys /tmp /var/tmp

# clean directories from /usr/tmp_rex or make sure it doesn't exist.
#	Do not delete it recursively in case rexd is already running.
# XXX This should be removed along with rexd.
# XXX This is too late, since inetd is already running, which means
# XXX	rexd might already be using its directory.
if test -d /var/tmp_rex; then
	rmdir /var/tmp_rex/* 2> /dev/null
else
	rm -f /var/tmp_rex
	mkdir /var/tmp_rex
fi
# Don't make the symlink if the rm fails.  In order to do this, we
# need to remove the -f flag to rm; otherwise, it won't exit with a
# non-zero value when rm fails.  If /usr/tmp_rex is already a symlink,
# we may just be making a symlink the thing it already points at.
# On diskless systems, /usr is mounted read-only.  Therefore, the rm
# of /usr/tmp_rex will fail.  Checking to see if /usr/tmp_rex is the
# correct symlink requires using something like awk which isn't in
# /sbin.  This is a good comprimise.
if test -d /usr/tmp_rex; then
	rm -r /usr/tmp_rex 2> /dev/null
	if [ $? = 0 ]; then
		ln -s ../var/tmp_rex /usr/tmp_rex 2> /dev/null
	fi
fi
chmod 775 /var/tmp_rex
chown sys.sys /var/tmp_rex

# prime the ps command data file, /tmp/.ps_data
nice ps -e < /dev/null > /dev/null 2>&1 &
