[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 |
---|
| 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 usernemo.dtd |
---|
| 43 | if [ ! -f usernemo.dtd ] |
---|
| 44 | then |
---|
| 45 | echo "eee : usernemo.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 "<usernemo>" > ${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 usersnemo/usernemo[child::userid='template']/components/component/name |
---|
| 116 | j=1 |
---|
| 117 | jlist[${j}]="OPA" |
---|
| 118 | j=$((${j} + 1)) |
---|
| 119 | jlist[${j}]="LIM" |
---|
| 120 | j=$((${j} + 1)) |
---|
| 121 | jlist[${j}]="TOP" |
---|
| 122 | j=$((${j} + 1)) |
---|
| 123 | jlist[${j}]="TAM" |
---|
| 124 | j=$((${j} + 1)) |
---|
| 125 | jlist[${j}]="SAXO" |
---|
| 126 | j=$((${j} + 1)) |
---|
| 127 | jlist[${j}]="OFF-LINE" |
---|
| 128 | j=$((${j} + 1)) |
---|
| 129 | jlist[${j}]="AGRIF" |
---|
| 130 | echo "<${elements}>" >> ${xmloutput} |
---|
| 131 | components_date=$(grep "components_date=" ${mailbodyfile} | awk -F"=" '{print $2}') |
---|
| 132 | echo "<components_date>$components_date</components_date>" >> ${xmloutput} |
---|
| 133 | ## find the element |
---|
| 134 | j=1 |
---|
| 135 | jlistsize=${#jlist[@]} |
---|
| 136 | while [ ${j} -le ${jlistsize} ] |
---|
| 137 | do |
---|
| 138 | jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:]) |
---|
| 139 | # recherche de ${jlist[j]} |
---|
| 140 | grep -q "${element}_${jlist_min}" ${mailbodyfile} |
---|
| 141 | ok=${?} |
---|
| 142 | if [ ${ok} -eq 0 ] |
---|
| 143 | then |
---|
| 144 | echo "<${element} code='${jlist_min}'>" >> ${xmloutput} |
---|
| 145 | echo "<name>${jlist[j]}</name>" >> ${xmloutput} |
---|
| 146 | echo "<value>yes</value>" >> ${xmloutput} |
---|
| 147 | echo "</${element}>" >> ${xmloutput} |
---|
| 148 | else |
---|
| 149 | echo "<${element} code='${jlist_min}'>" >> ${xmloutput} |
---|
| 150 | echo "<name>${jlist[j]}</name>" >> ${xmloutput} |
---|
| 151 | echo "<value>no</value>" >> ${xmloutput} |
---|
| 152 | echo "</${element}>" >> ${xmloutput} |
---|
| 153 | fi |
---|
| 154 | j=$(( $j + 1 )) |
---|
| 155 | done |
---|
| 156 | echo "</${elements}>" >> ${xmloutput} |
---|
| 157 | # |
---|
| 158 | element=platform |
---|
| 159 | elements=platforms |
---|
| 160 | #++ récupérer les usersnemo/usernemo[child::userid='template']/platforms/platform/name |
---|
| 161 | j=1 |
---|
| 162 | jlist[${j}]="CRAY" |
---|
| 163 | j=$((${j} + 1)) |
---|
| 164 | jlist[${j}]="IBM" |
---|
| 165 | j=$((${j} + 1)) |
---|
| 166 | jlist[${j}]="FUJITSU" |
---|
| 167 | j=$((${j} + 1)) |
---|
| 168 | jlist[${j}]="MAC" |
---|
| 169 | j=$((${j} + 1)) |
---|
| 170 | jlist[${j}]="NEC" |
---|
| 171 | j=$((${j} + 1)) |
---|
| 172 | jlist[${j}]="SGI" |
---|
| 173 | j=$((${j} + 1)) |
---|
| 174 | jlist[${j}]="SUN" |
---|
| 175 | j=$((${j} + 1)) |
---|
| 176 | jlist[${j}]='PC Cluster' |
---|
| 177 | echo "<${elements}>" >> ${xmloutput} |
---|
| 178 | ## find the element |
---|
| 179 | j=1 |
---|
| 180 | jlistsize=${#jlist[@]} |
---|
| 181 | while [ ${j} -le ${jlistsize} ] |
---|
| 182 | do |
---|
| 183 | # recherche de ${jlist[j]} |
---|
| 184 | jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:]) |
---|
| 185 | grep -q "${element}_${jlist_min}" ${mailbodyfile} |
---|
| 186 | ok=${?} |
---|
| 187 | if [ ${ok} -eq 0 ] |
---|
| 188 | then |
---|
| 189 | echo "<${element} code='${jlist_min}'>" >> ${xmloutput} |
---|
| 190 | echo "<name>${jlist[j]}</name>" >> ${xmloutput} |
---|
| 191 | echo "<value>yes</value>" >> ${xmloutput} |
---|
| 192 | echo "</${element}>" >> ${xmloutput} |
---|
| 193 | else |
---|
| 194 | echo "<${element} code='${jlist_min}'>" >> ${xmloutput} |
---|
| 195 | echo "<name>${jlist[j]}</name>" >> ${xmloutput} |
---|
| 196 | echo "<value>no</value>" >> ${xmloutput} |
---|
| 197 | echo "</${element}>" >> ${xmloutput} |
---|
| 198 | fi |
---|
| 199 | j=$(( $j + 1 )) |
---|
| 200 | done |
---|
| 201 | # |
---|
| 202 | # gestion des "others" |
---|
| 203 | j=1 |
---|
| 204 | jlistsize=${#jlist[@]} |
---|
| 205 | grep_cmd="grep ${element}_zzz_other ${mailbodyfile} " |
---|
| 206 | while [ ${j} -le ${jlistsize} ] |
---|
| 207 | do |
---|
| 208 | grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile |
---|
| 209 | j=$(( $j + 1 )) |
---|
| 210 | done |
---|
| 211 | other=$(eval ${grep_cmd} | awk -F "=" '{print$2}') |
---|
| 212 | echo "<${element} code='zzz_other'>" >> ${xmloutput} |
---|
| 213 | echo "<name>Other</name>" >> ${xmloutput} |
---|
| 214 | echo "<value>${other}</value>" >> ${xmloutput} |
---|
| 215 | echo "</${element}>" >> ${xmloutput} |
---|
| 216 | echo "</${elements}>" >> ${xmloutput} |
---|
| 217 | # |
---|
| 218 | processors=$(grep "processors=" ${mailbodyfile} | awk -F"=" '{print $2}') |
---|
| 219 | echo "<processors>$processors</processors>" >> ${xmloutput} |
---|
| 220 | # |
---|
| 221 | element=compiler |
---|
| 222 | elements=compilers |
---|
| 223 | unset jlist |
---|
| 224 | j=1 |
---|
| 225 | jlist[${j}]="g95" |
---|
| 226 | j=$((${j} + 1)) |
---|
| 227 | jlist[${j}]="ifort" |
---|
| 228 | j=$((${j} + 1)) |
---|
| 229 | jlist[${j}]="pgf" |
---|
| 230 | j=$((${j} + 1)) |
---|
| 231 | jlist[${j}]="sxf90" |
---|
| 232 | j=$((${j} + 1)) |
---|
| 233 | jlist[${j}]="xlf" |
---|
| 234 | echo "<${elements}>" >> ${xmloutput} |
---|
| 235 | ## find the element |
---|
| 236 | j=1 |
---|
| 237 | jlistsize=${#jlist[@]} |
---|
| 238 | while [ ${j} -le ${jlistsize} ] |
---|
| 239 | do |
---|
| 240 | # recherche de ${jlist[j]} |
---|
| 241 | jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:]) |
---|
| 242 | grep -q "${element}_${jlist_min}" ${mailbodyfile} |
---|
| 243 | ok=${?} |
---|
| 244 | if [ ${ok} -eq 0 ] |
---|
| 245 | then |
---|
| 246 | echo "<${element} code='${jlist_min}'>" >> ${xmloutput} |
---|
| 247 | echo "<name>${jlist[j]}</name>" >> ${xmloutput} |
---|
| 248 | echo "<value>yes</value>" >> ${xmloutput} |
---|
| 249 | echo "</${element}>" >> ${xmloutput} |
---|
| 250 | else |
---|
| 251 | echo "<${element} code='${jlist_min}'>" >> ${xmloutput} |
---|
| 252 | echo "<name>${jlist[j]}</name>" >> ${xmloutput} |
---|
| 253 | echo "<value>no</value>" >> ${xmloutput} |
---|
| 254 | echo "</${element}>" >> ${xmloutput} |
---|
| 255 | fi |
---|
| 256 | j=$(( $j + 1 )) |
---|
| 257 | done |
---|
| 258 | # |
---|
| 259 | # gestion des "others" |
---|
| 260 | j=1 |
---|
| 261 | jlistsize=${#jlist[@]} |
---|
| 262 | grep_cmd="grep ${element}_zzz_other= ${mailbodyfile} " |
---|
| 263 | while [ ${j} -le ${jlistsize} ] |
---|
| 264 | do |
---|
| 265 | grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile |
---|
| 266 | j=$(( $j + 1 )) |
---|
| 267 | done |
---|
| 268 | other=$(eval ${grep_cmd} | awk -F "=" '{print$2}') |
---|
| 269 | echo "<${element} code='zzz_other'>" >> ${xmloutput} |
---|
| 270 | echo "<name>Other</name>" >> ${xmloutput} |
---|
| 271 | echo "<value>${other}</value>" >> ${xmloutput} |
---|
| 272 | echo "</${element}>" >> ${xmloutput} |
---|
| 273 | echo "</${elements}>" >> ${xmloutput} |
---|
| 274 | # |
---|
| 275 | echo "</usernemo>" >> ${xmloutput} |
---|
| 276 | # |
---|
| 277 | xmloutputfull=/tmp/${xmloutput} # ++ |
---|
| 278 | echo '<?xml version="1.0" encoding="iso-8859-1"?>' > ${xmloutputfull} |
---|
| 279 | echo '<!DOCTYPE usersnemo SYSTEM "usernemo.dtd">' >> ${xmloutputfull} |
---|
| 280 | echo '<usersnemo>' >> ${xmloutputfull} |
---|
| 281 | echo '<date>bidon</date>' >> ${xmloutputfull} |
---|
| 282 | cat ${xmloutput} >> ${xmloutputfull} |
---|
| 283 | echo '</usersnemo>' >> ${xmloutputfull} |
---|
| 284 | # |
---|
| 285 | # ++ parce que je ne sais pas dire où est la dtd dans la commande xmllint |
---|
| 286 | cp usernemo.dtd /tmp/ |
---|
| 287 | xmllint --noout --valid ${xmloutputfull} 1>> ${log} 2>> ${log} |
---|
| 288 | status=${?} |
---|
| 289 | if [ ${status} -ne 0 ] |
---|
| 290 | then |
---|
| 291 | echo " eee : pb DTD conformance of ${xmloutputfull}" |
---|
| 292 | echo " eee : see ${log}" |
---|
| 293 | exit 1 |
---|
| 294 | else |
---|
| 295 | echo " iii : you can include ${xmloutput} in usernemo.xml" #++ filename path |
---|
| 296 | echo " iii : modify date in usernemo.xml" #++ filename path |
---|
| 297 | fi |
---|
| 298 | # |
---|
| 299 | exit 0 |
---|