Set +x on create-user-database script
[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 VERBOSE=no
18
19 cd /tmp || { log_failure_msg "bootclean: Could not cd to /tmp." ; return 1 ; }
20
21 [ "$(find . -maxdepth 0 -perm -002)" = "." ] || return 0
22
23 if [ ! "$TMPTIME" ]
24 then
25 log_warning_msg "Using default TMPTIME 0."
26 TMPTIME=0
27 fi
28
29 [ "$VERBOSE" = no ] || log_action_begin_msg "Cleaning /tmp"
30
31 rm -f .X*-lock
32
33 #
34 # Don't clean remaining files if TMPTIME is negative or 'infinite'
35 #
36 case "$TMPTIME" in
37 -*|infinite|infinity)
38 [ "$VERBOSE" = no ] || log_action_end_msg 0 "skipped"
39 return 0
40 ;;
41 esac
42
43 if [ "$TMPTIME" = 0 ]
44 then
45 TEXPR=""
46 DEXPR=""
47 else
48 TEXPR="-mtime +$TMPTIME -ctime +$TMPTIME -atime +$TMPTIME"
49 DEXPR="-mtime +$TMPTIME -ctime +$TMPTIME"
50 fi
51
52 EXCEPT='! -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
63 report_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 #
77 find . -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 #
86 find . -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
92 exit 0
93
94