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
RevLine 
[2]1#! /bin/sh
[75]2#+
[80]3#
[109]4# .. program:: mailtouser.sh
[103]5#
[95]6# =============
7# mailtouser.sh
8# =============
[2]9#
[95]10# -------------------------------------------------
11# convert email text in xml form following user.dtd
12# -------------------------------------------------
[2]13#
[93]14# SYNOPSIS
[75]15# ========
[2]16#
[75]17# ::
18#
19#  $ mailtouser.sh -m mailbodyfile -x xmloutput
20#
21#
22#
23# DESCRIPTION
24# ===========
25#
[108]26# .. option:: -m <mailbodyfile>
27# .. option:: -x <xmloutput>
[75]28#
[108]29# convert email text in xml form following :file:`user.dtd`
30#
[80]31# SEE ALSO
32# ========
[2]33#
[103]34# :ref:`bibopa.sh`
[80]35#
[75]36# EXAMPLES
37# ========
38#
39# ::
40#
41#  $ ./mailtouser.sh -m data/mail2007-05-10T09:01:56Z -x ginette.xml
42#
43#
[95]44# TODO
45# ====
[75]46#
[2]47# ++ gestion des comments
[75]48#
[2]49# ++ gestion de la signature
[75]50#
[95]51# EVOLUTIONS
52# ==========
53#
[4]54# $Id$
[2]55#
[75]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
[100]79   AIX|IRIX64)
80      echo " www : no specific posix checking"
81   ;;
82   *)
83      set -o posix
84   ;;
[75]85esac
[100]86unset system
87#
[80]88command=$(basename ${0})
[93]89log_date=$(date -u +"%Y%m%dT%H%M%SZ")
90log=/tmp/$(basename ${command} .sh).log.${log_date}
[2]91#
92usage=" Usage : ${command} -m mailbodyfile -x xmloutput"
93#
94# test if xmllint is available
[80]95tool=xmllint
96type ${tool} 1> /dev/null 2>&1
[2]97status=${?}
98if [ ${status} -ne 0 ]
99then
[100]100   echo " eee : ${tool} not found"
101   exit 1
[2]102fi
[80]103unset tool
104unset status
[2]105#
[31]106# check for user.dtd
107if [ ! -f user.dtd ]
[2]108then
[100]109   echo "eee : user.dtd not found"
110   exit 1
[2]111fi
112#
[102]113set +u
114while [ ! -z "${1}" ]
[2]115do
[100]116   case ${1} in
[101]117      -m)
[100]118         mailbodyfile=${2}
119         shift
120      ;;
[101]121      -x)
[100]122         xmloutput=${2}
123         shift
124      ;;
[101]125      *)
126         # other choice
[100]127         echo "eee : unknown option ${1}"
128         echo "${usage}"
129         exit 1
130      ;;
131   esac
[101]132   # next flag
133   shift
[2]134done
[100]135unset usage
[2]136#
137set -u
138#
139# check for mailbodyfile
140if [ ! -f ${mailbodyfile} ]
141then
[100]142   echo "eee : ${mailbodyfile} not found"
143   exit 1
[2]144fi
145#
146# check for xmloutput
147#++ err si exist
148#
[31]149echo "<user>" > ${xmloutput}
[2]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
[100]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)
[2]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
[31]184#++ récupérer les users/user[child::userid='template']/components/component/name
[4]185unset jlist
186unset jlist_name
[2]187j=1
188jlist[${j}]="OPA"
[4]189jlist_name[${j}]="OPA"
[2]190j=$((${j} + 1))
191jlist[${j}]="LIM"
[4]192jlist_name[${j}]="LIM"
[2]193j=$((${j} + 1))
194jlist[${j}]="TOP"
[4]195jlist_name[${j}]="TOP"
[2]196j=$((${j} + 1))
197jlist[${j}]="TAM"
[4]198jlist_name[${j}]="TAM"
[2]199j=$((${j} + 1))
200jlist[${j}]="SAXO"
[4]201jlist_name[${j}]="SAXO"
[2]202j=$((${j} + 1))
[4]203jlist[${j}]="offline"
204jlist_name[${j}]="Off-line"
[2]205j=$((${j} + 1))
206jlist[${j}]="AGRIF"
[4]207jlist_name[${j}]="AGRIF"
[2]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
[100]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 ))
[2]233done
234echo "</${elements}>" >> ${xmloutput}
235#
236element=platform
237elements=platforms
[31]238#++ récupérer les users/user[child::userid='template']/platforms/platform/name
[4]239unset jlist
240unset jlist_name
[2]241j=1
242jlist[${j}]="CRAY"
[4]243jlist_name[${j}]="CRAY"
[2]244j=$((${j} + 1))
245jlist[${j}]="IBM"
[4]246jlist_name[${j}]="IBM"
[2]247j=$((${j} + 1))
248jlist[${j}]="FUJITSU"
[4]249jlist_name[${j}]="FUJITSU"
[2]250j=$((${j} + 1))
251jlist[${j}]="MAC"
[4]252jlist_name[${j}]="MAC"
[2]253j=$((${j} + 1))
254jlist[${j}]="NEC"
[4]255jlist_name[${j}]="NEC"
[2]256j=$((${j} + 1))
257jlist[${j}]="SGI"
[4]258jlist_name[${j}]="SGI"
[2]259j=$((${j} + 1))
260jlist[${j}]="SUN"
[4]261jlist_name[${j}]="SUN"
[2]262j=$((${j} + 1))
[4]263jlist[${j}]='pccluster'
264jlist_name[${j}]="PC Cluster"
[2]265echo "<${elements}>" >> ${xmloutput}
266## find the element
267j=1
268jlistsize=${#jlist[@]}
269while [ ${j} -le ${jlistsize} ]
270do
[100]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 ))
[2]288done
289#
290# gestion des "others"
291j=1
292jlistsize=${#jlist[@]}
293grep_cmd="grep ${element}_zzz_other ${mailbodyfile} "
294while [ ${j} -le ${jlistsize} ]
295do
[100]296   grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile
297   j=$(( $j + 1 ))
[2]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
[4]312unset jlist_name
[2]313j=1
314jlist[${j}]="g95"
[4]315jlist_name[${j}]="g95"
[2]316j=$((${j} + 1))
317jlist[${j}]="ifort"
[4]318jlist_name[${j}]="ifort"
[2]319j=$((${j} + 1))
320jlist[${j}]="pgf"
[4]321jlist_name[${j}]="pgf"
[2]322j=$((${j} + 1))
323jlist[${j}]="sxf90"
[4]324jlist_name[${j}]="sxf90"
[2]325j=$((${j} + 1))
326jlist[${j}]="xlf"
[4]327jlist_name[${j}]="xlf"
[2]328echo "<${elements}>" >> ${xmloutput}
329## find the element
330j=1
331jlistsize=${#jlist[@]}
332while [ ${j} -le ${jlistsize} ]
333do
[100]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 ))
[2]351done
352#
353# gestion des "others"
354j=1
355jlistsize=${#jlist[@]}
356grep_cmd="grep ${element}_zzz_other= ${mailbodyfile} "
357while [ ${j} -le ${jlistsize} ]
358do
[100]359   grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile
360   j=$(( $j + 1 ))
[2]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#
[31]369echo "</user>" >> ${xmloutput}
[2]370#
371xmloutputfull=/tmp/${xmloutput} # ++
372echo '<?xml version="1.0" encoding="iso-8859-1"?>' > ${xmloutputfull}
[31]373echo '<!DOCTYPE users SYSTEM "user.dtd">' >> ${xmloutputfull}
374echo '<users>' >> ${xmloutputfull}
[2]375echo '<date>bidon</date>' >> ${xmloutputfull}
376cat ${xmloutput} >> ${xmloutputfull}
[31]377echo '</users>' >> ${xmloutputfull}
[2]378#
379# ++ parce que je ne sais pas dire où est la dtd dans la commande xmllint
[31]380cp user.dtd /tmp/
[2]381xmllint --noout --valid ${xmloutputfull} 1>> ${log} 2>> ${log}
382status=${?}
383if [ ${status} -ne 0 ]
384then
[100]385   echo " eee : pb DTD conformance of ${xmloutputfull}"
386   echo " eee : see ${log}"
387   exit 1
[2]388else
[100]389   echo " iii : you can include ${xmloutput} in user.xml" #++ filename path
390   echo " iii : modify date in user.xml" #++ filename path
[2]391fi
392#
393exit 0
Note: See TracBrowser for help on using the repository browser.