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 | #- |
---|
128 | system=$(uname) |
---|
129 | case "${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 | ;; |
---|
148 | esac |
---|
149 | unset system |
---|
150 | # |
---|
151 | set -u |
---|
152 | # |
---|
153 | LANG=POSIX |
---|
154 | # |
---|
155 | command=$(basename ${0}) |
---|
156 | # |
---|
157 | usage=" Usage : ${command} [--debug] -i filein " |
---|
158 | # |
---|
159 | hostname=$(hostname) |
---|
160 | # |
---|
161 | # default |
---|
162 | debug=0 |
---|
163 | # |
---|
164 | minargcount=2 |
---|
165 | if [ ${#} -lt ${minargcount} ] |
---|
166 | then |
---|
167 | echo "${command} : eee : not enough arguments" |
---|
168 | echo "${usage}" |
---|
169 | exit 1 |
---|
170 | fi |
---|
171 | # |
---|
172 | while [ ${#} -gt 0 ] |
---|
173 | do |
---|
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 |
---|
191 | done |
---|
192 | # |
---|
193 | # check parameters |
---|
194 | # |
---|
195 | # check for filein |
---|
196 | if [ ! -f ${filein} ] |
---|
197 | then |
---|
198 | echo "eee : ${filein} not found" |
---|
199 | exit 1 |
---|
200 | fi |
---|
201 | # |
---|
202 | # test if xml available |
---|
203 | tool=${xmlcmd} |
---|
204 | type ${tool} 1> /dev/null 2>&1 |
---|
205 | status=${?} |
---|
206 | if [ ${status} -ne 0 ] |
---|
207 | then |
---|
208 | echo "${command} : eee : ${tool} not found" |
---|
209 | exit 1 |
---|
210 | fi |
---|
211 | unset status |
---|
212 | unset 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 |
---|
227 | xpath="d:article/d:title" |
---|
228 | title=$(${xmlcmd} sel -N d="http://docbook.org/ns/docbook" -t -m "${xpath}" -v . ${filein}) |
---|
229 | if [ "${title}" = "" ] |
---|
230 | then |
---|
231 | echo "${command} : www : title not defined" |
---|
232 | echo "${command} : www : fix ${xpath}" |
---|
233 | exit 1 |
---|
234 | else |
---|
235 | echo "Title : ${title}" |
---|
236 | fi |
---|
237 | unset title |
---|
238 | # |
---|
239 | # project |
---|
240 | project_ok=0 |
---|
241 | xpath="//d:keyword[@xml:id='project']" |
---|
242 | project=$(${xmlcmd} sel -N d="http://docbook.org/ns/docbook" -t -m "${xpath}" -v . ${filein}) |
---|
243 | if [ "${project}" = "" ] |
---|
244 | then |
---|
245 | echo "${command} : www : project not defined" |
---|
246 | echo "${command} : www : fix ${xpath}" |
---|
247 | else |
---|
248 | echo "Project : ${project}" |
---|
249 | project_ok=1 |
---|
250 | fi |
---|
251 | unset project |
---|
252 | # |
---|
253 | # homepage |
---|
254 | homepage_ok=0 |
---|
255 | xpath="//d:bibliosource[@xml:id='homepage']" |
---|
256 | homepage=$(${xmlcmd} sel -N d="http://docbook.org/ns/docbook" -t -m "${xpath}" -v . ${filein}) |
---|
257 | if [ "${homepage}" = "" ] |
---|
258 | then |
---|
259 | echo "${command} : www : homepage not defined" |
---|
260 | echo "${command} : www : fix ${xpath}" |
---|
261 | else |
---|
262 | echo "HOME page : ${homepage}" |
---|
263 | homepage_ok=1 |
---|
264 | fi |
---|
265 | unset homepage |
---|
266 | # |
---|
267 | # contact |
---|
268 | contact_ok=0 |
---|
269 | xpath="/d:article/d:info/d:authorgroup/d:author[1]/d:email" |
---|
270 | contact=$(${xmlcmd} sel -N d="http://docbook.org/ns/docbook" -t -m "${xpath}" -v . ${filein}) |
---|
271 | if [ "${contact}" = "" ] |
---|
272 | then |
---|
273 | echo "${command} : www : contact not defined" |
---|
274 | echo "${command} : www : fix ${xpath}" |
---|
275 | else |
---|
276 | echo "Contact : ${contact}" |
---|
277 | contact_ok=1 |
---|
278 | fi |
---|
279 | unset contact |
---|
280 | # |
---|
281 | unset command |
---|
282 | unset hostname |
---|
283 | unset usage |
---|
284 | # |
---|
285 | # end |
---|
286 | #++set |
---|
287 | exit 0 |
---|