source: trunk/mailtouser.sh @ 100

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

indent shell scripts

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