1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#!/bin/bash
#
# Copyright (C) 2012-2020 SUSE Software Solutions Germany GmbH
#
# Author:
# Frank Sundermeyer <fsundermeyer at opensuse dot org>
#
# Wrapper script to mend the shortcomings of xsltproc:
# * checks all catalogs from XML_CATALOG_FILES
# aborts on first successful result
# * only returns a string if URI could be resolved
#
_XMLCATALOG=/usr/bin/xmlcatalog
_ME="$(basename "$0")"
_URI=""
_CAT_PATH=""
function exit_on_error {
echo -e "ERROR: ${1}" >&2
clean_daps
exit 1;
}
function usage {
cat <<EOF_helptext
Usage: $_ME <URI>
$_ME is a wrapper for xmlcatalog. It tries to resolve <URI>
via the catalogs defined in the variable XML_CATALOG_FILES. The catalogs
are used in the order they appear in XML_CATALOG_FILES. Once the URI
is resoved, remaining catalogs are ignored.
Returs 0 and the path to the catalog upon success,
returns 1 if the <URI> could not be resolved.
EOF_helptext
}
# Check if parameter (URI) is passed to the script;
#
if [[ -z $1 ]]; then
exit_on_error "No parameter passed to $_ME"
else
case "$1" in
--help|-h|?)
usage
exit 0
;;
*)
_URI="$1"
;;
esac
fi
# check if XML_CATALOG_FILES is set
#
[[ -z $XML_CATALOG_FILES ]] && exit_on_error "XML_CATALOG_FILES is not set"
# Try to resolve URI with all catalogs from XML_CATALOG_FILES
# exit on the first successful result
#
for _CAT in $XML_CATALOG_FILES; do
_CAT_PATH=$($_XMLCATALOG "$_CAT" "$_URI")
if [[ 0 -eq $? ]]; then
break
else
_CAT_PATH=""
fi
done
if [[ -n $_CAT_PATH ]]; then
echo "$_CAT_PATH"
exit 0
else
exit 1
fi
|