qvm-copy 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/sh
  2. set -e
  3. #
  4. # The Qubes OS Project, https://www.qubes-os.org#
  5. #
  6. # Copyright (C) 2017 Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. #
  22. #
  23. PROGRAM_NAME=${0##*/}
  24. if [ "$PROGRAM_NAME" = "qvm-move-to-vm" ] || [ "$PROGRAM_NAME" = "qvm-move" ]; then
  25. OPERATION_TYPE="move"
  26. else
  27. OPERATION_TYPE="copy"
  28. fi
  29. if [ "$PROGRAM_NAME" = "qvm-move-to-vm" ] || [ "$PROGRAM_NAME" = "qvm-copy-to-vm" ]; then
  30. TARGET_TYPE="vm"
  31. else
  32. TARGET_TYPE="default"
  33. fi
  34. if { [ $# -lt 2 ] && [ "$TARGET_TYPE" = "vm" ];} || { [ $# -lt 1 ] && [ "$TARGET_TYPE" = "default" ];} ; then
  35. if [ $TARGET_TYPE = "vm" ]; then
  36. echo "usage: $0 [--without-progress] destination_qube_name FILE [FILE ...]"
  37. else
  38. echo "usage: $0 [--without-progress] FILE [FILE ...]"
  39. fi
  40. echo
  41. if [ $OPERATION_TYPE = "move" ] ; then
  42. echo "Move FILE to ~/QubesIncoming/[THIS QUBE'S NAME]/ in the destination qube."
  43. else
  44. echo "Copy FILE to ~/QubesIncoming/[THIS QUBE'S NAME]/ in the destination qube."
  45. fi
  46. echo
  47. echo "You will be prompted to select the destination qube. If FILE is a directory, it will be copied recursively."
  48. exit 1
  49. fi
  50. if [ "$1" = "--without-progress" ] ; then
  51. export PROGRESS_TYPE=none
  52. shift
  53. else
  54. export PROGRESS_TYPE=console
  55. fi
  56. if [ "$TARGET_TYPE" = "vm" ]; then
  57. VM="$1"
  58. shift
  59. else
  60. VM="@default"
  61. fi
  62. if [ $PROGRESS_TYPE = console ] ; then
  63. FILECOPY_TOTAL_SIZE=$(du --apparent-size -c -- "$@" 2> /dev/null | tail -1 | cut -f 1)
  64. export FILECOPY_TOTAL_SIZE
  65. fi
  66. if [ "$TARGET_TYPE" = "vm" ]; then
  67. echo "qvm-copy-to-vm/qvm-move-to-vm tools are deprecated," >&2
  68. echo "use qvm-copy/qvm-move to avoid typing target qube name twice" >&2
  69. fi
  70. /usr/lib/qubes/qrexec-client-vm "$VM" qubes.Filecopy /usr/lib/qubes/qfile-agent "$@"
  71. if [ "$OPERATION_TYPE" = "move" ] ; then
  72. rm -rf -- "$@"
  73. fi