1#!/bin/sh
2#
3# $FreeBSD: src/etc/periodic/daily/110.clean-tmps,v 1.13 2004/02/28 04:58:40 ache Exp $
4#
5# Perform temporary directory cleaning so that long-lived systems
6# don't end up with excessively old files there.
7#
8
9# If there is a global system configuration file, suck it in.
10#
11if [ -r /etc/defaults/periodic.conf ]
12then
13    . /etc/defaults/periodic.conf
14    source_periodic_confs
15fi
16
17case "$daily_clean_tmps_enable" in
18    [Yy][Ee][Ss])
19	if [ -z "$daily_clean_tmps_days" ]
20	then
21	    echo '$daily_clean_tmps_enable is set but' \
22		'$daily_clean_tmps_days is not'
23	    rc=2
24	else
25	    echo ""
26	    echo "Removing old temporary files:"
27
28	    set -f noglob
29	    args="-atime +$daily_clean_tmps_days -mtime +$daily_clean_tmps_days"
30	    args="${args} -ctime +$daily_clean_tmps_days"
31	    dargs="-empty -mtime +$daily_clean_tmps_days"
32	    dargs="${dargs} ! -name .vfs_rsrc_streams_*"
33	    [ -n "$daily_clean_tmps_ignore" ] && {
34		args="$args "`echo " ${daily_clean_tmps_ignore% }" |
35		    sed 's/[ 	][ 	]*/ ! -name /g'`
36		dargs="$dargs "`echo " ${daily_clean_tmps_ignore% }" |
37		    sed 's/[ 	][ 	]*/ ! -name /g'`
38	    }
39	    case "$daily_clean_tmps_verbose" in
40		[Yy][Ee][Ss])
41		    print=-print;;
42		*)
43		    print=;;
44	    esac
45
46	    rc=$(for dir in $daily_clean_tmps_dirs
47		do
48		    [ ."${dir#/}" != ."$dir" -a -d $dir ] && cd $dir && {
49			find -dx . -fstype local -type f $args -delete $print
50			find -dx . -fstype local ! -name . -type d $dargs -delete $print
51		    } | sed "s,^\\.,  $dir,"
52		done | tee /dev/stderr | wc -l)
53	    [ -z "$print" ] && rc=0
54	    [ $rc -gt 1 ] && rc=1
55	    set -f glob
56	fi;;
57
58    *)  rc=0;;
59esac
60
61exit $rc
62