13 |
echo "Usage: $0 [OPTIONS]" |
echo "Usage: $0 [OPTIONS]" |
14 |
echo |
echo |
15 |
echo "where possible OPTIONS are:" |
echo "where possible OPTIONS are:" |
16 |
echo " (-help|-h) print usage" |
echo " (-h|-help) print usage" |
17 |
echo " (-ind |-i )DIR get mpack-created emails from DIR" |
echo " (-s|-silent) silent mode" |
18 |
|
echo " (-v|-verbose) verbose mode" |
19 |
|
echo " (-i |-ind )DIR get mpack-created emails from DIR" |
20 |
echo " [def=\"$INDIR\"]" |
echo " [def=\"$INDIR\"]" |
21 |
echo " (-outd |-o )DIR write the data to DIR" |
echo " (-o |-outd )DIR write the data to DIR" |
22 |
echo " [def=\"$OUTDIR\"]" |
echo " [def=\"$OUTDIR\"]" |
23 |
echo " (-tempd |-t )DIR use temporary directory DIR" |
echo " (-t |-tempd )DIR use temporary directory DIR" |
24 |
echo " [def=\"$TEMPDIR\"]" |
echo " [def=\"$TEMPDIR\"]" |
25 |
echo |
echo |
26 |
exit 1 |
exit 1 |
30 |
INDIR="/u/edhill/Mail/MITgcm-test" |
INDIR="/u/edhill/Mail/MITgcm-test" |
31 |
OUTDIR= |
OUTDIR= |
32 |
TEMPDIR=./ptmp |
TEMPDIR=./ptmp |
33 |
MUNPACK=/usr/local/bin/munpack |
MUNPACK=/u/edhill/local/bin/munpack |
34 |
|
PRT=1 |
35 |
|
|
36 |
# Parse options |
# Parse options |
37 |
ac_prev= |
ac_prev= |
50 |
|
|
51 |
-help | --help | -h | --h) |
-help | --help | -h | --h) |
52 |
usage ;; |
usage ;; |
53 |
|
-s | --s | -silent | --silent) |
54 |
|
PRT=0 ;; |
55 |
|
-v | --v | -verbose | --verbose) |
56 |
|
PRT=2 ;; |
57 |
|
|
58 |
-ind | --ind | -i | --i) |
-ind | --ind | -i | --i) |
59 |
ac_prev=INDIR ;; |
ac_prev=INDIR ;; |
90 |
echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created" |
echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created" |
91 |
exit 1 |
exit 1 |
92 |
fi |
fi |
93 |
|
chgrp gcmpack $OUTDIR |
94 |
|
chmod 775 $OUTDIR |
95 |
fi |
fi |
96 |
|
|
|
echo "Using OUTDIR=\"$OUTDIR\"" |
|
|
echo "Using INDIR=\"$INDIR\"" |
|
|
|
|
97 |
all_files=`ls -1 $INDIR` |
all_files=`ls -1 $INDIR` |
98 |
|
nb_files=`echo $all_files | grep -c '^msg\.'` |
99 |
|
|
100 |
|
if test $PRT = 1 ; then |
101 |
|
echo "Using OUTDIR=\"$OUTDIR\"" |
102 |
|
echo "Using INDIR=\"$INDIR\"" |
103 |
|
echo -n "Unpacking the emails ..." |
104 |
|
elif test $nb_files != 0 ; then |
105 |
|
echo "Unpacking $nb_files emails from '$INDIR' to '$OUTDIR'" |
106 |
|
if test $PRT = 2 ; then echo -n " dir:" ; fi |
107 |
|
fi |
108 |
|
|
|
echo -n "Unpacking the emails ..." |
|
109 |
for file in $all_files ; do |
for file in $all_files ; do |
110 |
|
|
111 |
# create local copy |
# create local copy |
137 |
rm -f $TEMPDIR"/out" |
rm -f $TEMPDIR"/out" |
138 |
|
|
139 |
# copy to $OUTDIR and rename if necessary |
# copy to $OUTDIR and rename if necessary |
140 |
|
sdir=$tdir |
141 |
if test -e $OUTDIR"/"$tdir ; then |
if test -e $OUTDIR"/"$tdir ; then |
142 |
ad=0 |
ad=0 |
143 |
while test -e $OUTDIR"/"$tdir"_"$ad ; do |
while test -e $OUTDIR"/"$tdir"_"$ad ; do |
144 |
ad=$(( $ad + 1 )) |
ad=$(( $ad + 1 )) |
145 |
done |
done |
146 |
mv $TEMPDIR"/"$tdir $OUTDIR"/"$tdir"_"$ad |
sdir=$tdir"_"$ad |
|
else |
|
|
mv $TEMPDIR"/"$tdir $OUTDIR |
|
|
fi |
|
|
|
|
|
# If it exists, gzip the "output.txt" file. |
|
|
if test -r $OUTDIR"/"$tdir"/output.txt" ; then |
|
|
gzip $OUTDIR"/"$tdir"/output.txt" |
|
147 |
fi |
fi |
148 |
|
if test $PRT = 2 ; then echo -n " '$sdir'" ; fi |
149 |
|
mv $TEMPDIR"/"$tdir $OUTDIR"/"$sdir > /dev/null 2>&1 |
150 |
|
chmod -R a+rx $OUTDIR"/"$sdir > /dev/null 2>&1 |
151 |
|
# gzip $OUTDIR"/"$sdir"/output.txt" |
152 |
|
|
153 |
# remove the original file |
# remove the original file |
154 |
rm -f $INDIR"/"$file |
rm -f $INDIR"/"$file |
155 |
|
|
156 |
done |
done |
157 |
echo " done" |
if test $PRT = 1 ; then echo " done" ; fi |
158 |
|
if test $PRT = 2 -a $nb_files != 0 ; then echo "" ; fi |
159 |
|
|
160 |
echo -n "gzipping all the \"output.txt\" files ..." |
# echo -n "gzipping all the \"output.txt\" files ..." |
161 |
( |
# ( |
162 |
cd $OUTDIR |
# cd $OUTDIR |
163 |
outp=`find . -name output.txt` |
# outp=`find . -name output.txt` |
164 |
if test "x$outp" != x ; then |
# if test "x$outp" != x ; then |
165 |
gzip $outp |
# gzip $outp |
166 |
fi |
# fi |
167 |
) |
# ) |
168 |
echo " done" |
# echo " done" |
169 |
|
|
170 |
echo -n "setting permissions to world-readable ..." |
# echo -n "setting permissions to world-readable ..." |
171 |
chmod -R a+rx $OUTDIR |
# chmod -R a+rx $OUTDIR > /dev/null 2>&1 |
172 |
echo " done" |
# echo " done" |
173 |
|
|
174 |
|
|