Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #!/bin/bash
  2. # author jiyin@redhat.com
  3. # author matteo.valentini@nethesis.it
  4.  
  5. TEMP=`getopt -o vt:u: --long target -n 'example.bash' -- "$@"`
  6. if [ $? != 0 ] ; then echo "getopt fail, terminating..." >&2 ; exit 1 ; fi
  7.  
  8. # Note the quotes around `$TEMP': they are essential!
  9. eval set -- "$TEMP"
  10.  
  11. Usage() {
  12. echo "usage: $0 [-u username:password] -t <rpcServUrl> <method> [arg1 arg2 ...]"
  13. exit 1
  14. }
  15. simpleArg() {
  16. local arg="$1"
  17. local type=${arg%%:*} val=${arg#*:}
  18. echo -e "${indent}<param><value><$type>$val</$type></value></param>"
  19. }
  20. structArg() {
  21. local arg="$1"
  22. : parse wait complete ...
  23. }
  24.  
  25. while true ; do
  26. case "$1" in
  27. -t|--target) servUrl=$2; shift 2;;
  28. -u) basic_auth=$2; shift 2;;
  29. -v) verbose=--verbose; shift;;
  30. --) shift; break;;
  31. *) echo "Internal error!"; exit 1;;
  32. esac
  33. done
  34. [ -z "$servUrl" ] && Usage
  35. [ $# -lt 1 ] && Usage
  36.  
  37. #<method> <arg1> <arg2> ... <argx>
  38. generateRequestXml() {
  39. method=$1; shift
  40. echo '<?xml version="1.0"?>'
  41. echo "<methodCall>"
  42. echo " <methodName>$method</methodName>"
  43. echo " <params>"
  44.  
  45. indent=" "
  46. for arg; do
  47. indent="${indent} "
  48. case $arg in
  49. struct:*) structArg "$arg";;
  50. *) simpleArg "$arg";;
  51. esac
  52. done
  53.  
  54. echo " </params>"
  55. echo "</methodCall>"
  56. }
  57. rpcxml=rpc$$.xml
  58. generateRequestXml "$@" > $rpcxml
  59. [ "$verbose" = "--verbose" ] && cat "$rpcxml"
  60. [ -n "$basic_auth" ] && basic_auth="--user $basic_auth"
  61. curl $basic_auth -k $verbose --data "@$rpcxml" --header "Content-Type: text/xml" "$servUrl" 2>/dev/null | xmllint --format -
  62. \rm -f $rpcxml
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement