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