source: trunk/mailtouser.sh @ 110

Last change on this file since 110 was 109, checked in by pinsard, 14 years ago

usage of program directive

  • 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#
88command=$(basename ${0})
89log_date=$(date -u +"%Y%m%dT%H%M%SZ")
90log=/tmp/$(basename ${command} .sh).log.${log_date}
91#
92usage=" Usage : ${command} -m mailbodyfile -x xmloutput"
93#
94# test if xmllint is available
95tool=xmllint
96type ${tool} 1> /dev/null 2>&1
97status=${?}
98if [ ${status} -ne 0 ]
99then
100   echo " eee : ${tool} not found"
101   exit 1
102fi
103unset tool
104unset status
105#
106# check for user.dtd
107if [ ! -f user.dtd ]
108then
109   echo "eee : user.dtd not found"
110   exit 1
111fi
112#
113set +u
114while [ ! -z "${1}" ]
115do
116   case ${1} in
117      -m)
118         mailbodyfile=${2}
119         shift
120      ;;
121      -x)
122         xmloutput=${2}
123         shift
124      ;;
125      *)
126         # other choice
127         echo "eee : unknown option ${1}"
128         echo "${usage}"
129         exit 1
130      ;;
131   esac
132   # next flag
133   shift
134done
135unset usage
136#
137set -u
138#
139# check for mailbodyfile
140if [ ! -f ${mailbodyfile} ]
141then
142   echo "eee : ${mailbodyfile} not found"
143   exit 1
144fi
145#
146# check for xmloutput
147#++ err si exist
148#
149echo "<user>" > ${xmloutput}
150echo "<!-- mailbodyfile : ${mailbodyfile} " >> ${xmloutput}
151cat ${mailbodyfile} >> ${xmloutput}
152echo "-->" >> ${xmloutput}
153echo "<!-- ${log_date} -->" >> ${xmloutput}
154author_id=$(grep "author_id=" ${mailbodyfile} | awk -F"=" '{print $2}')
155surname=$(grep "personal_surname=" ${mailbodyfile} | awk -F"=" '{print $2}')
156firstname=$(grep "personal_firstname=" ${mailbodyfile} | awk -F"=" '{print $2}')
157middlename=$(grep "personal_middlename=" ${mailbodyfile} | awk -F"=" '{print $2}')
158if [ "${author_id}" = "template" ]
159then
160  author_id=$( echo ${surname} | \
161     tr "[:lower:]" "[:upper:]" | \
162     tr " " "_"  | \
163     recode -d -f UTF-8..flat)
164  author_id=${author_id}_$( echo ${firstname:0:1} | \
165     tr "[:upper:]" "[:lower:]" | \
166     recode -d -f UTF-8..flat)
167fi
168echo "<userid>${author_id}</userid>" >> ${xmloutput}
169#
170echo "<personname>" >> ${xmloutput}
171#
172echo "<surname>$surname</surname>" >> ${xmloutput}
173#
174echo "<firstname>$firstname</firstname>" >> ${xmloutput}
175echo "<othername role='mi'>$middlename</othername>" >> ${xmloutput}
176#
177echo "</personname>" >> ${xmloutput}
178#
179email=$(grep "personal_email=" ${mailbodyfile} | awk -F"=" '{print $2}')
180echo "<email>$email</email>" >> ${xmloutput}
181#
182elements=components
183element=component
184#++ récupérer les users/user[child::userid='template']/components/component/name
185unset jlist
186unset jlist_name
187j=1
188jlist[${j}]="OPA"
189jlist_name[${j}]="OPA"
190j=$((${j} + 1))
191jlist[${j}]="LIM"
192jlist_name[${j}]="LIM"
193j=$((${j} + 1))
194jlist[${j}]="TOP"
195jlist_name[${j}]="TOP"
196j=$((${j} + 1))
197jlist[${j}]="TAM"
198jlist_name[${j}]="TAM"
199j=$((${j} + 1))
200jlist[${j}]="SAXO"
201jlist_name[${j}]="SAXO"
202j=$((${j} + 1))
203jlist[${j}]="offline"
204jlist_name[${j}]="Off-line"
205j=$((${j} + 1))
206jlist[${j}]="AGRIF"
207jlist_name[${j}]="AGRIF"
208echo "<${elements}>" >> ${xmloutput}
209components_date=$(grep "components_date=" ${mailbodyfile} | awk -F"=" '{print $2}')
210echo "<components_date>$components_date</components_date>" >> ${xmloutput}
211## find the element
212j=1
213jlistsize=${#jlist[@]}
214while [ ${j} -le ${jlistsize} ]
215do
216   jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:])
217   # recherche de ${jlist[j]}
218   grep -q "${element}_${jlist_min}" ${mailbodyfile}
219   ok=${?}
220   if [ ${ok} -eq 0 ]
221   then
222      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
223      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
224      echo "<value>yes</value>" >> ${xmloutput}
225      echo "</${element}>"  >> ${xmloutput}
226   else
227      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
228      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
229      echo "<value>no</value>" >> ${xmloutput}
230      echo "</${element}>"  >> ${xmloutput}
231   fi
232   j=$(( $j + 1 ))
233done
234echo "</${elements}>" >> ${xmloutput}
235#
236element=platform
237elements=platforms
238#++ récupérer les users/user[child::userid='template']/platforms/platform/name
239unset jlist
240unset jlist_name
241j=1
242jlist[${j}]="CRAY"
243jlist_name[${j}]="CRAY"
244j=$((${j} + 1))
245jlist[${j}]="IBM"
246jlist_name[${j}]="IBM"
247j=$((${j} + 1))
248jlist[${j}]="FUJITSU"
249jlist_name[${j}]="FUJITSU"
250j=$((${j} + 1))
251jlist[${j}]="MAC"
252jlist_name[${j}]="MAC"
253j=$((${j} + 1))
254jlist[${j}]="NEC"
255jlist_name[${j}]="NEC"
256j=$((${j} + 1))
257jlist[${j}]="SGI"
258jlist_name[${j}]="SGI"
259j=$((${j} + 1))
260jlist[${j}]="SUN"
261jlist_name[${j}]="SUN"
262j=$((${j} + 1))
263jlist[${j}]='pccluster'
264jlist_name[${j}]="PC Cluster"
265echo "<${elements}>" >> ${xmloutput}
266## find the element
267j=1
268jlistsize=${#jlist[@]}
269while [ ${j} -le ${jlistsize} ]
270do
271   # recherche de ${jlist[j]}
272   jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:])
273   grep -q "${element}_${jlist_min}" ${mailbodyfile}
274   ok=${?}
275   if [ ${ok} -eq 0 ]
276   then
277      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
278      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
279      echo "<value>yes</value>" >> ${xmloutput}
280      echo "</${element}>"  >> ${xmloutput}
281   else
282      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
283      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
284      echo "<value>no</value>" >> ${xmloutput}
285      echo "</${element}>"  >> ${xmloutput}
286   fi
287   j=$(( $j + 1 ))
288done
289#
290# gestion des "others"
291j=1
292jlistsize=${#jlist[@]}
293grep_cmd="grep ${element}_zzz_other ${mailbodyfile} "
294while [ ${j} -le ${jlistsize} ]
295do
296   grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile
297   j=$(( $j + 1 ))
298done
299other=$(eval ${grep_cmd} | awk -F "=" '{print$2}')
300echo "<${element} code='zzz_other'>" >> ${xmloutput}
301echo "<name>Other</name>" >> ${xmloutput}
302echo "<value>${other}</value>" >> ${xmloutput}
303echo "</${element}>"  >> ${xmloutput}
304echo "</${elements}>" >> ${xmloutput}
305#
306processors=$(grep "processors=" ${mailbodyfile} | awk -F"=" '{print $2}')
307echo "<processors>$processors</processors>" >> ${xmloutput}
308#
309element=compiler
310elements=compilers
311unset jlist
312unset jlist_name
313j=1
314jlist[${j}]="g95"
315jlist_name[${j}]="g95"
316j=$((${j} + 1))
317jlist[${j}]="ifort"
318jlist_name[${j}]="ifort"
319j=$((${j} + 1))
320jlist[${j}]="pgf"
321jlist_name[${j}]="pgf"
322j=$((${j} + 1))
323jlist[${j}]="sxf90"
324jlist_name[${j}]="sxf90"
325j=$((${j} + 1))
326jlist[${j}]="xlf"
327jlist_name[${j}]="xlf"
328echo "<${elements}>" >> ${xmloutput}
329## find the element
330j=1
331jlistsize=${#jlist[@]}
332while [ ${j} -le ${jlistsize} ]
333do
334   # recherche de ${jlist[j]}
335   jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:])
336   grep -q "${element}_${jlist_min}" ${mailbodyfile}
337   ok=${?}
338   if [ ${ok} -eq 0 ]
339   then
340      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
341      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
342      echo "<value>yes</value>" >> ${xmloutput}
343      echo "</${element}>"  >> ${xmloutput}
344   else
345      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
346      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
347      echo "<value>no</value>" >> ${xmloutput}
348      echo "</${element}>"  >> ${xmloutput}
349   fi
350   j=$(( $j + 1 ))
351done
352#
353# gestion des "others"
354j=1
355jlistsize=${#jlist[@]}
356grep_cmd="grep ${element}_zzz_other= ${mailbodyfile} "
357while [ ${j} -le ${jlistsize} ]
358do
359   grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile
360   j=$(( $j + 1 ))
361done
362other=$(eval ${grep_cmd} | awk -F "=" '{print$2}')
363echo "<${element} code='zzz_other'>" >> ${xmloutput}
364echo "<name>Other</name>" >> ${xmloutput}
365echo "<value>${other}</value>" >> ${xmloutput}
366echo "</${element}>"  >> ${xmloutput}
367echo "</${elements}>" >> ${xmloutput}
368#
369echo "</user>" >> ${xmloutput}
370#
371xmloutputfull=/tmp/${xmloutput} # ++
372echo '<?xml version="1.0" encoding="iso-8859-1"?>' > ${xmloutputfull}
373echo '<!DOCTYPE users SYSTEM "user.dtd">' >> ${xmloutputfull}
374echo '<users>' >> ${xmloutputfull}
375echo '<date>bidon</date>' >> ${xmloutputfull}
376cat ${xmloutput} >> ${xmloutputfull}
377echo '</users>' >> ${xmloutputfull}
378#
379# ++ parce que je ne sais pas dire où est la dtd dans la commande xmllint
380cp user.dtd /tmp/
381xmllint --noout --valid ${xmloutputfull} 1>> ${log} 2>> ${log}
382status=${?}
383if [ ${status} -ne 0 ]
384then
385   echo " eee : pb DTD conformance of ${xmloutputfull}"
386   echo " eee : see ${log}"
387   exit 1
388else
389   echo " iii : you can include ${xmloutput} in user.xml" #++ filename path
390   echo " iii : modify date in user.xml" #++ filename path
391fi
392#
393exit 0
Note: See TracBrowser for help on using the repository browser.