vm-execute 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env ruby
  2. require 'optparse'
  3. begin
  4. require "#{`git rev-parse --show-toplevel`.chomp}/features/support/helpers/exec_helper.rb"
  5. rescue LoadError => e
  6. raise "This script must be run from within Tails' Git directory."
  7. end
  8. $config = Hash.new
  9. def debug_log(*args) ; end
  10. class FakeVM
  11. def get_remote_shell_port
  12. 1337
  13. end
  14. end
  15. cmd_opts = {
  16. :spawn => false,
  17. :user => "root"
  18. }
  19. opt_parser = OptionParser.new do |opts|
  20. opts.banner = "Usage: features/scripts/vm-execute [opts] COMMAND"
  21. opts.separator ""
  22. opts.separator "Runs commands in the VM guest being tested. This script " \
  23. "must be run from within Tails' Git directory."
  24. opts.separator ""
  25. opts.separator "Options:"
  26. opts.on("-h", "--help", "Show this message") do
  27. puts opts
  28. exit
  29. end
  30. opts.on("-u", "--user USER", "Run command as USER") do |user|
  31. cmd_opts[:user] = user
  32. end
  33. opts.on("-s", "--spawn",
  34. "Run command in non-blocking mode") do |type|
  35. cmd_opts[:spawn] = true
  36. end
  37. end
  38. opt_parser.parse!(ARGV)
  39. cmd = ARGV.join(" ")
  40. c = VMCommand.new(FakeVM.new, cmd, cmd_opts)
  41. puts "Return status: #{c.returncode}"
  42. puts "STDOUT:\n#{c.stdout}"
  43. puts "STDERR:\n#{c.stderr}"
  44. exit c.returncode