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