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