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