source: trunk/mailtouser.sh @ 140

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

Consolidation of shell scripts

  • 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#
[116]88set -u
89#
[80]90command=$(basename ${0})
[93]91log_date=$(date -u +"%Y%m%dT%H%M%SZ")
92log=/tmp/$(basename ${command} .sh).log.${log_date}
[2]93#
94usage=" Usage : ${command} -m mailbodyfile -x xmloutput"
95#
96# test if xmllint is available
[80]97tool=xmllint
98type ${tool} 1> /dev/null 2>&1
[2]99status=${?}
100if [ ${status} -ne 0 ]
101then
[100]102   echo " eee : ${tool} not found"
103   exit 1
[2]104fi
[80]105unset tool
106unset status
[2]107#
[31]108# check for user.dtd
109if [ ! -f user.dtd ]
[2]110then
[100]111   echo "eee : user.dtd not found"
112   exit 1
[2]113fi
114#
[116]115while [ ${#} -gt 0 ]
[2]116do
[100]117   case ${1} in
[101]118      -m)
[100]119         mailbodyfile=${2}
120         shift
121      ;;
[101]122      -x)
[100]123         xmloutput=${2}
124         shift
125      ;;
[101]126      *)
127         # other choice
[100]128         echo "eee : unknown option ${1}"
129         echo "${usage}"
130         exit 1
131      ;;
132   esac
[101]133   # next flag
134   shift
[2]135done
[100]136unset usage
[2]137#
138# check for mailbodyfile
139if [ ! -f ${mailbodyfile} ]
140then
[100]141   echo "eee : ${mailbodyfile} not found"
142   exit 1
[2]143fi
144#
145# check for xmloutput
146#++ err si exist
147#
[31]148echo "<user>" > ${xmloutput}
[2]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
[100]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)
[2]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
[31]183#++ récupérer les users/user[child::userid='template']/components/component/name
[4]184unset jlist
185unset jlist_name
[2]186j=1
187jlist[${j}]="OPA"
[4]188jlist_name[${j}]="OPA"
[2]189j=$((${j} + 1))
190jlist[${j}]="LIM"
[4]191jlist_name[${j}]="LIM"
[2]192j=$((${j} + 1))
193jlist[${j}]="TOP"
[4]194jlist_name[${j}]="TOP"
[2]195j=$((${j} + 1))
196jlist[${j}]="TAM"
[4]197jlist_name[${j}]="TAM"
[2]198j=$((${j} + 1))
199jlist[${j}]="SAXO"
[4]200jlist_name[${j}]="SAXO"
[2]201j=$((${j} + 1))
[4]202jlist[${j}]="offline"
203jlist_name[${j}]="Off-line"
[2]204j=$((${j} + 1))
205jlist[${j}]="AGRIF"
[4]206jlist_name[${j}]="AGRIF"
[2]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
[100]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 ))
[2]232done
233echo "</${elements}>" >> ${xmloutput}
234#
235element=platform
236elements=platforms
[31]237#++ récupérer les users/user[child::userid='template']/platforms/platform/name
[4]238unset jlist
239unset jlist_name
[2]240j=1
241jlist[${j}]="CRAY"
[4]242jlist_name[${j}]="CRAY"
[2]243j=$((${j} + 1))
244jlist[${j}]="IBM"
[4]245jlist_name[${j}]="IBM"
[2]246j=$((${j} + 1))
247jlist[${j}]="FUJITSU"
[4]248jlist_name[${j}]="FUJITSU"
[2]249j=$((${j} + 1))
250jlist[${j}]="MAC"
[4]251jlist_name[${j}]="MAC"
[2]252j=$((${j} + 1))
253jlist[${j}]="NEC"
[4]254jlist_name[${j}]="NEC"
[2]255j=$((${j} + 1))
256jlist[${j}]="SGI"
[4]257jlist_name[${j}]="SGI"
[2]258j=$((${j} + 1))
259jlist[${j}]="SUN"
[4]260jlist_name[${j}]="SUN"
[2]261j=$((${j} + 1))
[4]262jlist[${j}]='pccluster'
263jlist_name[${j}]="PC Cluster"
[2]264echo "<${elements}>" >> ${xmloutput}
265## find the element
266j=1
267jlistsize=${#jlist[@]}
268while [ ${j} -le ${jlistsize} ]
269do
[100]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 ))
[2]287done
288#
289# gestion des "others"
290j=1
291jlistsize=${#jlist[@]}
292grep_cmd="grep ${element}_zzz_other ${mailbodyfile} "
293while [ ${j} -le ${jlistsize} ]
294do
[100]295   grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile
296   j=$(( $j + 1 ))
[2]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
[4]311unset jlist_name
[2]312j=1
313jlist[${j}]="g95"
[4]314jlist_name[${j}]="g95"
[2]315j=$((${j} + 1))
316jlist[${j}]="ifort"
[4]317jlist_name[${j}]="ifort"
[2]318j=$((${j} + 1))
319jlist[${j}]="pgf"
[4]320jlist_name[${j}]="pgf"
[2]321j=$((${j} + 1))
322jlist[${j}]="sxf90"
[4]323jlist_name[${j}]="sxf90"
[2]324j=$((${j} + 1))
325jlist[${j}]="xlf"
[4]326jlist_name[${j}]="xlf"
[2]327echo "<${elements}>" >> ${xmloutput}
328## find the element
329j=1
330jlistsize=${#jlist[@]}
331while [ ${j} -le ${jlistsize} ]
332do
[100]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 ))
[2]350done
351#
352# gestion des "others"
353j=1
354jlistsize=${#jlist[@]}
355grep_cmd="grep ${element}_zzz_other= ${mailbodyfile} "
356while [ ${j} -le ${jlistsize} ]
357do
[100]358   grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile
359   j=$(( $j + 1 ))
[2]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#
[31]368echo "</user>" >> ${xmloutput}
[2]369#
370xmloutputfull=/tmp/${xmloutput} # ++
371echo '<?xml version="1.0" encoding="iso-8859-1"?>' > ${xmloutputfull}
[31]372echo '<!DOCTYPE users SYSTEM "user.dtd">' >> ${xmloutputfull}
373echo '<users>' >> ${xmloutputfull}
[2]374echo '<date>bidon</date>' >> ${xmloutputfull}
375cat ${xmloutput} >> ${xmloutputfull}
[31]376echo '</users>' >> ${xmloutputfull}
[2]377#
378# ++ parce que je ne sais pas dire où est la dtd dans la commande xmllint
[31]379cp user.dtd /tmp/
[2]380xmllint --noout --valid ${xmloutputfull} 1>> ${log} 2>> ${log}
381status=${?}
382if [ ${status} -ne 0 ]
383then
[100]384   echo " eee : pb DTD conformance of ${xmloutputfull}"
385   echo " eee : see ${log}"
386   exit 1
[2]387else
[100]388   echo " iii : you can include ${xmloutput} in user.xml" #++ filename path
389   echo " iii : modify date in user.xml" #++ filename path
[2]390fi
391#
392exit 0
Note: See TracBrowser for help on using the repository browser.