summaryrefslogtreecommitdiffstats
path: root/cucumber/features/scripts/vm-execute
blob: 79b6942b266a71b6b60129d409ba565c760e85a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env ruby

require 'optparse'
begin
  require "#{`git rev-parse --show-toplevel`.chomp}/cucumber/features/support/helpers/exec_helper.rb"
rescue LoadError => e
  raise "This script must be run from within Tails' Git directory."
end
$config = Hash.new

def debug_log(*args) ; end

class FakeVM
  def get_remote_shell_port
    # FIXME -- we really ought to be able to ask the vm to dynamically allocate the port, then tell us what it did, rather than this
    LIBVIRT_REMOTE_SHELL_PORT
  end
end

cmd_opts = {
  :spawn => false,
  :user  => "root"
}

opt_parser = OptionParser.new do |opts|
  opts.banner = "Usage: cucumber/features/scripts/vm-execute [opts] COMMAND"
  opts.separator ""
  opts.separator "Runs commands in the VM guest being tested. This script " \
                    "must be run from within Tails' Git directory."
  opts.separator ""
  opts.separator "Options:"

  opts.on("-h", "--help", "Show this message") do
    puts opts
    exit
  end

  opts.on("-u", "--user USER", "Run command as USER") do |user|
    cmd_opts[:user] = user
  end

  opts.on("-s", "--spawn",
          "Run command in non-blocking mode") do |type|
    cmd_opts[:spawn] = true
  end
end
opt_parser.parse!(ARGV)
cmd = ARGV.join(" ")
c = VMCommand.new(FakeVM.new, cmd, cmd_opts)
puts "Return status: #{c.returncode}"
puts "STDOUT:\n#{c.stdout}"
puts "STDERR:\n#{c.stderr}"
exit c.returncode