qvm-copy-to-vm.gnome 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2010 Rafal Wojtczuk <rafal@invisiblethingslab.com>
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. #
  21. #
  22. SIZE=$(du -bcs -- "$@" 2>/dev/null | tail -n 1 | cut -f 1)
  23. set -e -o pipefail
  24. if [[ $SIZE == 0 ]]; then
  25. progress() {
  26. cat >/dev/null
  27. }
  28. elif [[ $0 == *.kde ]] && command -v kdialog >/dev/null; then
  29. progress() {
  30. (while read -r CURRSIZE; do
  31. if [[ $CURRSIZE == 0 ]]; then
  32. # shellcheck disable=SC2207
  33. REF=( $(kdialog --progressbar "$DESCRIPTION") )
  34. trap 'qdbus "${REF[@]}" close' EXIT # for this subshell
  35. qdbus "${REF[@]}" Set "" maximum "$SIZE"
  36. fi
  37. qdbus "${REF[@]}" Set "" value "$CURRSIZE"
  38. done) >/dev/null # hide qdbus's empty output lines
  39. }
  40. else
  41. progress() {
  42. while read -r CURRSIZE; do
  43. echo $((100 * CURRSIZE / SIZE))
  44. done | {
  45. read -r # wait for first line (always "0") and throw it away
  46. zenity --progress --text="$DESCRIPTION" --auto-close
  47. }
  48. }
  49. fi
  50. if [[ ${0##*/} == qvm-move-to-vm.* ]]; then
  51. DESCRIPTION="Moving files..."
  52. trap '[[ $? == 0 ]] && rm -rf -- "$@"' EXIT
  53. else
  54. DESCRIPTION="Copying files..."
  55. fi
  56. PROGRESS_TYPE=gui /usr/lib/qubes/qrexec-client-vm \$default qubes.Filecopy \
  57. /usr/lib/qubes/qfile-agent "$@" | progress