forked from ytsarev/suseviclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vnc.rb
executable file
·65 lines (52 loc) · 1.21 KB
/
vnc.rb
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
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env ruby
#This is optional addon to suseviclient.sh.
#It enables us to pass keystrokes to VM and automate custom scenarios
#To use it you have to install ruby-vnc:
#gem install ruby-vnc
require 'rubygems'
require 'net/vnc'
if ARGV[0] == nil or ARGV[0] == '--help'
puts "Usage:
./vnc.rb <server> <port> <password> <string_to_pass_to_server>"
exit
end
server, port, password, string = ARGV
port=port[2,3]
#keystrokes = "netsetup=dhcp autoyast=http://users.suse.cz/~ytsarev/tiny.xml".chars.to_a
keystrokes = string.chars.to_a
vnccode = "vnc.type '"
counter = 0
for character in keystrokes
if "#{character}" == ":"
vnccode += "'
vnc.key_down :shift
vnc.key_down ':'
vnc.key_up :shift
sleep 1
vnc.type '"
elsif character == "~"
vnccode += "'
vnc.key_down :shift
vnc.key_down '`'
vnc.key_up :shift
sleep 1
vnc.type '"
else
vnccode += "#{character}"
end
counter+=1
if (counter % 13) == 0
vnccode += "'
sleep 1
vnc.type '"
end
if counter == keystrokes.length
vnccode += "'"
end
end
#puts vnccode
Net::VNC.open "#{server}:#{port}", :shared => false, :password => password do |vnc|
vnc.key_press :down
eval(vnccode)
vnc.key_press :return
end