Debian Codegraph @

bin/daps-xmlformat

raw
1 #!/bin/bash
2 #
3 # Copyright (C) 2012-2020 SUSE Software Solutions Germany GmbH
4 #
5 # Author:
6 # Frank Sundermeyer <fsundermeyer at opensuse dot org>
7 #
8 # Used as a wrapper script, so it's not necessary to memorize
9 # where the config file stays
10
11 # ---------
12 # Verbose error handling
13 #
14 function exit_on_error {
15 >&2 echo -e "ERROR: ${1}"
16 exit 1;
17 }
18
19 # Binary filename can either be xmlformat, xmlformat.rb, or xmlformat.pl ;-((
20 # take the first one that exists
21 #
22 for _BINARY in xmlformat xmlformat.pl xmlformat.rb; do
23 XMLFORMAT_CMD="$(which "$_BINARY" 2>/dev/null)" && break
24 done
25
26 _XMLF_VERSION=$($XMLFORMAT_CMD --version 2>/dev/null | head -n1 | cut -d' ' -f2)
27
28 # Whenever xmlformat encounters an unknown attribute/value pair, it will error
29 # out. To avoid these issues, switch out config files depending on the
30 # xmlformat version.
31
32 # The versionless xmlformat config file is currently a symlink to the variant
33 # for xmlformat 1.04. This provides backward compatibility with the behavior
34 # of DAPS 3.1.2 and below. If necessary, we can change that symlink in the
35 # future.
36
37 # Check if we're at least on xmlformat v1.9.
38 if [[ $(echo -e "$_XMLF_VERSION\n1.9" | sort -b --version-sort | head -n1) == '1.9' ]]; then
39 _XMLF_DEFAULT_CONFIG="@sysconfdir@/daps/docbook-xmlformat-1.9.conf"
40 # We don't know any versions in between v1.04 and v1.9. We also don't know any
41 # versions older than v1.04.
42 else
43 _XMLF_DEFAULT_CONFIG="@sysconfdir@/daps/docbook-xmlformat-1.04.conf"
44 fi
45
46
47 # Set to version-specific default if empty/@default@
48 [[ "$XMLFORMAT_CONFIG_FILE" == '@default@' ]] && XMLFORMAT_CONFIG_FILE="$_XMLF_DEFAULT_CONFIG"
49 XMLFORMAT_CONFIG_FILE=${XMLFORMAT_CONFIG_FILE:-"$_XMLF_DEFAULT_CONFIG"}
50
51 # when using a Git checkout, @sysconfdir@ has not been
52 # replaced
53 #
54 # ${string/#substring/replacement}
55 # If $substring matches front end of $string, substitute
56 # $replacement for $substring.
57
58
59
60 if [[ "$XMLFORMAT_CONFIG_FILE" == "@sysconfdir@"* && -z $DAPSROOT ]]; then
61 _XMLF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
62 DAPSROOT=${_XMLF_DIR%/bin}
63 fi
64
65 XMLFORMAT_CONFIG_FILE=${XMLFORMAT_CONFIG_FILE/#@sysconfdir\@\/daps/${DAPSROOT}/etc}
66
67 # Also show the config file in verbose mode
68 #
69 if [[ "${@#-v}" = "$@" || "${@#--verbose}" = "$@" ]]; then
70 # use STDERR, since xmlformat prints all messages to STDERR
71 >&2 echo "Using config file '$XMLFORMAT_CONFIG_FILE'"
72 fi
73
74 #check if default is missing too
75 [[ -e "$XMLFORMAT_CONFIG_FILE" ]] || exit_on_error "Could not find config file '$XMLFORMAT_CONFIG_FILE'\n"
76
77 [[ -z "$XMLFORMAT_CMD" ]] && exit_on_error "The xmlformat script is missing. Please install the respective package!"
78
79 $XMLFORMAT_CMD --config-file "$XMLFORMAT_CONFIG_FILE" "$@"
80 exit $?