Debian Codegraph @

mail/archive_mail

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 #
3 # LinPac mail archivation tool
4 # (c) 1999 by Radek Burget OK2JBG
5 #
6 # This script archives messages older than specified number of days
7 # and deletes them
8 #
9 LIST_PATH="/var/ax25/ulistdscip-shell filesystem . . `/var/ax25/ulistd`."
10 MAIL_PATH="/var/ax25/mailscip-shell filesystem . . `/var/ax25/mail`."
11
12 ###########################################################################
13 # Print a list of messages ################################################
14 message_listscip-shell shell shell-project 0.0.0 message_list().()
15 {
16 awkscip-shell system . . awk. '
17 {
18 printf "%s ", $1
19 }
20 ' ${LIST_PATH}/$BBS_CALL
21 }
22
23 ###########################################################################
24 # List new messages #######################################################
25 list_newscip-shell shell shell-project 0.0.0 list_new().()
26 {
27 awkscip-shell system . . awk. -v "LIMIT=$1" '
28 {
29 if (LIMIT <= $1) print $0
30 }
31 ' ${LIST_PATH}/$BBS_CALL
32 }
33
34 ###########################################################################
35 # List old messages #######################################################
36 list_oldscip-shell shell shell-project 0.0.0 list_old().()
37 {
38 awkscip-shell system . . awk. -v "LIMIT=$1" '
39 {
40 if (LIMIT > $1) print $0
41 }
42 ' ${LIST_PATH}/$BBS_CALL
43 }
44
45 ###########################################################################
46 # Print a list of messages older than $1 and files exist
47 ###########################################################################
48 older_messagesscip-shell shell shell-project 0.0.0 older_messages().()
49 {
50 for NUM in `message_listscip-shell shell shell-project 0.0.0 message_list().`; do
51 if [scip-shell system . . `[`. $1 -gt $NUM ]; then
52 if [scip-shell system . . `[`. -e ${MAIL_PATH}/$BBS_CALL/$NUM ]; then
53 echoscip-shell system . . echo. $NUM
54 fi
55 else
56 exit 0
57 fi
58 done
59 }
60
61 ###########################################################################
62 # Print a date of this message ############################################
63 message_datescip-shell shell shell-project 0.0.0 message_date().()
64 {
65 awkscip-shell system . . awk. '
66 BEGIN {
67 FS = "[:/]"
68 }
69
70 /^R:/ {
71 if (FNR == 1) print $2
72 }
73 ' ${MAIL_PATH}/$BBS_CALL/$1
74 }
75
76 ###########################################################################
77 # Print the first message number where the date of the message ############
78 # is newer than specified number of days. #################################
79 first_messagescip-shell shell shell-project 0.0.0 first_message().()
80 {
81 # date of last message
82 LASTDATE="0"
83
84 # scan all messages
85 for NUM in `message_listscip-shell shell shell-project 0.0.0 message_list().`
86 do
87 if [scip-shell system . . `[`. -r ${MAIL_PATH}/${BBS_CALL}/$NUM ]; then
88 LASTDATE=`message_datescip-shell shell shell-project 0.0.0 message_date(). $NUM`
89 if [scip-shell system . . `[`. ! $MDATE -gt $LASTDATE ]; then
90 echoscip-shell system . . echo. $NUM
91 exit 0
92 fi
93 fi
94 done
95
96 # nothing has been found - return last+1
97 echoscip-shell system . . echo. $(($NUM+1))
98 exit 0
99 }
100
101 ###########################################################################
102 ###########################################################################
103
104 if [scip-shell system . . `[`. ! $# -eq 2 ]; then
105 echoscip-shell system . . echo. 'Usage: archive_mail <bbs_callsign> <days>'
106 echoscip-shell system . . echo. archives messages older than specified number of days and deletes them
107 exit 1
108 fi
109
110 BBS_CALL=`echoscip-shell system . . echo. $1 | awkscip-shell system . . awk. '{ print toupper($0) }'`
111 MDATE=`datescip-shell system . . date. --date "$2 days ago" '+%y%m%d'`
112
113 if [scip-shell system . . `[`. ! -r ${LIST_PATH}/$BBS_CALL ]; then
114 echoscip-shell system . . echo. List for $BBS_CALL doesn\'t exist
115 exit 2
116 fi
117
118 if [scip-shell system . . `[`. ! -d ${MAIL_PATH}/$BBS_CALL ]; then
119 echoscip-shell system . . echo. Mail directory for $BBS_CALL doesn\'t exist
120 exit 3
121 fi
122
123 echoscip-shell system . . echo. Checking message dates
124 FIRSTNUM=`first_messagescip-shell shell shell-project 0.0.0 first_message().`
125 echoscip-shell system . . echo. Archiving messages up to number $FIRSTNUM
126 ARCNAME=${MAIL_PATH}/${BBS_CALL}/archive_`datescip-shell system . . date. +%y%m%d`.tar.gz
127 echoscip-shell system . . echo. Archiving to "\"$ARCNAME\""
128
129 if [scip-shell system . . `[`. -e $ARCNAME ]; then
130 echoscip-shell system . . echo. Todays archive already exists - exiting
131 exit 1
132 fi
133
134 cd ${MAIL_PATH}/${BBS_CALL}
135 tarscip-shell system . . tar. --remove-files -cvz -f $ARCNAME `older_messagesscip-shell shell shell-project 0.0.0 older_messages(). $FIRSTNUM` >/dev/nullscip-shell filesystem . . `/dev/null`.
136 cd $OLDPWD
137
138 echoscip-shell system . . echo. Updating mail index ${LIST_PATH}/${BBS_CALL}
139
140 if [scip-shell system . . `[`. -e ${LIST_PATH}/${BBS_CALL}.old.gz ]; then
141 gzipscip-shell system . . gzip. -d ${LIST_PATH}/${BBS_CALL}.old.gz
142 fi
143
144 list_oldscip-shell shell shell-project 0.0.0 list_old(). $FIRSTNUM >>${LIST_PATH}/${BBS_CALL}.old
145 list_newscip-shell shell shell-project 0.0.0 list_new(). $FIRSTNUM >>${LIST_PATH}/${BBS_CALL}.new
146 mvscip-shell system . . mv. ${LIST_PATH}/${BBS_CALL}.new ${LIST_PATH}/${BBS_CALL}
147
148 gzipscip-shell system . . gzip. ${LIST_PATH}/${BBS_CALL}.old
149
150 echoscip-shell system . . echo. Done.