-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfetch-mailman-archives
executable file
·87 lines (76 loc) · 1.74 KB
/
fetch-mailman-archives
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/sh
usage()
{
cat >&2 <<__EOF__
Usage: $(basename $0) -U list_url -s start_year [ -m start_month ] [ -x extension ]
Options:
-s start_year -- Year at which to start downloading ML archives.
-m start_month -- Month at which to start downloading ML archives. Must
be specified by name, e.g. "November."
-U list_url -- The URL of the directory containing the ML archives.
-x extension -- An optional extension to add to each archive file,
e.g. "gz"
__EOF__
exit ${1-1}
}
log()
{
echo "$(basename $0): $1" 1>&2
}
while [ $# -gt 0 ]; do
case $1 in
-h|--help)
usage 0
;;
-m)
shift; STARTMONTH="$1"
;;
-s)
shift; STARTYEAR="$1"
;;
-U)
shift; URL="$1"
;;
-x)
shift; EXT=".$1"
;;
*)
usage
;;
esac
shift
done
if [ -z "$URL" ] || [ -z "$STARTYEAR" ]; then
usage
elif ! expr "$STARTYEAR" : '[1-9][0-9]*' >/dev/null 2>&1; then
log "invalid year '$STARTYEAR'"
usage
fi
MONTHS="January
February
March
April
May
June
July
August
September
October
November
December"
YEAR=$STARTYEAR
while [ $YEAR -le $(date '+%Y') ]; do
for MONTH in $MONTHS; do
[ $YEAR -eq $STARTYEAR -a -n "$STARTMONTH" \
-a -n "$(echo $MONTHS | grep ${MONTH}.*${STARTMONTH})" ] && continue
fetch "${URL}/${YEAR}-${MONTH}.txt${EXT}"
[ $? -eq 0 ] || continue
case $EXT in
.gz)
gunzip ${YEAR}-${MONTH}.txt.gz
;;
esac
[ $YEAR -eq $(date '+%Y') -a $MONTH = $(date '+%B') ] && break
done
YEAR=$((YEAR + 1))
done