source: trunk/checkmain.sh

Last change on this file was 354, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo

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