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