1 |
#! /usr/bin/env bash |
2 |
|
3 |
# $Header: $ |
4 |
# |
5 |
# The purpose of this script is to parse the emails produced by the |
6 |
# MITgcm/verificaton/testreport script and store the data in a |
7 |
# reasonable location. |
8 |
|
9 |
|
10 |
usage() |
11 |
{ |
12 |
echo |
13 |
echo "Usage: $0 [OPTIONS]" |
14 |
echo |
15 |
echo "where possible OPTIONS are:" |
16 |
echo " (-help|-h) print usage" |
17 |
echo " (-ind |-i )DIR get mpack-created emails from DIR" |
18 |
echo " [def=\"$INDIR\"]" |
19 |
echo " (-outd |-o )DIR write the data to DIR" |
20 |
echo " [def=\"$OUTDIR\"]" |
21 |
echo " (-tempd |-t )DIR use temporary directory DIR" |
22 |
echo " [def=\"$TEMPDIR\"]" |
23 |
echo |
24 |
exit 1 |
25 |
} |
26 |
|
27 |
# defaults |
28 |
INDIR="/u/edhill/Mail/MITgcm-test" |
29 |
OUTDIR= |
30 |
TEMPDIR=./ptmp |
31 |
MUNPACK=munpack |
32 |
|
33 |
# Parse options |
34 |
ac_prev= |
35 |
for ac_option ; do |
36 |
|
37 |
# If the previous option needs an argument, assign it. |
38 |
if test -n "$ac_prev"; then |
39 |
eval "$ac_prev=\$ac_option" |
40 |
ac_prev= |
41 |
continue |
42 |
fi |
43 |
|
44 |
ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` |
45 |
|
46 |
case $ac_option in |
47 |
|
48 |
-help | --help | -h | --h) |
49 |
usage ;; |
50 |
|
51 |
-ind | --ind | -i | --i) |
52 |
ac_prev=INDIR ;; |
53 |
--ind=* | -ind=* | --i=* | -i=*) |
54 |
INDIR=$ac_optarg ;; |
55 |
|
56 |
-outd | --outd | -o | --o) |
57 |
ac_prev=OUTDIR ;; |
58 |
--outd=* | -outd=* | --o=* | -o=*) |
59 |
OUTDIR=$ac_optarg ;; |
60 |
|
61 |
-tempd | --tempd | -t | --t) |
62 |
ac_prev=TEMPDIR ;; |
63 |
--tempd=* | -tempd=* | --t=* | -t=*) |
64 |
TEMPDIR=$ac_optarg ;; |
65 |
|
66 |
*) |
67 |
# copy the file list to FL_# |
68 |
echo "Error: don't understand argument \"$ac_option\"" |
69 |
usage |
70 |
;; |
71 |
|
72 |
esac |
73 |
|
74 |
done |
75 |
|
76 |
if test "x$OUTDIR" = x ; then |
77 |
OUTDIR="/u/u0/httpd/html/testing/results/"`date +%Y`"_"`date +%m` |
78 |
fi |
79 |
if test ! -e $OUTDIR ; then |
80 |
mkdir $OUTDIR |
81 |
RETVAL=$? |
82 |
if test "x$RETVAL" = x ; then |
83 |
echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created" |
84 |
exit 1 |
85 |
fi |
86 |
fi |
87 |
|
88 |
echo "Using OUTDIR=\"$OUTDIR\"" |
89 |
echo "Using INDIR=\"$INDIR\"" |
90 |
|
91 |
all_files=`ls -1 $INDIR` |
92 |
|
93 |
echo -n "Unpacking the emails ..." |
94 |
for file in $all_files ; do |
95 |
|
96 |
# create local copy |
97 |
rm -rf $TEMPDIR |
98 |
mkdir $TEMPDIR |
99 |
cp $INDIR"/"$file $TEMPDIR |
100 |
|
101 |
# ignore multi-part messages |
102 |
grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1 |
103 |
RETVAL=$? |
104 |
if test "x$RETVAL" = x0 ; then |
105 |
continue |
106 |
fi |
107 |
|
108 |
# munpack |
109 |
mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )` |
110 |
RETVAL=$? |
111 |
if test "x$RETVAL" != x0 ; then |
112 |
continue |
113 |
fi |
114 |
|
115 |
# un-tar |
116 |
( cd $TEMPDIR ; tar -xzvf $mun > out ) |
117 |
RETVAL=$? |
118 |
if test "x$RETVAL" != x0 ; then |
119 |
continue |
120 |
fi |
121 |
tdir=`cat $TEMPDIR"/out" | head -1 | cut -d '/' -f 1` |
122 |
rm -f $TEMPDIR"/out" |
123 |
|
124 |
# copy to $OUTDIR and rename if necessary |
125 |
if test -e $OUTDIR"/"$tdir ; then |
126 |
ad=0 |
127 |
while test -e $OUTDIR"/"$tdir"_"$ad ; do |
128 |
ad=$(( $ad + 1 )) |
129 |
done |
130 |
mv $TEMPDIR"/"$tdir $OUTDIR"/"$tdir"_"$ad |
131 |
else |
132 |
mv $TEMPDIR"/"$tdir $OUTDIR |
133 |
fi |
134 |
|
135 |
# If it exists, gzip the "output.txt" file. |
136 |
if test -r $OUTDIR"/"$tdir"/output.txt" ; then |
137 |
gzip $OUTDIR"/"$tdir"/output.txt" |
138 |
fi |
139 |
|
140 |
# remove the original file |
141 |
rm -f $INDIR"/"$file |
142 |
|
143 |
done |
144 |
echo " done" |
145 |
|
146 |
echo -n "gzipping all the \"output.txt\" files ..." |
147 |
( |
148 |
cd $OUTDIR |
149 |
outp=`find . -name output.txt` |
150 |
if test "x$outp" != x ; then |
151 |
gzip $outp |
152 |
fi |
153 |
) |
154 |
echo " done" |
155 |
|
156 |
echo -n "setting permissions to world-readable ..." |
157 |
chmod -R a+rx $OUTDIR |
158 |
echo " done" |