import-list: Recreate exim mailmandb if domain changed.
[clinton/scripts.git] / hcoop-clean-tmp
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
12 umask 022
13
14 . /lib/init/vars.sh
15 . /lib/lsb/init-functions
16
17 cd /tmp || { log_failure_msg "bootclean: Could not cd to /tmp." ; return 1 ; }
18
19 [ "$(find . -maxdepth 0 -perm -002)" = "." ] || return 0
20
21 if [ ! "$TMPTIME" ]
22 then
23 log_warning_msg "Using default TMPTIME 0."
24 TMPTIME=0
25 fi
26
27 [ "$VERBOSE" = no ] || log_action_begin_msg "Cleaning /tmp"
28
29 rm -f .X*-lock
30
31 #
32 # Don't clean remaining files if TMPTIME is negative or 'infinite'
33 #
34 case "$TMPTIME" in
35 -*|infinite|infinity)
36 [ "$VERBOSE" = no ] || log_action_end_msg 0 "skipped"
37 return 0
38 ;;
39 esac
40
41 if [ "$TMPTIME" = 0 ]
42 then
43 TEXPR=""
44 DEXPR=""
45 else
46 TEXPR="-mtime +$TMPTIME -ctime +$TMPTIME -atime +$TMPTIME"
47 DEXPR="-mtime +$TMPTIME -ctime +$TMPTIME"
48 fi
49
50 EXCEPT='! -name .
51 ! ( -path ./lost+found -uid 0 )
52 ! ( -path ./quota.user -uid 0 )
53 ! ( -path ./aquota.user -uid 0 )
54 ! ( -path ./quota.group -uid 0 )
55 ! ( -path ./aquota.group -uid 0 )
56 ! ( -path ./.journal -uid 0 )
57 ! ( -path ./.clean -uid 0 )
58 ! ( -path ./lost+found -uid 0 )
59 ! ( -path './...security*' -uid 0 )'
60
61 report_err()
62 {
63 if [ "$VERBOSE" = no ]
64 then
65 log_failure_msg "bootclean: Failure cleaning /tmp."
66 else
67 log_action_end_msg 1 "bootclean: Failure cleaning /tmp"
68 fi
69 }
70
71 #
72 # First remove all old files...
73 # (Use xargs here so that only one additional process gets created)
74 #
75 find . -depth -xdev $TEXPR $EXCEPT ! -type d \
76 -print0 | xargs -0r rm -f -- \
77 || { report_err ; return 1 ; }
78
79 #
80 # ...and then all empty directories
81 # (Don't use xargs here because dirs must be removed one by one from
82 # the bottom up)
83 #
84 find . -depth -xdev $DEXPR $EXCEPT -type d -empty \
85 -exec rmdir \{\} \; \
86 || { report_err ; return 1 ; }
87
88 [ "$VERBOSE" = no ] || log_action_end_msg 0
89
90 exit 0
91
92