source: trunk/mailtouser.sh @ 164

Last change on this file since 164 was 116, checked in by pinsard, 13 years ago

Consolidation of shell scripts

  • Property svn:keywords set to Id
File size: 9.4 KB
Line 
1#! /bin/sh
2#+
3#
4# .. program:: mailtouser.sh
5#
6# =============
7# mailtouser.sh
8# =============
9#
10# -------------------------------------------------
11# convert email text in xml form following user.dtd
12# -------------------------------------------------
13#
14# SYNOPSIS
15# ========
16#
17# ::
18#
19#  $ mailtouser.sh -m mailbodyfile -x xmloutput
20#
21#
22#
23# DESCRIPTION
24# ===========
25#
26# .. option:: -m <mailbodyfile>
27# .. option:: -x <xmloutput>
28#
29# convert email text in xml form following :file:`user.dtd`
30#
31# SEE ALSO
32# ========
33#
34# :ref:`bibopa.sh`
35#
36# EXAMPLES
37# ========
38#
39# ::
40#
41#  $ ./mailtouser.sh -m data/mail2007-05-10T09:01:56Z -x ginette.xml
42#
43#
44# TODO
45# ====
46#
47# ++ gestion des comments
48#
49# ++ gestion de la signature
50#
51# EVOLUTIONS
52# ==========
53#
54# $Id$
55#
56# - fplod 2008-09-16T15:42:41Z aedon.locean-ipsl.upmc.fr (Darwin)
57#
58#  * comments in ReStructured Text
59#
60# - fplod 2007-06-06T09:27:55Z aedon.locean-ipsl.upmc.fr (Darwin)
61#
62#  * correction for Off-Line and PC Cluster
63#
64# - fplod 2007-05-18T08:31:48Z aedon.locean-ipsl.upmc.fr (Darwin)
65#
66#  * add off-line and agrif components
67#
68# - fplod 2007-05-09T15:03:15Z aedon.locean-ipsl.upmc.fr (Darwin)
69#
70#  * reprise + ajout middlename + ajout components_date
71#
72# - fplod 2007-04-25T09:15:38Z aedon.locean-ipsl.upmc.fr (Darwin)
73#
74#  * creation
75#
76#-
77system=$(uname)
78case "${system}" in
79   AIX|IRIX64)
80      echo " www : no specific posix checking"
81   ;;
82   *)
83      set -o posix
84   ;;
85esac
86unset system
87#
88set -u
89#
90command=$(basename ${0})
91log_date=$(date -u +"%Y%m%dT%H%M%SZ")
92log=/tmp/$(basename ${command} .sh).log.${log_date}
93#
94usage=" Usage : ${command} -m mailbodyfile -x xmloutput"
95#
96# test if xmllint is available
97tool=xmllint
98type ${tool} 1> /dev/null 2>&1
99status=${?}
100if [ ${status} -ne 0 ]
101then
102   echo " eee : ${tool} not found"
103   exit 1
104fi
105unset tool
106unset status
107#
108# check for user.dtd
109if [ ! -f user.dtd ]
110then
111   echo "eee : user.dtd not found"
112   exit 1
113fi
114#
115while [ ${#} -gt 0 ]
116do
117   case ${1} in
118      -m)
119         mailbodyfile=${2}
120         shift
121      ;;
122      -x)
123         xmloutput=${2}
124         shift
125      ;;
126      *)
127         # other choice
128         echo "eee : unknown option ${1}"
129         echo "${usage}"
130         exit 1
131      ;;
132   esac
133   # next flag
134   shift
135done
136unset usage
137#
138# check for mailbodyfile
139if [ ! -f ${mailbodyfile} ]
140then
141   echo "eee : ${mailbodyfile} not found"
142   exit 1
143fi
144#
145# check for xmloutput
146#++ err si exist
147#
148echo "<user>" > ${xmloutput}
149echo "<!-- mailbodyfile : ${mailbodyfile} " >> ${xmloutput}
150cat ${mailbodyfile} >> ${xmloutput}
151echo "-->" >> ${xmloutput}
152echo "<!-- ${log_date} -->" >> ${xmloutput}
153author_id=$(grep "author_id=" ${mailbodyfile} | awk -F"=" '{print $2}')
154surname=$(grep "personal_surname=" ${mailbodyfile} | awk -F"=" '{print $2}')
155firstname=$(grep "personal_firstname=" ${mailbodyfile} | awk -F"=" '{print $2}')
156middlename=$(grep "personal_middlename=" ${mailbodyfile} | awk -F"=" '{print $2}')
157if [ "${author_id}" = "template" ]
158then
159  author_id=$( echo ${surname} | \
160     tr "[:lower:]" "[:upper:]" | \
161     tr " " "_"  | \
162     recode -d -f UTF-8..flat)
163  author_id=${author_id}_$( echo ${firstname:0:1} | \
164     tr "[:upper:]" "[:lower:]" | \
165     recode -d -f UTF-8..flat)
166fi
167echo "<userid>${author_id}</userid>" >> ${xmloutput}
168#
169echo "<personname>" >> ${xmloutput}
170#
171echo "<surname>$surname</surname>" >> ${xmloutput}
172#
173echo "<firstname>$firstname</firstname>" >> ${xmloutput}
174echo "<othername role='mi'>$middlename</othername>" >> ${xmloutput}
175#
176echo "</personname>" >> ${xmloutput}
177#
178email=$(grep "personal_email=" ${mailbodyfile} | awk -F"=" '{print $2}')
179echo "<email>$email</email>" >> ${xmloutput}
180#
181elements=components
182element=component
183#++ récupérer les users/user[child::userid='template']/components/component/name
184unset jlist
185unset jlist_name
186j=1
187jlist[${j}]="OPA"
188jlist_name[${j}]="OPA"
189j=$((${j} + 1))
190jlist[${j}]="LIM"
191jlist_name[${j}]="LIM"
192j=$((${j} + 1))
193jlist[${j}]="TOP"
194jlist_name[${j}]="TOP"
195j=$((${j} + 1))
196jlist[${j}]="TAM"
197jlist_name[${j}]="TAM"
198j=$((${j} + 1))
199jlist[${j}]="SAXO"
200jlist_name[${j}]="SAXO"
201j=$((${j} + 1))
202jlist[${j}]="offline"
203jlist_name[${j}]="Off-line"
204j=$((${j} + 1))
205jlist[${j}]="AGRIF"
206jlist_name[${j}]="AGRIF"
207echo "<${elements}>" >> ${xmloutput}
208components_date=$(grep "components_date=" ${mailbodyfile} | awk -F"=" '{print $2}')
209echo "<components_date>$components_date</components_date>" >> ${xmloutput}
210## find the element
211j=1
212jlistsize=${#jlist[@]}
213while [ ${j} -le ${jlistsize} ]
214do
215   jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:])
216   # recherche de ${jlist[j]}
217   grep -q "${element}_${jlist_min}" ${mailbodyfile}
218   ok=${?}
219   if [ ${ok} -eq 0 ]
220   then
221      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
222      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
223      echo "<value>yes</value>" >> ${xmloutput}
224      echo "</${element}>"  >> ${xmloutput}
225   else
226      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
227      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
228      echo "<value>no</value>" >> ${xmloutput}
229      echo "</${element}>"  >> ${xmloutput}
230   fi
231   j=$(( $j + 1 ))
232done
233echo "</${elements}>" >> ${xmloutput}
234#
235element=platform
236elements=platforms
237#++ récupérer les users/user[child::userid='template']/platforms/platform/name
238unset jlist
239unset jlist_name
240j=1
241jlist[${j}]="CRAY"
242jlist_name[${j}]="CRAY"
243j=$((${j} + 1))
244jlist[${j}]="IBM"
245jlist_name[${j}]="IBM"
246j=$((${j} + 1))
247jlist[${j}]="FUJITSU"
248jlist_name[${j}]="FUJITSU"
249j=$((${j} + 1))
250jlist[${j}]="MAC"
251jlist_name[${j}]="MAC"
252j=$((${j} + 1))
253jlist[${j}]="NEC"
254jlist_name[${j}]="NEC"
255j=$((${j} + 1))
256jlist[${j}]="SGI"
257jlist_name[${j}]="SGI"
258j=$((${j} + 1))
259jlist[${j}]="SUN"
260jlist_name[${j}]="SUN"
261j=$((${j} + 1))
262jlist[${j}]='pccluster'
263jlist_name[${j}]="PC Cluster"
264echo "<${elements}>" >> ${xmloutput}
265## find the element
266j=1
267jlistsize=${#jlist[@]}
268while [ ${j} -le ${jlistsize} ]
269do
270   # recherche de ${jlist[j]}
271   jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:])
272   grep -q "${element}_${jlist_min}" ${mailbodyfile}
273   ok=${?}
274   if [ ${ok} -eq 0 ]
275   then
276      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
277      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
278      echo "<value>yes</value>" >> ${xmloutput}
279      echo "</${element}>"  >> ${xmloutput}
280   else
281      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
282      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
283      echo "<value>no</value>" >> ${xmloutput}
284      echo "</${element}>"  >> ${xmloutput}
285   fi
286   j=$(( $j + 1 ))
287done
288#
289# gestion des "others"
290j=1
291jlistsize=${#jlist[@]}
292grep_cmd="grep ${element}_zzz_other ${mailbodyfile} "
293while [ ${j} -le ${jlistsize} ]
294do
295   grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile
296   j=$(( $j + 1 ))
297done
298other=$(eval ${grep_cmd} | awk -F "=" '{print$2}')
299echo "<${element} code='zzz_other'>" >> ${xmloutput}
300echo "<name>Other</name>" >> ${xmloutput}
301echo "<value>${other}</value>" >> ${xmloutput}
302echo "</${element}>"  >> ${xmloutput}
303echo "</${elements}>" >> ${xmloutput}
304#
305processors=$(grep "processors=" ${mailbodyfile} | awk -F"=" '{print $2}')
306echo "<processors>$processors</processors>" >> ${xmloutput}
307#
308element=compiler
309elements=compilers
310unset jlist
311unset jlist_name
312j=1
313jlist[${j}]="g95"
314jlist_name[${j}]="g95"
315j=$((${j} + 1))
316jlist[${j}]="ifort"
317jlist_name[${j}]="ifort"
318j=$((${j} + 1))
319jlist[${j}]="pgf"
320jlist_name[${j}]="pgf"
321j=$((${j} + 1))
322jlist[${j}]="sxf90"
323jlist_name[${j}]="sxf90"
324j=$((${j} + 1))
325jlist[${j}]="xlf"
326jlist_name[${j}]="xlf"
327echo "<${elements}>" >> ${xmloutput}
328## find the element
329j=1
330jlistsize=${#jlist[@]}
331while [ ${j} -le ${jlistsize} ]
332do
333   # recherche de ${jlist[j]}
334   jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:])
335   grep -q "${element}_${jlist_min}" ${mailbodyfile}
336   ok=${?}
337   if [ ${ok} -eq 0 ]
338   then
339      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
340      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
341      echo "<value>yes</value>" >> ${xmloutput}
342      echo "</${element}>"  >> ${xmloutput}
343   else
344      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
345      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
346      echo "<value>no</value>" >> ${xmloutput}
347      echo "</${element}>"  >> ${xmloutput}
348   fi
349   j=$(( $j + 1 ))
350done
351#
352# gestion des "others"
353j=1
354jlistsize=${#jlist[@]}
355grep_cmd="grep ${element}_zzz_other= ${mailbodyfile} "
356while [ ${j} -le ${jlistsize} ]
357do
358   grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile
359   j=$(( $j + 1 ))
360done
361other=$(eval ${grep_cmd} | awk -F "=" '{print$2}')
362echo "<${element} code='zzz_other'>" >> ${xmloutput}
363echo "<name>Other</name>" >> ${xmloutput}
364echo "<value>${other}</value>" >> ${xmloutput}
365echo "</${element}>"  >> ${xmloutput}
366echo "</${elements}>" >> ${xmloutput}
367#
368echo "</user>" >> ${xmloutput}
369#
370xmloutputfull=/tmp/${xmloutput} # ++
371echo '<?xml version="1.0" encoding="iso-8859-1"?>' > ${xmloutputfull}
372echo '<!DOCTYPE users SYSTEM "user.dtd">' >> ${xmloutputfull}
373echo '<users>' >> ${xmloutputfull}
374echo '<date>bidon</date>' >> ${xmloutputfull}
375cat ${xmloutput} >> ${xmloutputfull}
376echo '</users>' >> ${xmloutputfull}
377#
378# ++ parce que je ne sais pas dire où est la dtd dans la commande xmllint
379cp user.dtd /tmp/
380xmllint --noout --valid ${xmloutputfull} 1>> ${log} 2>> ${log}
381status=${?}
382if [ ${status} -ne 0 ]
383then
384   echo " eee : pb DTD conformance of ${xmloutputfull}"
385   echo " eee : see ${log}"
386   exit 1
387else
388   echo " iii : you can include ${xmloutput} in user.xml" #++ filename path
389   echo " iii : modify date in user.xml" #++ filename path
390fi
391#
392exit 0
Note: See TracBrowser for help on using the repository browser.