source: trunk/mailtouser.sh @ 76

Last change on this file since 76 was 75, checked in by pinsard, 16 years ago

comments in shell scripts in ReStructured? Text

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