From 156c318535b5537b929f4bdc6adcff60e278add2570c7ab2edd7f11f430ae625 Mon Sep 17 00:00:00 2001 From: Thomas Schraitle Date: Fri, 3 Mar 2023 13:33:26 +0000 Subject: [PATCH 1/2] Only spec file changes - Introduce check-catalog.sh script in %check section This script tests the docbook_5.xml XML catalog, extracts entries, and checks if the file exists. - Add missing "/" in catalog file "docbook_5.xml" In several rewritePrefix attributes the missing "/" leads to invalid local paths. For example: $ xmlcatalog /etc/xml/catalog https://cdn.docbook.org/schema/5.2/rng/assemblyxi.rnc file:///usr/share/xml/docbook/schema/rng/5.2assemblyxi.rnc The ".../5.2assemblyxi.rnc" part should be ".../5.2/assemblyxi.rnc". OBS-URL: https://build.opensuse.org/package/show/Publishing/docbook_5?expand=0&rev=41 --- check-catalog.sh | 175 ++++++++++++++++++++++++++++++++++++++++++++++ docbook_5.changes | 18 +++++ docbook_5.spec | 13 ++-- docbook_5.xml | 45 ++++++------ 4 files changed, 223 insertions(+), 28 deletions(-) create mode 100644 check-catalog.sh diff --git a/check-catalog.sh b/check-catalog.sh new file mode 100644 index 0000000..3ef65ea --- /dev/null +++ b/check-catalog.sh @@ -0,0 +1,175 @@ +#!/bin/bash +# +# Checks catalog URIs +# +# Dependencies: +# * xmlstarlet +# +# Copyright 2023 SUSE Linux Products GmbH +# Author: Tom Schraitle 2023 + +ME=${0##*/} +BUILDROOT="" +ERRORS=() + +function usage() +{ +cat << EOF +$ME [--buildroot=BUILDROOT] CATALOG_FILE + +Checks catalog URIs + +Options + --root Used when building a package, points + to the build root + +Arguments + CATALOG_FILE XML catalog file with catalog entries + +Return codes + 0 everything fine. Celebrate! \o/ + 10 catalog file doesn't exist + 100 some catalog error occured +EOF +} + +function resolveuri() { + local catalog="$1" + local uri="$2" + xmlcatalog "$catalog" "$uri" 2>/dev/null +} + +function xpathfromcatalog() { + local catalog="$1" + local xpath="$2" + local NS="urn:oasis:names:tc:entity:xmlns:xml:catalog" + xml sel --text -N c=$NS -t -v "$xpath" "$catalog" +} + + +# -- CLI parsing +ARGS=$(getopt -o h -l help,buildroot: -n "$ME" -- "$@") +eval set -- "$ARGS" +while true; do + case "$1" in + --help|-h) + usage + exit 0 + ;; + --buildroot) + # Ensure that path ends with "/" + BUILDROOT="${2%/}/" + shift 2 + ;; + --) shift ; break ;; + *) exit_on_error "Wrong parameter: $1" ;; + esac +done + + +CATALOG="$1" + +if [ ! -e "$CATALOG" ]; then + printf "Catalog file '$CATALOG' doesn't exist" >/dev/stderr + exit 10 +fi + + +declare -A TO_CHECK=( + #------------- + [5.0/nvdl]="docbook.nvdl" + [5.0/rng]="docbook.rnc docbook.rng docbookxi.rnc docbookxi.rng" + [5.0/sch]="docbook.sch" + [5.0/xsd]="docbook.xsd xlink.xsd xml.xsd" + #------------- + [5.1/nvdl]="docbook.nvdl" + [5.1/rng]="assembly.rnc assembly.rng dbits.rnc dbits.rng docbook.rnc docbook.rng docbookxi.rnc docbookxi.rng" + [5.1/sch]="assembly.sch dbits.sch docbook.sch docbookxi.sch" + #------------- + [5.2/nvdl]="assembly.nvdl dbits.nvdl docbook.nvdl" + [5.2/rng]="assembly.rnc assembly.rng assemblyxi.rnc assemblyxi.rng dbits.rnc dbits.rng dbitsxi.rnc dbitsxi.rng docbook.rnc docbook.rng docbookxi.rnc docbookxi.rng" + [5.2/sch]="assembly.sch assemblyxi.sch dbits.sch docbook.sch docbookxi.sch" + #------------- +) + +SYSTEMS=$(xpathfromcatalog "$CATALOG" \ + "//c:system/@systemId") + +# +for uri in $SYSTEMS; do + next=$(( "${#ERRORS[@]}" + 1 )) + result=$(resolveuri "$CATALOG" "$uri") + if [[ $? -ne 0 ]]; then + result="" + ERRORS[next]="$uri" + else + result="${BUILDROOT}${result#file://*}" + + if [[ $ret -ne 0 ]]; then + result="" + ERRORS[next]="$uri/$file" + elif [[ ! -e $result ]]; then + ERRORS[next]="$result" + fi + fi + +done + + +REWRITESYSTEMS=$(xpathfromcatalog "$CATALOG" \ + "//c:rewriteSystem/@systemIdStartString") + +for uri in $REWRITESYSTEMS; do + result=$(resolveuri "$CATALOG" "$uri") + if [[ $? -ne 0 ]]; then + result="" + next=$(( ${#ERRORS[@]} + 1 )) + ERRORS[next]="$uri" + fi + # Check if we have after the release a format + if [[ $uri =~ ((5\.[0-9])/([^/]+))(/)? ]]; then + # If we have a match, we have: + # ${BASH_REMATCH[0]} => the complete match + # ${BASH_REMATCH[1]} => DocBook version + Format, e.g "5.0/rng" + # ${BASH_REMATCH[2]} => DocBook version only + # ${BASH_REMATCH[3]} => Format only + DBFORMAT=${BASH_REMATCH[1]} + FORMAT=${BASH_REMATCH[3]} + FILES="${TO_CHECK[$DBFORMAT]}" + + # Remove "/" at end, if needed: + uri="${uri%/}" + # echo "To check $DBFORMAT: $FILES" + for file in $FILES; do + echo -en "Checking $uri/$file... =>" + next=$(( "$len" + 1 )) + result=$(resolveuri "$CATALOG" "${uri}/$file") + ret=$? + result="${BUILDROOT}${result#file://*}" + # We check the return value and _not_ the result string + if [[ $ret -ne 0 ]]; then + result="" + ERRORS[next]="$uri/$file" + echo -en " not resolvable\n" + elif [[ ! -e $result ]]; then + ERRORS[next]="$result" + echo -en " doesn't exist\n" + else + echo -en " ok\n" + fi + done + fi +done + +echo "-----------------------------" +# make them unique: +ERRORS=($(for err in "${ERRORS[@]}"; do echo "${err}"; done | sort -u)) +echo "Found ${#ERRORS[@]} errors". + +if [ ${#ERRORS[@]} -ne 0 ]; then + for elem in "${!ERRORS[@]}"; do + echo "${elem}: ${ERRORS[${elem}]}" + done + exit 100 +fi +exit 0 \ No newline at end of file diff --git a/docbook_5.changes b/docbook_5.changes index ca37647..8e52d21 100644 --- a/docbook_5.changes +++ b/docbook_5.changes @@ -1,3 +1,21 @@ +------------------------------------------------------------------- +Fri Mar 3 06:54:34 UTC 2023 - Thomas Schraitle - 5.2CR5 + +Only spec file changes + +- Introduce check-catalog.sh script in %check section + This script tests the docbook_5.xml XML catalog, extracts entries, and checks + if the file exists. + +- Add missing "/" in catalog file "docbook_5.xml" + In several rewritePrefix attributes the missing "/" leads to invalid local paths. + For example: + + $ xmlcatalog /etc/xml/catalog https://cdn.docbook.org/schema/5.2/rng/assemblyxi.rnc + file:///usr/share/xml/docbook/schema/rng/5.2assemblyxi.rnc + + The ".../5.2assemblyxi.rnc" part should be ".../5.2/assemblyxi.rnc". + ------------------------------------------------------------------- Thu Feb 9 12:39:46 UTC 2023 - Thomas Schraitle - 5.2CR5 diff --git a/docbook_5.spec b/docbook_5.spec index c1e8e9d..af009d4 100644 --- a/docbook_5.spec +++ b/docbook_5.spec @@ -33,6 +33,9 @@ Source2: %{name}-README.SUSE Source3: docbook-5.0-docs.tar.bz2 Source4: docbook-5.1-docs.tar.bz2 Source6: Makefile +# For testing +Source10: check-catalog.sh + # DB 5.0 Source500: docbook-5.0.tar.bz2 # DB 5.1 @@ -46,6 +49,7 @@ BuildRequires: fdupes BuildRequires: libxml2-tools BuildRequires: sgml-skel BuildRequires: unzip +BuildRequires: xmlstarlet Requires: sgml-skel >= 0.7 Requires(post): sgml-skel >= 0.7 Requires(postun):sgml-skel >= 0.7 @@ -119,12 +123,9 @@ update-xml-catalog %check %define catalog %{buildroot}%{xml_sysconf_dir}/catalog.d/docbook_5.xml -if [ -e %{catalog} ]; then - xmlcatalog %{catalog} http://www.oasis-open.org/docbook/xml/5.2/rng/docbook.rnc - exit 0 -else - exit 10 -fi +cp -p %{SOURCE10} . + +./check-catalog.sh --buildroot %{buildroot} "%{catalog}" %files %config %{xml_sysconf_dir}/catalog.d/docbook_5.xml diff --git a/docbook_5.xml b/docbook_5.xml index 1c1eadb..79f3fbf 100644 --- a/docbook_5.xml +++ b/docbook_5.xml @@ -1,16 +1,17 @@ - +--> - + - + @@ -18,16 +19,16 @@ - - + + - - + + @@ -36,13 +37,13 @@ - + - + - + - + @@ -66,13 +67,13 @@ - + - + - + - + @@ -95,13 +96,13 @@ - + - + - + - + @@ -122,13 +123,13 @@ - + - + - + From 970a1e54a1bc1b0b8a5aec24df35c415d2d9111748fab098926c24854132aa5e Mon Sep 17 00:00:00 2001 From: Thomas Schraitle Date: Fri, 3 Mar 2023 13:36:34 +0000 Subject: [PATCH 2/2] Set x-bit on check-catalog.sh OBS-URL: https://build.opensuse.org/package/show/Publishing/docbook_5?expand=0&rev=42 --- docbook_5.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/docbook_5.spec b/docbook_5.spec index af009d4..1655b14 100644 --- a/docbook_5.spec +++ b/docbook_5.spec @@ -124,6 +124,7 @@ update-xml-catalog %check %define catalog %{buildroot}%{xml_sysconf_dir}/catalog.d/docbook_5.xml cp -p %{SOURCE10} . +chmod +x check-catalog.sh ./check-catalog.sh --buildroot %{buildroot} "%{catalog}"