host info updates
[distro-setup] / mailclean
1 #!/bin/bash
2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
7 # its license to GPL.
8
9 # Copyright 2024 Ian Kelling
10
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14
15 # http://www.apache.org/licenses/LICENSE-2.0
16
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22
23
24 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
25 source /a/bin/bash-bear-trap/bash-bear
26
27 source /a/bin/bash_unpublished/source-state
28 if [[ $HOSTNAME != "$MAIL_HOST" ]]; then
29 exit 0
30 fi
31
32
33 # find but ignore directories which dont exist, assuming first args are directories
34 # and a following arg starts with -
35 myfind() {
36 dirs=()
37 for d; do
38 if [[ $d == -* ]]; then
39 # past dirs, onto options
40 break
41 fi
42 shift
43 if [[ -e $d ]]; then
44 dirs+=($d)
45 fi
46 done
47 if (( ${#dirs[*]} )); then
48 find ${dirs[@]} $@
49 fi
50 }
51
52 # qemu-devel is our biggest list by far, so occasionally
53 # I want to hop into conversations about our mailing
54 # systems there, but I don't need many old messages.
55 myfind /m/md/l/qemu-devel/new -type f -mtime +14 -execdir rm -- '{}' +
56 myfind /m/md/l/listhelper-moderatre/new -type f -mtime +14 -execdir rm -- '{}' +
57 myfind /m/md/{sec,Spam,Drafts,{rtcc,sysadmin}/new} -type f -mtime +100 -execdir rm -- '{}' +
58 myfind /m/md/log -type f -mtime +300 -execdir rm -- '{}' +
59 myfind /m/md/dmarc -type f -mtime +60 -execdir rm -- '{}' +
60 myfind /m/md/fsfalerts -type f -mtime +10 -execdir rm -- '{}' +
61
62 # not strictly a mail directory, but it fits well in this script
63 myfind /p/c/.editor-backups -type f -mtime +300 -execdir rm -- '{}' +
64
65
66
67 shopt -s nullglob
68 shopt -s extglob
69
70
71 archive() {
72 days=$1
73 shift
74 for d; do
75 [[ -d $d ]] || continue
76 leafdir=${d##*/} # cur/new
77 archivebase=${d%/*}-myarchive
78 archive=$archivebase/$leafdir
79 mkdir -p ${archivebase}/{cur,tmp,new}
80 find $d -type f -mtime +$days -name '1*' -exec mv '{}' $archive \;
81 # count=$(find $d -type f -mtime +$days -name '1*' | wc -l)
82 # if (( count )); then
83 # echo $d $count
84 # fi
85 done
86 }
87
88 cd /m/md
89 archive 800 ./!(*archive|board|Drafts|Sent|INBOX)/*(cur|new) ./l/!(*archive)/*(cur|new)
90 archive 60 ./{sysadmin,rtcc,fsfcc,fsfmembers}/{cur,new}
91 archive 30 ./Junk/{cur,new}
92
93 # This is a generally useless file which will grow to 1gb and eat up memory.
94 # https://doc.dovecot.org/admin_manual/known_issues/large_cache/
95 # I could probably disable the cache for this folder, but that would
96 # also mean I'm testing less of the full functionality.
97 rm -f /m/md/l/testignore/dovecot.index.cache