#!/bin/sh
# Remove stale files
# Remote filesystems are mounted now
#
# TODO: /var/service or whatever
# Cleaning shouldn't be done at boot:
# servers can stay up for years, need more frequent cleaning ;)
#
. /boot.conf
test "$LOG_START" && echo "<*> Executing '$0 $*'"

if test "$RMFILES$RMRFILES"; then
    test "$LOG_STAGE" && echo "* Removing stale locks and temporary files"
    if test "$RMFILES"; then
	for n in $RMFILES; do
	    #echo -n "  DEBUG: $n"
	    rm -f "$n" 1>/dev/null 2>&1
	done
    fi
    if test "$RMRFILES"; then
	for n in $RMRFILES; do
	    #echo -n "  DEBUG: $n"
	    rm -rf "$n" 1>/dev/null 2>&1
	done
    fi
fi

test "$LOG_STAGE" && echo "* Recreating temporary storage"
if test "$MKDIRS"; then
    for n in $MKDIRS; do
	#echo -n "  DEBUG: $n"
	mkdir -p "$n" 1>/dev/null 2>&1
    done
fi
>/var/run/utmp
>>/var/log/wtmp

exit 0
