-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.sh
executable file
·87 lines (83 loc) · 2.51 KB
/
cleanup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
now=`date +'%s'`
nowtd="$HOME/`date +'%Y/%m/%d'`"
logto=.cleanuplog
DIRS="$HOME $HOME/Desktop $HOME/dwhelper"
shopt -s extglob
IGNORE='*@(bin|lib|man|share|include|borg|backup|mprime5|.DCOP*|.dbus|.config|.gtkrc-1.2-gnome2|.local|.openoffice.org*|.recently-used|.Trash|.xsession-errors*|.desktop|.directory|Music|unison.log|.git|.procmail.log|.Xauthority|.ICEauthority|.spamassassin|.gnome2_private|.gconfd|.fonts.conf|.gksu.lock|.gtk_qt_engine_rc|.gtkrc*|.mcop*|.nautilus|.texmf-var|porn|etch|gentoo|ubuntu|baal|muumuu)'
DELETE='*@(.fontconfig|.dvdcss|.evolution|.adobe|.macromedia|.thumbnails|.gnome|.icons|.metacity|.themes|.update-notifier)'
commit=$1
function maybe() {
echo "$@" >>$logto
if [ "$commit" != softly ] ; then
echo "$@"
fi
if [ "$commit" = commit ] || [ "$commit" = softly ] ; then
"$@"
fi
}
function debug() {
# echo "$@" >>$logto
if [ "$commit" = debug ] ; then
echo "$@"
fi
}
for d in $DIRS ; do
if [ -d $d ]; then
cd $d
else
continue
fi
for f in * .* ; do
if git-ls-files --error-unmatch $f &>/dev/null ; then
debug git $f
continue 1
fi
if [ -d "$f" ] ; then
for di in $DIRS ; do
case "$d/$f" in
"$d/.."|"$d/."|"$di")
debug subdir $f
continue 2
;;
esac
done
fi
if [ -d "$f/.svn" ] ; then
debug svn $f
continue 1
fi
case $d/$f in
$IGNORE)
debug ignore $f
continue 1
;;
$DELETE)
debug delete $f
maybe rm -rvf $f
continue 1
;;
*/[0-9][0-9][0-9][0-9])
debug dated $f
continue 1
;;
esac
modified=`stat -c %Z "$f"`
if (($now - $modified > 30 * 86400)); then
td="$HOME/`date \"--date=\`stat \"$f\" -c %z\`\" +'%Y/%m/%d'`"
dest="$td/`basename \"$f\"`"
debug "$dest"
[ -d $td ] || maybe mkdir -p $td
maybe mv -v "$f" "$dest"
elif (($now - $modified > 7 * 86400)); then
debug aging $f
echo "${f} aging" $(( 30 - ($now - $modified) / 86400 )) days left
else
debug toonew $f
fi
done
done
if [ -f $logto ] ; then
[ -d $nowtd ] || mkdir -p $nowtd
mv $logto $nowtd/$logto
fi