admin.vm.volume.Import 960 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/sh
  2. set -e
  3. # use temporary file, because env variables deal poorly with \0 inside
  4. tmpfile=$(mktemp)
  5. trap "rm -f $tmpfile" EXIT
  6. qubesd-query -e \
  7. "$QREXEC_REMOTE_DOMAIN" \
  8. "admin.vm.volume.Import" \
  9. "$QREXEC_REQUESTED_TARGET" \
  10. "$1" >$tmpfile
  11. # exit if qubesd returned an error (not '0\0')
  12. if [ "$(head -c 2 $tmpfile | xxd -p)" != "3000" ]; then
  13. cat "$tmpfile"
  14. exit 1
  15. fi
  16. size=$(tail -c +3 "$tmpfile"|cut -d ' ' -f 1)
  17. path=$(tail -c +3 "$tmpfile"|cut -d ' ' -f 2)
  18. # now process stdin into this path
  19. if dd bs=4k of="$path" count="$size" iflag=count_bytes,fullblock \
  20. conv=sparse,notrunc,nocreat,fdatasync; then
  21. status="ok"
  22. else
  23. status="fail"
  24. fi
  25. # send status notification to qubesd, and pass its response to the caller
  26. echo -n "$status" | qubesd-query -c /var/run/qubesd.internal.sock \
  27. "$QREXEC_REMOTE_DOMAIN" \
  28. "internal.vm.volume.ImportEnd" \
  29. "$QREXEC_REQUESTED_TARGET" \
  30. "$1"