5 require 'rexml/document'
7 top_level_dir
= `git rev-parse --show-toplevel`.chomp
8 require "#{top_level_dir}/features/support/helpers/remote_shell.rb"
9 require "#{top_level_dir}/features/support/helpers/misc_helpers.rb"
11 raise "This script must be run from within Tails' Git directory."
15 VIRTIO_REMOTE_SHELL
= 'org.tails.remote_shell.0'.freeze
17 def debug_log(*args
); end
19 # Implements the subset of the VM class that we need here
24 virt
= Libvirt
.open('qemu:///system')
25 domain
= virt
.lookup_domain_by_name('TailsToaster')
26 @domain_xml = domain
.xml_desc
28 raise 'There was a problem with the TailsToaster VM (is it running?)'
34 def virtio_channel_socket_path(channel
)
35 rexml
= REXML
::Document.new(@domain_xml)
36 rexml
.elements
.each('domain/devices/channel') do |e
|
37 target
= e
.elements
['target']
38 if target
.attribute('name').to_s
== channel
39 return e
.elements
['source'].attribute('path').to_s
42 raise 'The running TailsToaster has no remote shell channel!'
52 opt_parser
= OptionParser
.new
do |opts
|
53 opts
.banner
= 'Usage: features/scripts/vm-file [opts]'
55 opts
.separator
'Copies file to/from VM'
57 opts
.separator
'Options:'
59 opts
.on_tail('-h', '--help', 'Show this message') do
64 opts
.on('--upload=LOCAL', 'Upload file to the VM') do |src
|
65 cmd_opts
[:upload] = true
69 opts
.on('--download=REMOTE', 'Download file from the VM') do |src
|
70 cmd_opts
[:upload] = false
74 opts
.on('--to=DESTINATION', 'File destination') do |dest
|
79 opt_parser
.parse
!(ARGV)
82 content
= File
.read(cmd_opts
[:src])
83 f
= RemoteShell
::File.new(FakeVM
.new
, cmd_opts
[:dst])
86 f
= RemoteShell
::File.new(FakeVM
.new
, cmd_opts
[:src])
87 File
.write(cmd_opts
[:dst], f
.read
)