qubes_pencmd 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/sh
  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. SHARE_DIR=/var/run/qubes
  23. function do_new()
  24. {
  25. FILE=$SHARE_DIR/pendrive.$2
  26. truncate -s 1G $FILE || exit 1
  27. vmname=$(xenstore-read /local/domain/$1/name)
  28. mkfs.vfat -n "$vmname" $FILE || exit 1
  29. xm block-attach $1 file:/$FILE /dev/xvdg w || exit 1
  30. }
  31. function do_umount()
  32. {
  33. xm block-detach $1 /dev/xvdh || exit 1
  34. rm $SHARE_DIR/pendrive.$2
  35. }
  36. function do_send()
  37. {
  38. FILE=$SHARE_DIR/pendrive.$3
  39. vmname=$(xenstore-read /local/domain/$1/name)
  40. xenstore-write /local/domain/$2/qubes_blocksrc $vmname
  41. xm block-detach $1 /dev/xvdg || exit 1
  42. xm block-attach $2 file:/$FILE /dev/xvdh w || exit 1
  43. }
  44. if [ $# -lt 1 ] ; then
  45. echo args missing ?
  46. exit 1
  47. fi
  48. if [ "$1" = "new" ] ; then
  49. if ! [ $# = 3 ] ; then
  50. echo new requires 2 more args
  51. exit 1
  52. fi
  53. do_new "$2" "$3"
  54. elif [ "$1" = "umount" ] ; then
  55. if ! [ $# = 3 ] ; then
  56. echo umount requires 2 more args
  57. exit 1
  58. fi
  59. do_umount "$2" "$3"
  60. elif [ "$1" = "send" ] ; then
  61. if ! [ $# = 4 ] ; then
  62. echo send requires 3 more args
  63. exit 1
  64. fi
  65. do_send "$2" "$3" "$4"
  66. else
  67. echo bad cmd
  68. exit 1
  69. fi