hcoop-git-maint: Improve detection of bad permissions.
[clinton/scripts.git] / hcoop-clean-tmp
CommitLineData
0fafd2af 1#!/bin/sh
2
3# Thu Mar 27 13:59:00 EDT 2008 docelic:
4#
5# Clean /tmp for files older than TMPTIME days. Basically the copy of
6# /etc/init/bootclean's clean_tmp().
7#
8# How much files are kept is controlled by existing variable TMPTIME in
9# /etc/default/rcS.
10#
11
12umask 022
13
14. /lib/init/vars.sh
15. /lib/lsb/init-functions
16
e6002cfa 17VERBOSE=no
18
0fafd2af 19cd /tmp || { log_failure_msg "bootclean: Could not cd to /tmp." ; return 1 ; }
20
21[ "$(find . -maxdepth 0 -perm -002)" = "." ] || return 0
22
23if [ ! "$TMPTIME" ]
24then
25 log_warning_msg "Using default TMPTIME 0."
26 TMPTIME=0
27fi
28
29[ "$VERBOSE" = no ] || log_action_begin_msg "Cleaning /tmp"
30
31rm -f .X*-lock
32
33#
34# Don't clean remaining files if TMPTIME is negative or 'infinite'
35#
36case "$TMPTIME" in
37 -*|infinite|infinity)
38 [ "$VERBOSE" = no ] || log_action_end_msg 0 "skipped"
39 return 0
40 ;;
41esac
42
43if [ "$TMPTIME" = 0 ]
44then
45 TEXPR=""
46 DEXPR=""
47else
48 TEXPR="-mtime +$TMPTIME -ctime +$TMPTIME -atime +$TMPTIME"
49 DEXPR="-mtime +$TMPTIME -ctime +$TMPTIME"
50fi
51
52EXCEPT='! -name .
53 ! ( -path ./lost+found -uid 0 )
54 ! ( -path ./quota.user -uid 0 )
55 ! ( -path ./aquota.user -uid 0 )
56 ! ( -path ./quota.group -uid 0 )
57 ! ( -path ./aquota.group -uid 0 )
58 ! ( -path ./.journal -uid 0 )
59 ! ( -path ./.clean -uid 0 )
60 ! ( -path ./lost+found -uid 0 )
61 ! ( -path './...security*' -uid 0 )'
62
63report_err()
64{
65 if [ "$VERBOSE" = no ]
66 then
67 log_failure_msg "bootclean: Failure cleaning /tmp."
68 else
69 log_action_end_msg 1 "bootclean: Failure cleaning /tmp"
70 fi
71}
72
73#
74# First remove all old files...
75# (Use xargs here so that only one additional process gets created)
76#
77find . -depth -xdev $TEXPR $EXCEPT ! -type d \
78 -print0 | xargs -0r rm -f -- \
79 || { report_err ; return 1 ; }
80
81#
82# ...and then all empty directories
83# (Don't use xargs here because dirs must be removed one by one from
84# the bottom up)
85#
86find . -depth -xdev $DEXPR $EXCEPT -type d -empty \
87 -exec rmdir \{\} \; \
88 || { report_err ; return 1 ; }
89
90[ "$VERBOSE" = no ] || log_action_end_msg 0
91
92exit 0
93
94