2009-04-19 23:10:45 +08:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
2019-01-25 17:50:27 +08:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-19 23:10:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2019-05-21 16:33:05 +08:00
|
|
|
TMPFILE=
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
if [ -n "$TMPFILE" ]; then
|
|
|
|
rm -f "$TMPFILE"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
case "$1" in
|
2013-08-20 06:26:41 +08:00
|
|
|
-h | --h | --he | --hel | --help)
|
|
|
|
cat <<EOF
|
|
|
|
Usage:
|
|
|
|
$0 XML-FILE [SCHEMA-NAME]
|
|
|
|
$0 OPTION
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-h | --help Display program help
|
|
|
|
-V | --version Display program version
|
|
|
|
EOF
|
|
|
|
exit ;;
|
|
|
|
-V | --v | --ve | --ver | --vers | --versi | --versio | --version)
|
|
|
|
cat <<EOF
|
|
|
|
$0 (libvirt) @VERSION@
|
|
|
|
EOF
|
|
|
|
exit ;;
|
|
|
|
--) shift ;;
|
2019-05-21 16:33:05 +08:00
|
|
|
-?*)
|
2013-08-20 06:26:41 +08:00
|
|
|
echo "$0: unrecognized option '$1'" >&2
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
|
2011-02-21 04:29:26 +08:00
|
|
|
XMLFILE="$1"
|
|
|
|
TYPE="$2"
|
2009-04-19 23:10:45 +08:00
|
|
|
|
2019-05-21 16:33:05 +08:00
|
|
|
if [ "$XMLFILE" = "-" ]; then
|
|
|
|
TMPFILE=`mktemp --tmpdir virt-xml.XXXX`
|
|
|
|
cat > "$TMPFILE"
|
|
|
|
else
|
|
|
|
if [ -z "$XMLFILE" ]; then
|
|
|
|
echo "syntax: $0 XMLFILE [TYPE]" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2009-04-19 23:10:45 +08:00
|
|
|
|
2019-05-21 16:33:05 +08:00
|
|
|
if [ ! -f "$XMLFILE" ]; then
|
|
|
|
echo "$0: document $XMLFILE does not exist" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
2009-04-19 23:10:45 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$TYPE" ]; then
|
2019-05-21 16:33:05 +08:00
|
|
|
if [ -n "$TMPFILE" ]; then
|
|
|
|
ROOT=`xmllint --stream --debug - < "$TMPFILE" 2>/dev/null | grep "^0 1 " | awk '{ print $3 }'`
|
|
|
|
else
|
|
|
|
ROOT=`xmllint --stream --debug "$XMLFILE" 2>/dev/null | grep "^0 1 " | awk '{ print $3 }'`
|
|
|
|
fi
|
2011-02-21 04:29:26 +08:00
|
|
|
case "$ROOT" in
|
2022-05-11 14:18:32 +08:00
|
|
|
*cpu*)
|
|
|
|
TYPE="cpu"
|
|
|
|
;;
|
2013-08-20 06:32:31 +08:00
|
|
|
*domainsnapshot*) # Must come first, since *domain* is a substring
|
|
|
|
TYPE="domainsnapshot"
|
|
|
|
;;
|
2022-05-11 14:18:32 +08:00
|
|
|
*domaincheckpoint*)
|
|
|
|
TYPE="domaincheckpoint"
|
|
|
|
;;
|
|
|
|
*domainbackup*)
|
|
|
|
TYPE="domainbackup"
|
|
|
|
;;
|
2022-07-06 10:02:52 +08:00
|
|
|
*domainCap*)
|
2022-05-11 14:18:32 +08:00
|
|
|
TYPE="domaincaps"
|
|
|
|
;;
|
2009-04-19 23:10:45 +08:00
|
|
|
*domain*)
|
|
|
|
TYPE="domain"
|
|
|
|
;;
|
2019-09-12 21:12:02 +08:00
|
|
|
*networkport*)
|
|
|
|
TYPE="networkport"
|
|
|
|
;;
|
2009-04-19 23:10:45 +08:00
|
|
|
*network*)
|
|
|
|
TYPE="network"
|
|
|
|
;;
|
2022-07-06 10:02:52 +08:00
|
|
|
*storagepoolCap*)
|
2022-05-11 14:18:32 +08:00
|
|
|
TYPE="storagepoolcaps"
|
|
|
|
;;
|
2009-04-19 23:10:45 +08:00
|
|
|
*pool*)
|
|
|
|
TYPE="storagepool"
|
|
|
|
;;
|
|
|
|
*volume*)
|
|
|
|
TYPE="storagevol"
|
|
|
|
;;
|
|
|
|
*capabilities*)
|
|
|
|
TYPE="capability"
|
|
|
|
;;
|
|
|
|
*device*)
|
|
|
|
TYPE="nodedev"
|
|
|
|
;;
|
2018-07-13 09:39:29 +08:00
|
|
|
*filterbinding*)
|
|
|
|
TYPE="nwfilterbinding"
|
|
|
|
;;
|
2013-08-20 06:32:31 +08:00
|
|
|
*filter*)
|
|
|
|
TYPE="nwfilter"
|
|
|
|
;;
|
|
|
|
*secret*)
|
|
|
|
TYPE="secret"
|
|
|
|
;;
|
2013-09-11 11:47:14 +08:00
|
|
|
*interface*)
|
|
|
|
TYPE="interface"
|
|
|
|
;;
|
2009-04-19 23:10:45 +08:00
|
|
|
*)
|
2013-08-20 06:26:41 +08:00
|
|
|
echo "$0: cannot determine schema type for $XMLFILE" >&2
|
2009-04-19 23:10:45 +08:00
|
|
|
exit 3
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
build: use common .in replacement mechanism
We had several different styles of .in conversion in our Makefiles:
ALLCAPS, @ALLCAPS@, @lower@, ::lower::
Canonicalize on one form, to make it easier to copy and paste
between .in files.
Also, we were using some non-portable sed constructs: \@ is an
undefined escape sequence (it happens to be @ itself in GNU sed,
but POSIX allows it to mean something else), as well as risky
behavior (failure to consistently quote things means a space
in $(sysconfdir) could throw things off; also, Autoconf recommends
using | rather than , or ! in the s||| operator, because | has to
be quoted in shell and is therefore less likely to appear in file
names than , or !).
Fix all of these uses to follow the same syntax.
* daemon/libvirtd.8.in: Switch to @var@.
* tools/virt-xml-validate.in: Likewise.
* tools/virt-pki-validate.in: Likewise.
* src/locking/virtlockd.init.in: Likewise.
* daemon/Makefile.am: Prefer | over ! in sed.
(libvirtd.8): Prefer consistent substitution.
(libvirtd.init, libvirtd.service): Avoid non-portable sed.
* tools/Makefile.am (libvirt-guests.sh, libvirt-guests.init)
(libvirt-guests.service): Likewise.
(virt-xml-validate, virt-pki-validate, virt-sanlock-cleanup):
Prefer consistent capitalization.
* src/Makefile.am (virtlockd.init, virtlockd.service)
(virtlockd.socket): Prefer consistent substitution.
2013-01-05 04:35:04 +08:00
|
|
|
SCHEMA="@schemadir@/${TYPE}.rng"
|
2009-04-19 23:10:45 +08:00
|
|
|
|
|
|
|
if [ ! -f "$SCHEMA" ]; then
|
2013-08-20 06:26:41 +08:00
|
|
|
echo "$0: schema $SCHEMA does not exist" >&2
|
2009-04-19 23:10:45 +08:00
|
|
|
exit 4
|
|
|
|
fi
|
|
|
|
|
2019-05-21 16:33:05 +08:00
|
|
|
if [ -n "$TMPFILE" ]; then
|
|
|
|
xmllint --noout --relaxng "$SCHEMA" - < "$TMPFILE"
|
|
|
|
else
|
|
|
|
xmllint --noout --relaxng "$SCHEMA" "$XMLFILE"
|
|
|
|
fi
|
2013-08-20 06:26:41 +08:00
|
|
|
exit
|