Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. id=`date +%s`-$$
  4.  
  5. echo "Cmd: $0 $@" >>/tmp/log-$id
  6. # redirect stderr to file, but still have ability to send something to the
  7. # "real" stderr
  8. exec 3>&2
  9. exec 2>/tmp/log-$id-stderr
  10.  
  11. firstarg=""
  12. while true; do
  13. if [ "$1" = "-V" ]; then
  14. exit 0
  15. elif [ "$1" = "-o" ]; then
  16. shift
  17. elif [[ "x$1" = "x-"* ]]; then
  18. true # simply ignore
  19. elif [ -z "$firstarg" ]; then
  20. firstarg="$1"
  21. else
  22. break
  23. fi
  24. shift
  25. done
  26. echo "Cmd2: $@" >>/tmp/log-$id
  27.  
  28. if [[ "$0" = *"scp" ]]; then
  29. src="$firstarg"
  30. dst_host="${1%:*}"
  31. dst="${1#*:}"
  32. if ! [ -r "$src" ]; then
  33. echo "File not found: $src" >&2
  34. exit 1
  35. fi
  36. tmpname=`mktemp`
  37. cp "$src" "$tmpname"
  38. qvm-copy-to-vm $dst_host $tmpname || exit 1
  39. echo "mv \"/home/user/QubesIncoming/`hostname`/`basename $tmpname`\" \"$dst\"" | qrexec-client-vm $dst_host qubes.VMShell >/dev/null
  40. elif [[ "$0" = *ssh ]]; then
  41. dst_host="$firstarg"
  42. tee /tmp/log-$id-in | qrexec-client-vm "$dst_host" qubes.VMShell >/tmp/log-$id-out
  43. ecode=$?
  44. # decode executed command (generated by caller)
  45. cat /tmp/log-$id-in | sed -z 's/.*"""\(.*\)""".*/\1/'|base64 -d > /tmp/log-$id-shim
  46. delim=$(grep ^OPTIONS.delimiter /tmp/log-$id-shim|cut -f2 -d "'")
  47. salt_args=$(grep ^ARGS /tmp/log-$id-shim|tail -1|cut -f2 -d "'")
  48. echo "$delim"
  49. if [ "$ecode" -eq 11 ]; then
  50. echo "deploy"
  51. elif [ "$ecode" -eq 13 ]; then
  52. echo "ext_mods"
  53. else
  54. if [ "$ecode" -eq 0 ]; then
  55. ret="true"
  56. else
  57. ret="false"
  58. fi
  59. echo "$delim" >&3
  60. echo "salt args: $salt_args" >&2
  61. if [[ "$salt_args" = 'test.opts_pkg' ]]; then
  62. cat <<EOF
  63. {
  64. "local": {
  65. "return": {
  66. "grains": {
  67. "os": "Linux",
  68. "os_family": "Debian"
  69. },
  70. "state_top": "top.sls",
  71. "renderer": "yaml_jinja",
  72. "environment": null
  73. },
  74. "retcode": $ecode,
  75. "id": "$dst_host"
  76. }
  77. }
  78. EOF
  79. else
  80. cat <<EOF
  81. {
  82. "local": {
  83. "return": $ret,
  84. "retcode": $ecode,
  85. "id": "$dst_host"
  86. }
  87. }
  88. EOF
  89. fi
  90. fi
  91. exit $ecode
  92. #/home/user/salt-ssh/bin/shell-wrapper /tmp/$id-e "$@" >/dev/null
  93. else
  94. #WTF? at least log the input...
  95. cat >>/tmp/log-$id
  96. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement