File: daps-xmlformat.in

package info (click to toggle)
daps 3.3.2%2Bcleaned1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,536 kB
  • sloc: xml: 9,773; sh: 3,059; python: 1,322; lisp: 380; makefile: 239
file content (80 lines) | stat: -rwxr-xr-x 2,712 bytes parent folder | download | duplicates (3)
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
76
77
78
79
80
#!/bin/bash
#
# Copyright (C) 2012-2020 SUSE Software Solutions Germany GmbH
#
# Author:
# Frank Sundermeyer <fsundermeyer at opensuse dot org>
#
# Used as a wrapper script, so it's not necessary to memorize
# where the config file stays

# ---------
# Verbose error handling
#
function exit_on_error {
    >&2 echo -e "ERROR: ${1}"
    exit 1;
}

# Binary filename can either be xmlformat, xmlformat.rb, or xmlformat.pl ;-((
# take the first one that exists
#
for _BINARY in xmlformat xmlformat.pl xmlformat.rb; do
    XMLFORMAT_CMD="$(which "$_BINARY" 2>/dev/null)" && break
done

_XMLF_VERSION=$($XMLFORMAT_CMD --version 2>/dev/null | head -n1 | cut -d' ' -f2)

# Whenever xmlformat encounters an unknown attribute/value pair, it will error
# out. To avoid these issues, switch out config files depending on the
# xmlformat version.

# The versionless xmlformat config file is currently a symlink to the variant
# for xmlformat 1.04. This provides backward compatibility with the behavior
# of DAPS 3.1.2 and below. If necessary, we can change that symlink in the
# future.

# Check if we're at least on xmlformat v1.9.
if [[ $(echo -e "$_XMLF_VERSION\n1.9" | sort -b --version-sort | head -n1) == '1.9' ]]; then
    _XMLF_DEFAULT_CONFIG="@sysconfdir@/daps/docbook-xmlformat-1.9.conf"
# We don't know any versions in between v1.04 and v1.9. We also don't know any
# versions older than v1.04.
else
    _XMLF_DEFAULT_CONFIG="@sysconfdir@/daps/docbook-xmlformat-1.04.conf"
fi


# Set to version-specific default if empty/@default@
[[ "$XMLFORMAT_CONFIG_FILE" == '@default@' ]] && XMLFORMAT_CONFIG_FILE="$_XMLF_DEFAULT_CONFIG"
XMLFORMAT_CONFIG_FILE=${XMLFORMAT_CONFIG_FILE:-"$_XMLF_DEFAULT_CONFIG"}

# when using a Git checkout, @sysconfdir@ has not been
# replaced
#
# ${string/#substring/replacement}
# If $substring matches front end of $string, substitute
# $replacement for $substring.



if [[ "$XMLFORMAT_CONFIG_FILE" == "@sysconfdir@"* && -z $DAPSROOT ]]; then
    _XMLF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    DAPSROOT=${_XMLF_DIR%/bin}
fi

XMLFORMAT_CONFIG_FILE=${XMLFORMAT_CONFIG_FILE/#@sysconfdir\@\/daps/${DAPSROOT}/etc}

# Also show the config file in verbose mode
#
if [[ "${@#-v}" = "$@" || "${@#--verbose}" = "$@" ]]; then
    # use STDERR, since xmlformat prints all messages to STDERR
    >&2 echo "Using config file '$XMLFORMAT_CONFIG_FILE'"
fi

#check if default is missing too
[[ -e "$XMLFORMAT_CONFIG_FILE" ]] || exit_on_error "Could not find config file '$XMLFORMAT_CONFIG_FILE'\n"

[[ -z "$XMLFORMAT_CMD" ]] && exit_on_error "The xmlformat script is missing. Please install the respective package!"

$XMLFORMAT_CMD --config-file "$XMLFORMAT_CONFIG_FILE" "$@"
exit $?