source: trunk/mailtouser.sh @ 101

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

improve environnement definition

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