HeSYINUvSBZfxqA-veewee 0.2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. data/.gitignore +15 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +69 -0
  4. data/HeSYINUvSBZfxqA-veewee.gemspec +33 -0
  5. data/README.md +198 -0
  6. data/Rakefile +92 -0
  7. data/bin/veewee +79 -0
  8. data/lib/java/README.txt +5 -0
  9. data/lib/java/dir2floppy.jar +0 -0
  10. data/lib/java/dir2floppy.java +137 -0
  11. data/lib/vagrant_init.rb +6 -0
  12. data/lib/veewee/command.rb +82 -0
  13. data/lib/veewee/config.rb +5 -0
  14. data/lib/veewee/export.rb +81 -0
  15. data/lib/veewee/scancode.rb +151 -0
  16. data/lib/veewee/session.rb +783 -0
  17. data/lib/veewee/shell.rb +54 -0
  18. data/lib/veewee/ssh.rb +193 -0
  19. data/lib/veewee/transaction.rb +122 -0
  20. data/lib/veewee/utils.rb +26 -0
  21. data/lib/veewee/version.rb +3 -0
  22. data/lib/veewee/web.rb +48 -0
  23. data/lib/veewee.rb +2 -0
  24. data/templates/CentOS-4.8-i386/definition.rb +14 -0
  25. data/templates/CentOS-4.8-i386/ks.cfg +45 -0
  26. data/templates/CentOS-4.8-i386/postinstall.sh +55 -0
  27. data/templates/CentOS-5.6-i386/definition.rb +17 -0
  28. data/templates/CentOS-5.6-i386/ks.cfg +45 -0
  29. data/templates/CentOS-5.6-i386/postinstall.sh +50 -0
  30. data/templates/CentOS-5.6-i386-netboot/definition.rb +16 -0
  31. data/templates/CentOS-5.6-i386-netboot/ks.cfg +45 -0
  32. data/templates/CentOS-5.6-i386-netboot/postinstall.sh +52 -0
  33. data/templates/CentOS-5.6-x86_64-netboot/definition.rb +16 -0
  34. data/templates/CentOS-5.6-x86_64-netboot/ks.cfg +45 -0
  35. data/templates/CentOS-5.6-x86_64-netboot/postinstall.sh +60 -0
  36. data/templates/CentOS-6.0-i386/definition.rb +17 -0
  37. data/templates/CentOS-6.0-i386/ks.cfg +47 -0
  38. data/templates/CentOS-6.0-i386/postinstall.sh +48 -0
  39. data/templates/CentOS-6.0-i386-netboot/definition.rb +16 -0
  40. data/templates/CentOS-6.0-i386-netboot/ks.cfg +52 -0
  41. data/templates/CentOS-6.0-i386-netboot/postinstall.sh +30 -0
  42. data/templates/CentOS-6.0-x86_64/definition.rb +17 -0
  43. data/templates/CentOS-6.0-x86_64/ks.cfg +47 -0
  44. data/templates/CentOS-6.0-x86_64/postinstall.sh +48 -0
  45. data/templates/CentOS-6.0-x86_64-netboot/definition.rb +16 -0
  46. data/templates/CentOS-6.0-x86_64-netboot/ks.cfg +52 -0
  47. data/templates/CentOS-6.0-x86_64-netboot/postinstall.sh +30 -0
  48. data/templates/Debian-5.0.8-amd64-netboot/definition.rb +39 -0
  49. data/templates/Debian-5.0.8-amd64-netboot/postinstall.sh +60 -0
  50. data/templates/Debian-5.0.8-amd64-netboot/preseed.cfg +312 -0
  51. data/templates/Debian-5.0.8-i386-netboot/definition.rb +39 -0
  52. data/templates/Debian-5.0.8-i386-netboot/postinstall.sh +60 -0
  53. data/templates/Debian-5.0.8-i386-netboot/preseed.cfg +312 -0
  54. data/templates/Debian-6.0.2-amd64-netboot/definition.rb +39 -0
  55. data/templates/Debian-6.0.2-amd64-netboot/postinstall.sh +71 -0
  56. data/templates/Debian-6.0.2-amd64-netboot/preseed.cfg +312 -0
  57. data/templates/Debian-6.0.2-i386-netboot/definition.rb +41 -0
  58. data/templates/Debian-6.0.2-i386-netboot/postinstall.sh +83 -0
  59. data/templates/Debian-6.0.2-i386-netboot/preseed.cfg +312 -0
  60. data/templates/Fedora-14-amd64/definition.rb +16 -0
  61. data/templates/Fedora-14-amd64/ks.cfg +41 -0
  62. data/templates/Fedora-14-amd64/postinstall.sh +54 -0
  63. data/templates/Fedora-14-amd64-netboot/definition.rb +16 -0
  64. data/templates/Fedora-14-amd64-netboot/ks.cfg +40 -0
  65. data/templates/Fedora-14-amd64-netboot/postinstall.sh +54 -0
  66. data/templates/Fedora-14-i386/definition.rb +16 -0
  67. data/templates/Fedora-14-i386/ks.cfg +41 -0
  68. data/templates/Fedora-14-i386/postinstall.sh +54 -0
  69. data/templates/Fedora-14-i386-netboot/definition.rb +16 -0
  70. data/templates/Fedora-14-i386-netboot/ks.cfg +40 -0
  71. data/templates/Fedora-14-i386-netboot/postinstall.sh +54 -0
  72. data/templates/Fedora-15-i386/definition.rb +17 -0
  73. data/templates/Fedora-15-i386/ks.cfg +64 -0
  74. data/templates/Fedora-15-i386/postinstall.sh +33 -0
  75. data/templates/Fedora-15-i386-netboot/definition.rb +17 -0
  76. data/templates/Fedora-15-i386-netboot/ks.cfg +82 -0
  77. data/templates/Fedora-15-i386-netboot/postinstall.sh +18 -0
  78. data/templates/Sysrescuecd-2.0.0-experimental/autorun0 +3 -0
  79. data/templates/Sysrescuecd-2.0.0-experimental/definition.rb +20 -0
  80. data/templates/archlinux-i386/aif.cfg +33 -0
  81. data/templates/archlinux-i386/definition.rb +29 -0
  82. data/templates/archlinux-i386/postinstall.sh +95 -0
  83. data/templates/archlinux-x86_64/aif.cfg +33 -0
  84. data/templates/archlinux-x86_64/definition.rb +29 -0
  85. data/templates/archlinux-x86_64/postinstall.sh +95 -0
  86. data/templates/freebsd-8.2-experimental/definition.rb +19 -0
  87. data/templates/freebsd-8.2-experimental/postinstall.sh +191 -0
  88. data/templates/freebsd-8.2-pcbsd-i386/definition.rb +31 -0
  89. data/templates/freebsd-8.2-pcbsd-i386/pcinstall.fbg.cfg +57 -0
  90. data/templates/freebsd-8.2-pcbsd-i386/postinstall.sh +93 -0
  91. data/templates/freebsd-8.2-pcbsd-i386-netboot/definition.rb +34 -0
  92. data/templates/freebsd-8.2-pcbsd-i386-netboot/pcinstall.fbg.cfg +58 -0
  93. data/templates/freebsd-8.2-pcbsd-i386-netboot/postinstall.sh +93 -0
  94. data/templates/gentoo-latest-i386-experimental/definition.rb +29 -0
  95. data/templates/gentoo-latest-i386-experimental/postinstall.sh +184 -0
  96. data/templates/openindiana-148-ai-x86/auto_install/ai.dtd +58 -0
  97. data/templates/openindiana-148-ai-x86/auto_install/ai_manifest.xml +241 -0
  98. data/templates/openindiana-148-ai-x86/auto_install/configuration.dtd +44 -0
  99. data/templates/openindiana-148-ai-x86/auto_install/default.xml +121 -0
  100. data/templates/openindiana-148-ai-x86/auto_install/default.xml.orig +124 -0
  101. data/templates/openindiana-148-ai-x86/auto_install/sc_profiles/static_network.xml +105 -0
  102. data/templates/openindiana-148-ai-x86/auto_install/software.dtd +105 -0
  103. data/templates/openindiana-148-ai-x86/auto_install/target.dtd +196 -0
  104. data/templates/openindiana-148-ai-x86/default.xml +121 -0
  105. data/templates/openindiana-148-ai-x86/definition.rb +59 -0
  106. data/templates/openindiana-148-ai-x86/postinstall.sh +103 -0
  107. data/templates/opensuse-11.4-i386-experimental/README +11 -0
  108. data/templates/opensuse-11.4-i386-experimental/autoinst.xml +1269 -0
  109. data/templates/opensuse-11.4-i386-experimental/autoinst.xml.generated +1269 -0
  110. data/templates/opensuse-11.4-i386-experimental/autoinst.xml.tweaked +1269 -0
  111. data/templates/opensuse-11.4-i386-experimental/definition.rb +31 -0
  112. data/templates/opensuse-11.4-i386-experimental/postinstall.sh +90 -0
  113. data/templates/solaris-11-express-i386/auto_install/ai.dtd +58 -0
  114. data/templates/solaris-11-express-i386/auto_install/ai_manifest.xml +241 -0
  115. data/templates/solaris-11-express-i386/auto_install/configuration.dtd +44 -0
  116. data/templates/solaris-11-express-i386/auto_install/default.xml +124 -0
  117. data/templates/solaris-11-express-i386/auto_install/default.xml.orig +124 -0
  118. data/templates/solaris-11-express-i386/auto_install/sc_profiles/static_network.xml +105 -0
  119. data/templates/solaris-11-express-i386/auto_install/software.dtd +105 -0
  120. data/templates/solaris-11-express-i386/auto_install/target.dtd +196 -0
  121. data/templates/solaris-11-express-i386/default.xml +121 -0
  122. data/templates/solaris-11-express-i386/definition.rb +65 -0
  123. data/templates/solaris-11-express-i386/postinstall.sh +98 -0
  124. data/templates/ubuntu-10.04.2-amd64-netboot/definition.rb +23 -0
  125. data/templates/ubuntu-10.04.2-amd64-netboot/postinstall.sh +90 -0
  126. data/templates/ubuntu-10.04.2-amd64-netboot/preseed.cfg +89 -0
  127. data/templates/ubuntu-10.04.2-server-amd64/definition.rb +57 -0
  128. data/templates/ubuntu-10.04.2-server-amd64/postinstall.sh +90 -0
  129. data/templates/ubuntu-10.04.2-server-amd64/preseed.cfg +87 -0
  130. data/templates/ubuntu-10.04.2-server-amd64-alt/definition.rb +57 -0
  131. data/templates/ubuntu-10.04.2-server-amd64-alt/postinstall.sh +249 -0
  132. data/templates/ubuntu-10.04.2-server-amd64-alt/preseed.cfg +124 -0
  133. data/templates/ubuntu-10.04.2-server-i386/definition.rb +24 -0
  134. data/templates/ubuntu-10.04.2-server-i386/postinstall.sh +91 -0
  135. data/templates/ubuntu-10.04.2-server-i386/preseed.cfg +87 -0
  136. data/templates/ubuntu-10.04.2-server-i386-netboot/definition.rb +23 -0
  137. data/templates/ubuntu-10.04.2-server-i386-netboot/postinstall.sh +90 -0
  138. data/templates/ubuntu-10.04.2-server-i386-netboot/preseed.cfg +89 -0
  139. data/templates/ubuntu-10.10-server-amd64/definition.rb +24 -0
  140. data/templates/ubuntu-10.10-server-amd64/postinstall.sh +90 -0
  141. data/templates/ubuntu-10.10-server-amd64/preseed.cfg +87 -0
  142. data/templates/ubuntu-10.10-server-amd64-netboot/definition.rb +24 -0
  143. data/templates/ubuntu-10.10-server-amd64-netboot/postinstall.sh +90 -0
  144. data/templates/ubuntu-10.10-server-amd64-netboot/preseed.cfg +89 -0
  145. data/templates/ubuntu-10.10-server-i386/definition.rb +24 -0
  146. data/templates/ubuntu-10.10-server-i386/postinstall.sh +90 -0
  147. data/templates/ubuntu-10.10-server-i386/preseed.cfg +87 -0
  148. data/templates/ubuntu-10.10-server-i386-netboot/definition.rb +24 -0
  149. data/templates/ubuntu-10.10-server-i386-netboot/postinstall.sh +90 -0
  150. data/templates/ubuntu-10.10-server-i386-netboot/preseed.cfg +89 -0
  151. data/templates/ubuntu-11.04-server-amd64/definition.rb +24 -0
  152. data/templates/ubuntu-11.04-server-amd64/postinstall.sh +90 -0
  153. data/templates/ubuntu-11.04-server-amd64/preseed.cfg +87 -0
  154. data/templates/ubuntu-11.04-server-i386/definition.rb +24 -0
  155. data/templates/ubuntu-11.04-server-i386/postinstall.sh +90 -0
  156. data/templates/ubuntu-11.04-server-i386/preseed.cfg +87 -0
  157. data/templates/ubuntu-8.04.4-server-amd64/definition.rb +25 -0
  158. data/templates/ubuntu-8.04.4-server-amd64/postinstall.sh +68 -0
  159. data/templates/ubuntu-8.04.4-server-amd64/preseed.cfg +88 -0
  160. data/templates/ubuntu-8.04.4-server-i386/definition.rb +25 -0
  161. data/templates/ubuntu-8.04.4-server-i386/postinstall.sh +47 -0
  162. data/templates/ubuntu-8.04.4-server-i386/preseed.cfg +87 -0
  163. data/templates/windows-2008R2-amd64/Autounattend.xml +132 -0
  164. data/templates/windows-2008R2-amd64/README.md +68 -0
  165. data/templates/windows-2008R2-amd64/cygwin-setup.exe +0 -0
  166. data/templates/windows-2008R2-amd64/definition.rb +16 -0
  167. data/templates/windows-2008R2-amd64/install-cygwin-sshd.bat +38 -0
  168. data/templates/windows-2008R2-amd64/install-winrm.bat +6 -0
  169. data/templates/windows-2008R2-amd64/oracle-cert.cer +0 -0
  170. data/templates/windows-2008R2-amd64/postinstall.sh +122 -0
  171. data/templates/windows-2008R2-amd64/winrm.rb +8 -0
  172. data/trials/docu-vbox.txt +83 -0
  173. data/trials/f.rb +29 -0
  174. data/trials/t.rb +15 -0
  175. data/validation/features/steps/ssh_steps.rb +170 -0
  176. data/validation/support/env.rb +1 -0
  177. data/validation/vagrant-private.key +27 -0
  178. data/validation/vagrant.feature +52 -0
  179. data/validation/vagrant.pub +1 -0
  180. data/veewee.gemspec +33 -0
  181. data/vendor/cache/Platform-0.4.0.gem +0 -0
  182. data/vendor/cache/archive-tar-minitar-0.5.2.gem +0 -0
  183. data/vendor/cache/builder-3.0.0.gem +0 -0
  184. data/vendor/cache/cucumber-1.0.2.gem +0 -0
  185. data/vendor/cache/diff-lcs-1.1.2.gem +0 -0
  186. data/vendor/cache/erubis-2.7.0.gem +0 -0
  187. data/vendor/cache/ffi-1.0.9.gem +0 -0
  188. data/vendor/cache/gherkin-2.4.6.gem +0 -0
  189. data/vendor/cache/highline-1.6.2.gem +0 -0
  190. data/vendor/cache/i18n-0.5.0.gem +0 -0
  191. data/vendor/cache/json-1.5.3.gem +0 -0
  192. data/vendor/cache/net-scp-1.0.4.gem +0 -0
  193. data/vendor/cache/net-ssh-2.1.4.gem +0 -0
  194. data/vendor/cache/open4-1.1.0.gem +0 -0
  195. data/vendor/cache/popen4-0.1.2.gem +0 -0
  196. data/vendor/cache/progressbar-0.9.1.gem +0 -0
  197. data/vendor/cache/rspec-2.5.0.gem +0 -0
  198. data/vendor/cache/rspec-core-2.5.2.gem +0 -0
  199. data/vendor/cache/rspec-expectations-2.5.0.gem +0 -0
  200. data/vendor/cache/rspec-mocks-2.5.0.gem +0 -0
  201. data/vendor/cache/term-ansicolor-1.0.6.gem +0 -0
  202. data/vendor/cache/thor-0.14.6.gem +0 -0
  203. data/vendor/cache/vagrant-0.8.2.gem +0 -0
  204. data/vendor/cache/virtualbox-0.9.1.gem +0 -0
  205. metadata +417 -0
@@ -0,0 +1,82 @@
1
+ require 'veewee/session'
2
+
3
+ #Load Veewee::Session libraries
4
+ lib_dir= File.expand_path(File.join(File.dirname(__FILE__),"..","..", "lib"))
5
+ Dir.glob(File.join(lib_dir, '**','*.rb')).each {|f| require f }
6
+
7
+ #Setup some base variables to use
8
+ template_dir=File.expand_path(File.join(lib_dir,"..", "templates"))
9
+
10
+ veewee_dir="."
11
+ definition_dir= File.expand_path(File.join(veewee_dir, "definitions"))
12
+ tmp_dir=File.expand_path(File.join(veewee_dir, "tmp"))
13
+ iso_dir=File.expand_path(File.join(veewee_dir, "iso"))
14
+ box_dir=File.expand_path(File.join(veewee_dir, "boxes"))
15
+ validation_dir=File.expand_path(File.join(lib_dir, "..","validation"))
16
+
17
+ #Initialize
18
+ Veewee::Session.setenv({:veewee_dir => veewee_dir, :definition_dir => definition_dir,
19
+ :template_dir => template_dir, :iso_dir => iso_dir, :box_dir => box_dir, :tmp_dir => tmp_dir, :validation_dir => validation_dir})
20
+
21
+ module Veewee
22
+ class Command < Vagrant::Command::GroupBase
23
+ register "basebox","Commands to manage baseboxes"
24
+
25
+ desc "templates", "List the currently available basebox templates"
26
+ def templates
27
+ Veewee::Session.list_templates
28
+ end
29
+
30
+ desc "define BOXNAME TEMPLATE", "Define a new basebox starting from a template"
31
+ method_option :force,:type => :boolean , :default => false, :aliases => "-f", :desc => "overwrite the definition"
32
+ def define(boxname, template)
33
+ Veewee::Session.define(boxname,template,options)
34
+ end
35
+
36
+ desc "undefine BOXNAME", "Removes the definition of a basebox "
37
+ def undefine(boxname)
38
+ Veewee::Session.undefine(boxname)
39
+ end
40
+
41
+ desc "build BOXNAME", "Build the box BOXNAME"
42
+ method_option :force,:type => :boolean , :default => false, :aliases => "-f", :desc => "overwrite the basebox"
43
+ method_option :nogui,:type => :boolean , :default => false, :aliases => "-n", :desc => "no gui"
44
+
45
+ def build(boxname)
46
+ Veewee::Session.build(boxname,options)
47
+ end
48
+
49
+ desc "ostypes", "List the available Operating System types"
50
+ def ostypes
51
+ Veewee::Session.list_ostypes
52
+ end
53
+
54
+ desc "destroy BOXNAME", "Destroys the virtualmachine that was build for a basebox"
55
+ def destroy(boxname)
56
+ Veewee::Session.destroy_vm(boxname)
57
+ end
58
+
59
+ desc "list", "Lists all defined baseboxes"
60
+ def list
61
+ Veewee::Session.list_definitions
62
+ end
63
+
64
+ desc "export [NAME]", "Exports the basebox to the vagrant box format"
65
+ method_options :force => :boolean
66
+ def export(boxname)
67
+ if (!boxname.nil?)
68
+ Veewee::Session.export_box(boxname)
69
+ end
70
+ end
71
+
72
+ desc "validate [NAME]", "Validates a box against vagrant compliancy rules"
73
+ method_option :user,:default => "vagrant", :aliases => "-u", :desc => "user to login with"
74
+ def validate(boxname)
75
+ if (!boxname.nil?)
76
+ Veewee::Session.validate_box(boxname,options)
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ end
@@ -0,0 +1,5 @@
1
+ module Veewee
2
+ class BaseBoxConfig < Vagrant::Config::Base
3
+ configures :basebox
4
+ end
5
+ end
@@ -0,0 +1,81 @@
1
+ require 'pathname'
2
+ module Veewee
3
+ class Export
4
+
5
+ # Shellutil.execute("vagrant package --base #{vmname} --include /tmp/Vagrantfile --output /tmp/#{vmname}.box", {:progress => "on"})
6
+
7
+ def self.vagrant(boxname,boxdir,definition)
8
+
9
+ #Check if box already exists
10
+ vm=VirtualBox::VM.find(boxname)
11
+ if vm.nil?
12
+ puts "#{boxname} is not found, maybe you need to build first?"
13
+ exit
14
+ end
15
+ #We need to shutdown first
16
+ if vm.running?
17
+ puts "Vagrant requires the box to be shutdown, before it can export"
18
+ puts "Sudo also needs to work for user #{definition[:ssh_user]}"
19
+ puts "Performing a clean shutdown now."
20
+ ssh_options={ :user => definition[:ssh_user], :port => definition[:ssh_host_port], :password => definition[:ssh_password],
21
+ :timeout => definition[:ssh_timeout]}
22
+
23
+ Veewee::Ssh.execute("localhost","sudo #{definition[:shutdown_cmd]}",ssh_options)
24
+
25
+ #Wait for state poweroff
26
+ while (vm.running?) do
27
+ print '.'
28
+ sleep 1
29
+ end
30
+ puts
31
+ puts "Machine #{boxname} is powered off cleanly"
32
+ end
33
+
34
+ #Vagrant requires a relative path for output of boxes
35
+
36
+ #4.0.x. not using boxes as a subdir
37
+ boxdir=Pathname.new(Dir.pwd)
38
+
39
+ full_path=File.join(boxdir,boxname+".box")
40
+ path1=Pathname.new(full_path)
41
+ path2=Pathname.new(Dir.pwd)
42
+ box_path=path1.relative_path_from(path2).to_s
43
+
44
+ if File.exists?("#{box_path}")
45
+ puts "box #{boxname}.box already exists"
46
+ exit
47
+ end
48
+
49
+ puts "Excuting vagrant voodoo:"
50
+ export_command="vagrant package --base '#{boxname}' --output '#{box_path}'"
51
+ puts "#{export_command}"
52
+ Veewee::Shell.execute("#{export_command}") #hmm, needs to get the gem_home set?
53
+ puts
54
+
55
+ #add_ssh_nat_mapping back!!!!
56
+
57
+ puts "To import it into vagrant type:"
58
+ puts "vagrant box add '#{boxname}' '#{box_path}'"
59
+ puts ""
60
+ puts "To use it:"
61
+ puts "vagrant init '#{boxname}'"
62
+ puts "vagrant up"
63
+ puts "vagrant ssh"
64
+ end
65
+
66
+ end
67
+ end
68
+
69
+
70
+ # #currently vagrant has a problem with the machine up, it calculates the wrong port to ssh to poweroff the system
71
+ # thebox.execute("shutdown -h now")
72
+ # thebox.wait_for_state("poweroff")
73
+
74
+ # Shellutil.execute("echo 'Vagrant::Config.run do |config|' > /tmp/Vagrantfile")
75
+ # Shellutil.execute("echo ' config.ssh.forwarded_port_key = \"ssh\"' >> /tmp/Vagrantfile")
76
+ # Shellutil.execute("echo ' config.vm.forward_port(\"ssh\",22,#{host_port})' >> /tmp/Vagrantfile")
77
+ # Shellutil.execute("echo 'end' >> /tmp/Vagrantfile")
78
+
79
+
80
+ #vagrant export disables the machine
81
+ # thebox.ssh_enable_vmachine({:hostport => host_port , :guestport => 22} )
@@ -0,0 +1,151 @@
1
+ module Veewee
2
+ class Scancode
3
+
4
+ def self.send_sequence(vboxcmd,vname,sequence,webport)
5
+ puts
6
+ counter=0
7
+ sequence.each { |s|
8
+ counter=counter+1
9
+
10
+ s.gsub!(/%IP%/,Veewee::Session.local_ip);
11
+ s.gsub!(/%PORT%/,webport);
12
+ s.gsub!(/%NAME%/, vname);
13
+ puts "Typing:[#{counter}]: "+s
14
+
15
+ keycodes=string_to_keycode(s)
16
+
17
+ # VBox seems to have issues with sending the scancodes as one big
18
+ # .join()-ed string. It seems to get them out or order or ignore some.
19
+ # A workaround is to send the scancodes one-by-one.
20
+ codes=""
21
+ for keycode in keycodes.split(' ') do
22
+
23
+ unless keycode=="wait"
24
+ send_keycode(vboxcmd,vname,keycode)
25
+ sleep 0.01
26
+ else
27
+ sleep 1
28
+ end
29
+ end
30
+ #sleep after each sequence (needs to be param)
31
+ sleep 1
32
+ }
33
+
34
+ puts "Done typing."
35
+ puts
36
+
37
+ end
38
+
39
+ def self.send_keycode(vboxcmd,vname,keycode)
40
+ command= "#{vboxcmd} controlvm '#{vname}' keyboardputscancode #{keycode}"
41
+ #puts "#{command}"
42
+ IO.popen("#{command}") { |f| print '' }
43
+ end
44
+
45
+ def self.string_to_keycode(thestring)
46
+
47
+ #http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
48
+
49
+ k=Hash.new
50
+ k['1'] = '02 82' ; k['2'] = '03 83' ; k['3'] = '04 84'; k['4']= '05 85' ;
51
+ k['5']='06 86'; k['6'] = '07 87' ; k['7'] = '08 88'; k['8'] = '09 89'; k['9']= '0a 8a';
52
+ k['0']='0b 8b'; k['-'] = '0c 8c'; k['='] = '0d 8d' ;
53
+ k['Tab'] = '0f 8f';
54
+ k['q'] = '10 90' ; k['w'] = '11 91' ; k['e'] = '12 92';
55
+ k['r'] = '13 93' ; k['t'] = '14 94' ; k['y'] = '15 95';
56
+ k['u']= '16 96' ; k['i']='17 97'; k['o'] = '18 98' ; k['p'] = '19 99' ;
57
+
58
+ k['Q'] = '2a 10 aa' ; k['W'] = '2a 11 aa' ; k['E'] = '2a 12 aa'; k['R'] = '2a 13 aa' ; k['T'] = '2a 14 aa' ; k['Y'] = '2a 15 aa'; k['U']= '2a 16 aa' ; k['I']='2a 17 aa'; k['O'] = '2a 18 aa' ; k['P'] = '2a 19 aa' ;
59
+
60
+ k['a'] = '1e 9e'; k['s'] = '1f 9f' ; k['d'] = '20 a0' ; k['f'] = '21 a1'; k['g'] = '22 a2' ; k['h'] = '23 a3' ; k['j'] = '24 a4';
61
+ k['k']= '25 a5' ; k['l']='26 a6';
62
+ k['A'] = '2a 1e aa 9e'; k['S'] = '2a 1f aa 9f' ; k['D'] = '2a 20 aa a0' ; k['F'] = '2a 21 aa a1';
63
+ k['G'] = '2a 22 aa a2' ; k['H'] = '2a 23 aa a3' ; k['J'] = '2a 24 aa a4'; k['K']= '2a 25 aa a5' ; k['L']='2a 26 aa a6';
64
+
65
+ k[';'] = '27 a7' ;k['"']='2a 28 aa a8';k['\'']='28 a8';
66
+
67
+ k['\\'] = '2b ab'; k['|'] = '2a 2b aa 8b';
68
+
69
+ k['[']='1a 9a'; k[']']='1b 9b';
70
+ k['<']='2a 33 aa b3'; k['>']='2a 34 aa b4';
71
+ k['$']='2a 05 aa 85';
72
+ k['+']='2a 0d aa 8d';
73
+
74
+ k['z'] = '2c ac'; k['x'] = '2d ad' ; k['c'] = '2e ae' ; k['v'] = '2f af'; k['b'] = '30 b0' ; k['n'] = '31 b1' ;
75
+ k['m'] = '32 b2';
76
+ k['Z'] = '2a 2c aa ac'; k['X'] = '2a 2d aa ad' ; k['C'] = '2a 2e aa ae' ; k['V'] = '2a 2f aa af';
77
+ k['B'] = '2a 30 aa b0' ; k['N'] = '2a 31 aa b1' ; k['M'] = '2a 32 aa b2';
78
+
79
+ k[',']= '33 b3' ; k['.']='34 b4'; k['/'] = '35 b5' ;k[':'] = '2a 27 aa a7';
80
+ k['%'] = '2a 06 aa 86'; k['_'] = '2a 0c aa 8c';
81
+ k['&'] = '2a 08 aa 88';
82
+ k['('] = '2a 0a aa 8a';
83
+ k[')'] = '2a 0b aa 8b';
84
+
85
+
86
+ special=Hash.new;
87
+ special['<Enter>'] = '1c 9c';
88
+ special['<Backspace>'] = '0e 8e';
89
+ special['<Spacebar>'] = '39 b9';
90
+ special['<Return>'] = '1c 9c'
91
+ special['<Esc>'] = '01 81';
92
+ special['<Tab>'] = '0f 8f';
93
+ special['<KillX>'] = '1d 38 0e';
94
+ special['<Wait>'] = 'wait';
95
+
96
+ special['<Up>'] = '48 c8';
97
+ special['<Down>'] = '50 d0';
98
+ special['<PageUp>'] = '49 c9';
99
+ special['<PageDown>'] = '51 d1';
100
+ special['<End>'] = '4f cf';
101
+ special['<Insert>'] = '52 d2';
102
+ special['<Delete>'] = '53 d3';
103
+ special['<Left>'] = '4b cb';
104
+ special['<Right>'] = '4d cd';
105
+ special['<Home>'] = '47 c7';
106
+
107
+ special['<F1>'] = '3b';
108
+ special['<F2>'] = '3c';
109
+ special['<F3>'] = '3d';
110
+ special['<F4>'] = '3e';
111
+ special['<F5>'] = '3f';
112
+ special['<F6>'] = '40';
113
+ special['<F7>'] = '41';
114
+ special['<F8>'] = '42';
115
+ special['<F9>'] = '43';
116
+ special['<F10>'] = '44';
117
+
118
+ keycodes=''
119
+ thestring.gsub!(/ /,"<Spacebar>")
120
+
121
+ until thestring.length == 0
122
+ nospecial=true;
123
+ special.keys.each { |key|
124
+ if thestring.start_with?(key)
125
+ #take thestring
126
+ #check if it starts with a special key + pop special string
127
+ keycodes=keycodes+special[key]+' ';
128
+ thestring=thestring.slice(key.length,thestring.length-key.length)
129
+ nospecial=false;
130
+ break;
131
+ end
132
+ }
133
+ if nospecial
134
+ code=k[thestring.slice(0,1)]
135
+ if !code.nil?
136
+ keycodes=keycodes+code+' '
137
+ else
138
+ puts "no scan code for #{thestring.slice(0,1)}"
139
+ end
140
+ #pop one
141
+ thestring=thestring.slice(1,thestring.length-1)
142
+ end
143
+ end
144
+
145
+ return keycodes
146
+ end
147
+
148
+ end
149
+ end
150
+
151
+