qubes_pencmd 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. xenstore-write /local/domain/$2/qubes_transaction_seq "$4"
  42. xm block-detach $1 /dev/xvdg || exit 1
  43. xm block-attach $2 file:/$FILE /dev/xvdh w || exit 1
  44. }
  45. export PATH=$PATH:/sbin:/usr/sbin
  46. if [ $# -lt 1 ] ; then
  47. echo args missing ?
  48. exit 1
  49. fi
  50. if [ "$1" = "new" ] ; then
  51. if ! [ $# = 3 ] ; then
  52. echo new requires 2 more args
  53. exit 1
  54. fi
  55. do_new "$2" "$3"
  56. elif [ "$1" = "umount" ] ; then
  57. if ! [ $# = 3 ] ; then
  58. echo umount requires 2 more args
  59. exit 1
  60. fi
  61. do_umount "$2" "$3"
  62. elif [ "$1" = "send" ] ; then
  63. if ! [ $# = 5 ] ; then
  64. echo send requires 4 more args
  65. exit 1
  66. fi
  67. do_send "$2" "$3" "$4" "$5"
  68. else
  69. echo bad cmd
  70. exit 1
  71. fi