source: trunk/checkmain.sh @ 164

Last change on this file since 164 was 146, checked in by pinsard, 12 years ago

xmlstarlet vs xml

  • Property svn:executable set to *
File size: 5.2 KB
Line 
1#! /bin/sh
2#
3#+
4# .. program:: checkmain.sh
5#
6# ============
7# checkmain.sh
8# ============
9#
10# SYNOPSIS
11# ========
12#
13# ::
14#
15#  $ checkmain.sh [--debug] -i filein
16#
17# DESCRIPTION
18# ===========
19#
20# .. option:: -i <filein>
21#
22# Check SUPERBIB requirements in main.xml **filein** XML/DocBook.
23#
24# project
25#   Should be defined :samp:`//d:keyword[@xml:id='project']`
26#
27#   Is used for ++
28# title
29#   Should be defined :samp:`d:article/d:title`
30#
31#   Is used for ++
32# homepage
33#   Should be defined :samp:`//d:bibliosource[@xml:id='homepage']`
34#
35#   Is used for ++
36# contact
37#   Should be defined :samp:`/d:article/d:info/d:authorgroup/d:author[1]/d:email`
38#
39#   Is used by PHP pages to send emails.
40#
41# .. warning::
42#
43#    There is now check on email and homepage.
44#    They **must** be real to avoid black holes of mails and 404 HTPP errors.
45#
46# EXAMPLES
47# ========
48#
49# To check the SUPERBIB demo main file::
50#
51#   $ ./checkmain.sh -i data/maindemo1.xml
52#   Title : superbib Demo1
53#   Project : superbib demo1
54#   HOME page : http://forge.ipsl.jussieu.fr/superbib/
55#   Contact : Francoise.Pinsard@locean-ipsl.upmc.fr
56#
57# To check the NEMO demo main file::
58#
59#   $ ./checkmain.sh -i data/mainnemo.xml
60#   Title : NEMO survey
61#   Project : NEMO
62#   HOME page : http://www.nemo-ocean.eu/
63#   Contact : opatlod@locean-ipsl.upmc.fr
64#
65# SEE ALSO
66# ========
67#
68# :ref:`using`
69#
70# :ref:`components_db.xsl`
71# :ref:`form_db.xsl`
72# :ref:`main_html.xsl`
73# :ref:`main_rest.xsl`
74# :ref:`superbib01_html.xsl`
75# :ref:`superbib01_rest.xsl`
76# :ref:`superbib01_xml.xsl`
77# :ref:`superbib02_html.xsl`
78# :ref:`superbib02_xml.xsl`
79# :ref:`superbib03_xml.xsl`
80# :ref:`superbibmany01_html.xsl`
81# :ref:`superbibmany01_xml.xsl`
82# :ref:`superbibmany02_html.xsl`
83# :ref:`superbibmany02_xml.xsl`
84# :ref:`template_db.xsl`
85# :ref:`user_db.xsl`
86# :ref:`user_html.xsl`
87# :ref:`user_rest.xsl`
88#
89# TODO
90# ====
91#
92# improve description
93#
94# XML/Docbook compliant : pb with element form: Schemas validity error : Element '{http://www.w3.org/1999/xhtml}form': This element is not expected.
95# .. so as I do not know haox to get rid of this I comment this test (see XFORM and so one)
96#
97# check for news on DocBook realase (now 20110701 5.0)
98#
99#
100# EVOLUTIONS
101# ==========
102#
103# $URL$
104#
105# $Id$
106#
107# - fplod 20120227
108#
109#   * xmlstarlet vs xml
110#
111# - fplod 20110701T113247Z cratos.locean-ipsl.upmc.fr (Linux)
112#
113#   * creation
114#
115#-
116system=$(uname)
117case "${system}" in
118   AIX|IRIX64)
119      echo "www : no specific posix checking"
120      date_cmd=date
121      xmlcmd=xml
122   ;;
123   Darwin)
124      set -o posix
125      date_cmd=gdate
126      xmlcmd=xmlstarlet
127   ;;
128   Linux)
129      set -o posix
130      date_cmd=date
131      xmlcmd=xml
132   ;;
133   *)
134     set -o posix
135   ;;
136esac
137unset system
138#
139set -u
140#
141LANG=POSIX
142#
143command=$(basename ${0})
144#
145usage=" Usage : ${command} [--debug] -i filein "
146#
147hostname=$(hostname)
148#
149# default
150debug=0
151#
152minargcount=2
153if [ ${#} -lt ${minargcount} ]
154then
155   echo "${command} : eee : not enought arguments"
156   echo "${usage}"
157   exit 1
158fi
159#
160while [ ${#} -gt 0 ]
161do
162   case ${1} in
163      --debug)
164         debug=1
165      ;;
166      -i)
167         filein=${2}
168         shift
169      ;;
170      *)
171        # anything else
172        echo "${command} : eee : unknown option ${1}"
173        echo "${command} : eee : ${usage}"
174        exit 1
175      ;;
176   esac
177   # next flag
178   shift
179done
180#
181# check parameters
182#
183# check for filein
184if [ ! -f ${filein} ]
185then
186   echo "eee : ${filein} not found"
187   exit 1
188fi
189#
190# test if xml available
191tool=${xmlcmd}
192type ${tool} 1> /dev/null 2>&1
193status=${?}
194if [ ${status} -ne 0 ]
195then
196   echo "${command} : eee : ${tool} not found"
197   exit 1
198fi
199unset status
200unset tool
201#
202#++# check XML/DocBook conformity
203#++${xmlcmd} val --err \
204#++--xsd http://www.docbook.org/xml/5.0/xsd/docbook.xsd \
205#++${filein}
206#++status=${?}
207#++if [ ${status} -ne 0 ]
208#++then
209#++   echo "${command} : eee : ${filein} is not XML/DocBook compliant"
210#++   exit 1
211#++fi
212#++unset status
213#
214# title
215xpath="d:article/d:title"
216title=$(${xmlcmd} sel -N d="http://docbook.org/ns/docbook" -t -m "${xpath}" -v . ${filein})
217if [ "${title}" = "" ]
218then
219   echo "${command} : www : title not defined"
220   echo "${command} : www : fix ${xpath}"
221   exit 1
222else
223   echo "Title : ${title}"
224fi
225unset title
226#
227#
228# project
229project_ok=0
230xpath="//d:keyword[@xml:id='project']"
231project=$(${xmlcmd} sel -N d="http://docbook.org/ns/docbook" -t -m "${xpath}" -v . ${filein})
232if [ "${project}" = "" ]
233then
234   echo "${command} : www : project not defined"
235   echo "${command} : www : fix ${xpath}"
236else
237   echo "Project : ${project}"
238   project_ok=1
239fi
240unset project
241#
242# homepage
243homepage_ok=0
244xpath="//d:bibliosource[@xml:id='homepage']"
245homepage=$(${xmlcmd} sel -N d="http://docbook.org/ns/docbook" -t -m "${xpath}" -v . ${filein})
246if [ "${homepage}" = "" ]
247then
248   echo "${command} : www : homepage not defined"
249   echo "${command} : www : fix ${xpath}"
250else
251   echo "HOME page : ${homepage}"
252   homepage_ok=1
253fi
254unset homepage
255#
256# contact
257contact_ok=0
258xpath="/d:article/d:info/d:authorgroup/d:author[1]/d:email"
259contact=$(${xmlcmd} sel -N d="http://docbook.org/ns/docbook" -t -m "${xpath}" -v . ${filein})
260if [ "${contact}" = "" ]
261then
262   echo "${command} : www : contact not defined"
263   echo "${command} : www : fix ${xpath}"
264else
265   echo "Contact : ${contact}"
266   contact_ok=1
267fi
268unset contact
269#
270unset command
271unset hostname
272unset usage
273#
274# end
275#++set
276exit 0
Note: See TracBrowser for help on using the repository browser.