1 | #! /bin/sh |
---|
2 | # |
---|
3 | # module : |
---|
4 | # convert email text in xml form folloowing user.dtd |
---|
5 | # |
---|
6 | # see also bibopa.sh |
---|
7 | # |
---|
8 | # example : |
---|
9 | # $ ./mailtouser.sh -m data/mail2007-05-10T09:01:56Z -x ginette.xml |
---|
10 | # |
---|
11 | # see also bibopa.sh |
---|
12 | # |
---|
13 | # update : |
---|
14 | # ++ gestion des comments |
---|
15 | # ++ gestion de la signature |
---|
16 | # $Id$ |
---|
17 | # fplod 2007-06-06T09:27:55Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
18 | # correction for Off-Line and PC Cluster |
---|
19 | # fplod 2007-05-18T08:31:48Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
20 | # add off-line and agrif components |
---|
21 | # fplod 2007-05-09T15:03:15Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
22 | # reprise + ajout middlename + ajout components_date |
---|
23 | # fplod 2007-04-25T09:15:38Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
24 | # creation |
---|
25 | # |
---|
26 | set -o posix |
---|
27 | command=$(basename ${0} .sh) |
---|
28 | log_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
---|
29 | log=/tmp/${command}.${log_date} |
---|
30 | # |
---|
31 | usage=" Usage : ${command} -m mailbodyfile -x xmloutput" |
---|
32 | # |
---|
33 | # test if xmllint is available |
---|
34 | type xmllint 1> /dev/null 2>&1 |
---|
35 | status=${?} |
---|
36 | if [ ${status} -ne 0 ] |
---|
37 | then |
---|
38 | echo " eee : xmllint not found" |
---|
39 | exit 1 |
---|
40 | fi |
---|
41 | # |
---|
42 | # check for user.dtd |
---|
43 | if [ ! -f user.dtd ] |
---|
44 | then |
---|
45 | echo "eee : user.dtd not found" |
---|
46 | exit 1 |
---|
47 | fi |
---|
48 | # |
---|
49 | while [ ! -z "${1}" ] # ++ pb bash |
---|
50 | do |
---|
51 | case ${1} in |
---|
52 | -m) # mailbodyfile |
---|
53 | mailbodyfile=${2} |
---|
54 | shift |
---|
55 | ;; |
---|
56 | -x) # xmloutput |
---|
57 | xmloutput=${2} |
---|
58 | shift |
---|
59 | ;; |
---|
60 | *) # other choice |
---|
61 | echo "${usage}" |
---|
62 | exit 1 |
---|
63 | ;; |
---|
64 | esac |
---|
65 | shift # next flag |
---|
66 | done |
---|
67 | # |
---|
68 | set -u |
---|
69 | # |
---|
70 | # check for mailbodyfile |
---|
71 | if [ ! -f ${mailbodyfile} ] |
---|
72 | then |
---|
73 | echo "eee : ${mailbodyfile} not found" |
---|
74 | exit 1 |
---|
75 | fi |
---|
76 | # |
---|
77 | # check for xmloutput |
---|
78 | #++ err si exist |
---|
79 | # |
---|
80 | echo "<user>" > ${xmloutput} |
---|
81 | echo "<!-- mailbodyfile : ${mailbodyfile} " >> ${xmloutput} |
---|
82 | cat ${mailbodyfile} >> ${xmloutput} |
---|
83 | echo "-->" >> ${xmloutput} |
---|
84 | echo "<!-- ${log_date} -->" >> ${xmloutput} |
---|
85 | author_id=$(grep "author_id=" ${mailbodyfile} | awk -F"=" '{print $2}') |
---|
86 | surname=$(grep "personal_surname=" ${mailbodyfile} | awk -F"=" '{print $2}') |
---|
87 | firstname=$(grep "personal_firstname=" ${mailbodyfile} | awk -F"=" '{print $2}') |
---|
88 | middlename=$(grep "personal_middlename=" ${mailbodyfile} | awk -F"=" '{print $2}') |
---|
89 | if [ "${author_id}" = "template" ] |
---|
90 | then |
---|
91 | author_id=$( echo ${surname} | \ |
---|
92 | tr "[:lower:]" "[:upper:]" | \ |
---|
93 | tr " " "_" | \ |
---|
94 | recode -d -f UTF-8..flat) |
---|
95 | author_id=${author_id}_$( echo ${firstname:0:1} | \ |
---|
96 | tr "[:upper:]" "[:lower:]" | \ |
---|
97 | recode -d -f UTF-8..flat) |
---|
98 | fi |
---|
99 | echo "<userid>${author_id}</userid>" >> ${xmloutput} |
---|
100 | # |
---|
101 | echo "<personname>" >> ${xmloutput} |
---|
102 | # |
---|
103 | echo "<surname>$surname</surname>" >> ${xmloutput} |
---|
104 | # |
---|
105 | echo "<firstname>$firstname</firstname>" >> ${xmloutput} |
---|
106 | echo "<othername role='mi'>$middlename</othername>" >> ${xmloutput} |
---|
107 | # |
---|
108 | echo "</personname>" >> ${xmloutput} |
---|
109 | # |
---|
110 | email=$(grep "personal_email=" ${mailbodyfile} | awk -F"=" '{print $2}') |
---|
111 | echo "<email>$email</email>" >> ${xmloutput} |
---|
112 | # |
---|
113 | elements=components |
---|
114 | element=component |
---|
115 | #++ récupérer les users/user[child::userid='template']/components/component/name |
---|
116 | unset jlist |
---|
117 | unset jlist_name |
---|
118 | j=1 |
---|
119 | jlist[${j}]="OPA" |
---|
120 | jlist_name[${j}]="OPA" |
---|
121 | j=$((${j} + 1)) |
---|
122 | jlist[${j}]="LIM" |
---|
123 | jlist_name[${j}]="LIM" |
---|
124 | j=$((${j} + 1)) |
---|
125 | jlist[${j}]="TOP" |
---|
126 | jlist_name[${j}]="TOP" |
---|
127 | j=$((${j} + 1)) |
---|
128 | jlist[${j}]="TAM" |
---|
129 | jlist_name[${j}]="TAM" |
---|
130 | j=$((${j} + 1)) |
---|
131 | jlist[${j}]="SAXO" |
---|
132 | jlist_name[${j}]="SAXO" |
---|
133 | j=$((${j} + 1)) |
---|
134 | jlist[${j}]="offline" |
---|
135 | jlist_name[${j}]="Off-line" |
---|
136 | j=$((${j} + 1)) |
---|
137 | jlist[${j}]="AGRIF" |
---|
138 | jlist_name[${j}]="AGRIF" |
---|
139 | echo "<${elements}>" >> ${xmloutput} |
---|
140 | components_date=$(grep "components_date=" ${mailbodyfile} | awk -F"=" '{print $2}') |
---|
141 | echo "<components_date>$components_date</components_date>" >> ${xmloutput} |
---|
142 | ## find the element |
---|
143 | j=1 |
---|
144 | jlistsize=${#jlist[@]} |
---|
145 | while [ ${j} -le ${jlistsize} ] |
---|
146 | do |
---|
147 | jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:]) |
---|
148 | # recherche de ${jlist[j]} |
---|
149 | grep -q "${element}_${jlist_min}" ${mailbodyfile} |
---|
150 | ok=${?} |
---|
151 | if [ ${ok} -eq 0 ] |
---|
152 | then |
---|
153 | echo "<${element} code='${jlist_min}'>" >> ${xmloutput} |
---|
154 | echo "<name>${jlist_name[j]}</name>" >> ${xmloutput} |
---|
155 | echo "<value>yes</value>" >> ${xmloutput} |
---|
156 | echo "</${element}>" >> ${xmloutput} |
---|
157 | else |
---|
158 | echo "<${element} code='${jlist_min}'>" >> ${xmloutput} |
---|
159 | echo "<name>${jlist_name[j]}</name>" >> ${xmloutput} |
---|
160 | echo "<value>no</value>" >> ${xmloutput} |
---|
161 | echo "</${element}>" >> ${xmloutput} |
---|
162 | fi |
---|
163 | j=$(( $j + 1 )) |
---|
164 | done |
---|
165 | echo "</${elements}>" >> ${xmloutput} |
---|
166 | # |
---|
167 | element=platform |
---|
168 | elements=platforms |
---|
169 | #++ récupérer les users/user[child::userid='template']/platforms/platform/name |
---|
170 | unset jlist |
---|
171 | unset jlist_name |
---|
172 | j=1 |
---|
173 | jlist[${j}]="CRAY" |
---|
174 | jlist_name[${j}]="CRAY" |
---|
175 | j=$((${j} + 1)) |
---|
176 | jlist[${j}]="IBM" |
---|
177 | jlist_name[${j}]="IBM" |
---|
178 | j=$((${j} + 1)) |
---|
179 | jlist[${j}]="FUJITSU" |
---|
180 | jlist_name[${j}]="FUJITSU" |
---|
181 | j=$((${j} + 1)) |
---|
182 | jlist[${j}]="MAC" |
---|
183 | jlist_name[${j}]="MAC" |
---|
184 | j=$((${j} + 1)) |
---|
185 | jlist[${j}]="NEC" |
---|
186 | jlist_name[${j}]="NEC" |
---|
187 | j=$((${j} + 1)) |
---|
188 | jlist[${j}]="SGI" |
---|
189 | jlist_name[${j}]="SGI" |
---|
190 | j=$((${j} + 1)) |
---|
191 | jlist[${j}]="SUN" |
---|
192 | jlist_name[${j}]="SUN" |
---|
193 | j=$((${j} + 1)) |
---|
194 | jlist[${j}]='pccluster' |
---|
195 | jlist_name[${j}]="PC Cluster" |
---|
196 | echo "<${elements}>" >> ${xmloutput} |
---|
197 | ## find the element |
---|
198 | j=1 |
---|
199 | jlistsize=${#jlist[@]} |
---|
200 | while [ ${j} -le ${jlistsize} ] |
---|
201 | do |
---|
202 | # recherche de ${jlist[j]} |
---|
203 | jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:]) |
---|
204 | grep -q "${element}_${jlist_min}" ${mailbodyfile} |
---|
205 | ok=${?} |
---|
206 | if [ ${ok} -eq 0 ] |
---|
207 | then |
---|
208 | echo "<${element} code='${jlist_min}'>" >> ${xmloutput} |
---|
209 | echo "<name>${jlist_name[j]}</name>" >> ${xmloutput} |
---|
210 | echo "<value>yes</value>" >> ${xmloutput} |
---|
211 | echo "</${element}>" >> ${xmloutput} |
---|
212 | else |
---|
213 | echo "<${element} code='${jlist_min}'>" >> ${xmloutput} |
---|
214 | echo "<name>${jlist_name[j]}</name>" >> ${xmloutput} |
---|
215 | echo "<value>no</value>" >> ${xmloutput} |
---|
216 | echo "</${element}>" >> ${xmloutput} |
---|
217 | fi |
---|
218 | j=$(( $j + 1 )) |
---|
219 | done |
---|
220 | # |
---|
221 | # gestion des "others" |
---|
222 | j=1 |
---|
223 | jlistsize=${#jlist[@]} |
---|
224 | grep_cmd="grep ${element}_zzz_other ${mailbodyfile} " |
---|
225 | while [ ${j} -le ${jlistsize} ] |
---|
226 | do |
---|
227 | grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile |
---|
228 | j=$(( $j + 1 )) |
---|
229 | done |
---|
230 | other=$(eval ${grep_cmd} | awk -F "=" '{print$2}') |
---|
231 | echo "<${element} code='zzz_other'>" >> ${xmloutput} |
---|
232 | echo "<name>Other</name>" >> ${xmloutput} |
---|
233 | echo "<value>${other}</value>" >> ${xmloutput} |
---|
234 | echo "</${element}>" >> ${xmloutput} |
---|
235 | echo "</${elements}>" >> ${xmloutput} |
---|
236 | # |
---|
237 | processors=$(grep "processors=" ${mailbodyfile} | awk -F"=" '{print $2}') |
---|
238 | echo "<processors>$processors</processors>" >> ${xmloutput} |
---|
239 | # |
---|
240 | element=compiler |
---|
241 | elements=compilers |
---|
242 | unset jlist |
---|
243 | unset jlist_name |
---|
244 | j=1 |
---|
245 | jlist[${j}]="g95" |
---|
246 | jlist_name[${j}]="g95" |
---|
247 | j=$((${j} + 1)) |
---|
248 | jlist[${j}]="ifort" |
---|
249 | jlist_name[${j}]="ifort" |
---|
250 | j=$((${j} + 1)) |
---|
251 | jlist[${j}]="pgf" |
---|
252 | jlist_name[${j}]="pgf" |
---|
253 | j=$((${j} + 1)) |
---|
254 | jlist[${j}]="sxf90" |
---|
255 | jlist_name[${j}]="sxf90" |
---|
256 | j=$((${j} + 1)) |
---|
257 | jlist[${j}]="xlf" |
---|
258 | jlist_name[${j}]="xlf" |
---|
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 | echo "</user>" >> ${xmloutput} |
---|
301 | # |
---|
302 | xmloutputfull=/tmp/${xmloutput} # ++ |
---|
303 | echo '<?xml version="1.0" encoding="iso-8859-1"?>' > ${xmloutputfull} |
---|
304 | echo '<!DOCTYPE users SYSTEM "user.dtd">' >> ${xmloutputfull} |
---|
305 | echo '<users>' >> ${xmloutputfull} |
---|
306 | echo '<date>bidon</date>' >> ${xmloutputfull} |
---|
307 | cat ${xmloutput} >> ${xmloutputfull} |
---|
308 | echo '</users>' >> ${xmloutputfull} |
---|
309 | # |
---|
310 | # ++ parce que je ne sais pas dire où est la dtd dans la commande xmllint |
---|
311 | cp user.dtd /tmp/ |
---|
312 | xmllint --noout --valid ${xmloutputfull} 1>> ${log} 2>> ${log} |
---|
313 | status=${?} |
---|
314 | if [ ${status} -ne 0 ] |
---|
315 | then |
---|
316 | echo " eee : pb DTD conformance of ${xmloutputfull}" |
---|
317 | echo " eee : see ${log}" |
---|
318 | exit 1 |
---|
319 | else |
---|
320 | echo " iii : you can include ${xmloutput} in user.xml" #++ filename path |
---|
321 | echo " iii : modify date in user.xml" #++ filename path |
---|
322 | fi |
---|
323 | # |
---|
324 | exit 0 |
---|