You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

132 lines
2.8 KiB

  1. #!/bin/sh
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. set -e
  16. TMPFILE=
  17. cleanup() {
  18. if [ -n "$TMPFILE" ]; then
  19. rm -f "$TMPFILE"
  20. fi
  21. }
  22. trap cleanup EXIT
  23. case "$1" in
  24. -h | --h | --he | --hel | --help)
  25. cat <<EOF
  26. Usage:
  27. $0 XML-FILE [SCHEMA-NAME]
  28. $0 OPTION
  29. Options:
  30. -h | --help Display program help
  31. -V | --version Display program version
  32. EOF
  33. exit ;;
  34. -V | --v | --ve | --ver | --vers | --versi | --versio | --version)
  35. cat <<EOF
  36. $0 (libvirt) @VERSION@
  37. EOF
  38. exit ;;
  39. --) shift ;;
  40. -?*)
  41. echo "$0: unrecognized option '$1'" >&2
  42. exit 1 ;;
  43. esac
  44. XMLFILE="$1"
  45. TYPE="$2"
  46. if [ "$XMLFILE" = "-" ]; then
  47. TMPFILE=`mktemp --tmpdir virt-xml.XXXX`
  48. cat > "$TMPFILE"
  49. else
  50. if [ -z "$XMLFILE" ]; then
  51. echo "syntax: $0 XMLFILE [TYPE]" >&2
  52. exit 1
  53. fi
  54. if [ ! -f "$XMLFILE" ]; then
  55. echo "$0: document $XMLFILE does not exist" >&2
  56. exit 2
  57. fi
  58. fi
  59. if [ -z "$TYPE" ]; then
  60. if [ -n "$TMPFILE" ]; then
  61. ROOT=`xmllint --stream --debug - < "$TMPFILE" 2>/dev/null | grep "^0 1 " | awk '{ print $3 }'`
  62. else
  63. ROOT=`xmllint --stream --debug "$XMLFILE" 2>/dev/null | grep "^0 1 " | awk '{ print $3 }'`
  64. fi
  65. case "$ROOT" in
  66. *domainsnapshot*) # Must come first, since *domain* is a substring
  67. TYPE="domainsnapshot"
  68. ;;
  69. *domain*)
  70. TYPE="domain"
  71. ;;
  72. *networkport*)
  73. TYPE="networkport"
  74. ;;
  75. *network*)
  76. TYPE="network"
  77. ;;
  78. *pool*)
  79. TYPE="storagepool"
  80. ;;
  81. *volume*)
  82. TYPE="storagevol"
  83. ;;
  84. *capabilities*)
  85. TYPE="capability"
  86. ;;
  87. *device*)
  88. TYPE="nodedev"
  89. ;;
  90. *filterbinding*)
  91. TYPE="nwfilterbinding"
  92. ;;
  93. *filter*)
  94. TYPE="nwfilter"
  95. ;;
  96. *secret*)
  97. TYPE="secret"
  98. ;;
  99. *interface*)
  100. TYPE="interface"
  101. ;;
  102. *)
  103. echo "$0: cannot determine schema type for $XMLFILE" >&2
  104. exit 3
  105. esac
  106. fi
  107. SCHEMA="@schemadir@/${TYPE}.rng"
  108. if [ ! -f "$SCHEMA" ]; then
  109. echo "$0: schema $SCHEMA does not exist" >&2
  110. exit 4
  111. fi
  112. if [ -n "$TMPFILE" ]; then
  113. xmllint --noout --relaxng "$SCHEMA" - < "$TMPFILE"
  114. else
  115. xmllint --noout --relaxng "$SCHEMA" "$XMLFILE"
  116. fi
  117. exit