1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # Sun VirtualBox
|
---|
4 | #
|
---|
5 | # Guest Additions X11 config update script
|
---|
6 | #
|
---|
7 | # Copyright (C) 2006-2009 Oracle Corporation
|
---|
8 | #
|
---|
9 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | # available from http://www.virtualbox.org. This file is free software;
|
---|
11 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | # General Public License (GPL) as published by the Free Software
|
---|
13 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | #
|
---|
17 |
|
---|
18 | my $auto_mouse = 0;
|
---|
19 | my $new_mouse = 0;
|
---|
20 | my $no_bak = 0;
|
---|
21 | my $old_mouse_dev = "/dev/psaux";
|
---|
22 |
|
---|
23 | foreach $arg (@ARGV)
|
---|
24 | {
|
---|
25 | if (lc($arg) eq "--automouse")
|
---|
26 | {
|
---|
27 | $auto_mouse = 1;
|
---|
28 | }
|
---|
29 | elsif (lc($arg) eq "--newmouse")
|
---|
30 | {
|
---|
31 | $new_mouse = 1;
|
---|
32 | }
|
---|
33 | elsif (lc($arg) eq "--nobak")
|
---|
34 | {
|
---|
35 | $no_bak = 1;
|
---|
36 | }
|
---|
37 | elsif (lc($arg) eq "--nopsaux")
|
---|
38 | {
|
---|
39 | $old_mouse_dev = "/dev/input/mice";
|
---|
40 | }
|
---|
41 | else
|
---|
42 | {
|
---|
43 | my $cfg = $arg;
|
---|
44 | my $CFG;
|
---|
45 | my $xkbopts = "";
|
---|
46 | my $kb_driver = "";
|
---|
47 | my $layout_kb = "";
|
---|
48 | if (open(CFG, $cfg))
|
---|
49 | {
|
---|
50 | my $TMP;
|
---|
51 | my $temp = $cfg.".vbox.tmp";
|
---|
52 | open(TMP, ">$temp") or die "Can't create $TMP: $!\n";
|
---|
53 |
|
---|
54 | my $in_section = 0;
|
---|
55 | print TMP "# VirtualBox generated configuration file\n";
|
---|
56 | print TMP "# based on $cfg.\n";
|
---|
57 |
|
---|
58 | while (defined ($line = <CFG>))
|
---|
59 | {
|
---|
60 | if ($line =~ /^\s*Section\s*"([a-zA-Z]+)"/i)
|
---|
61 | {
|
---|
62 | my $section = lc($1);
|
---|
63 | if ( ($section eq "inputdevice")
|
---|
64 | || ($section eq "device")
|
---|
65 | || ($section eq "serverlayout")
|
---|
66 | || ($section eq "screen")
|
---|
67 | || ($section eq "monitor")
|
---|
68 | || ($section eq "keyboard")
|
---|
69 | || ($section eq "pointer"))
|
---|
70 | {
|
---|
71 | $in_section = 1;
|
---|
72 | }
|
---|
73 | } else {
|
---|
74 | if ($line =~ /^\s*EndSection/i)
|
---|
75 | {
|
---|
76 | $line = "# " . $line unless $in_section eq 0;
|
---|
77 | $in_section = 0;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | if ($in_section)
|
---|
82 | {
|
---|
83 | # Remember XKB options
|
---|
84 | if ($line =~ /^\s*option\s+\"xkb/i)
|
---|
85 | {
|
---|
86 | $xkbopts = $xkbopts . $line;
|
---|
87 | }
|
---|
88 | # If we find a keyboard driver, remember it
|
---|
89 | if ($line =~ /^\s*driver\s+\"(kbd|keyboard)\"/i)
|
---|
90 | {
|
---|
91 | $kb_driver = $1;
|
---|
92 | }
|
---|
93 | $line = "# " . $line;
|
---|
94 | }
|
---|
95 | print TMP $line;
|
---|
96 | }
|
---|
97 |
|
---|
98 | if ($kb_driver ne "")
|
---|
99 | {
|
---|
100 | print TMP <<EOF;
|
---|
101 | Section "InputDevice"
|
---|
102 | Identifier "Keyboard[0]"
|
---|
103 | Driver "$kb_driver"
|
---|
104 | $xkbopts Option "Protocol" "Standard"
|
---|
105 | Option "CoreKeyboard"
|
---|
106 | EndSection
|
---|
107 | EOF
|
---|
108 | $layout_kb = " InputDevice \"Keyboard[0]\" \"CoreKeyboard\"\n"
|
---|
109 | }
|
---|
110 |
|
---|
111 | if (!$auto_mouse && !$new_mouse) {
|
---|
112 | print TMP <<EOF;
|
---|
113 |
|
---|
114 | Section "InputDevice"
|
---|
115 | Identifier "Mouse[1]"
|
---|
116 | Driver "vboxmouse"
|
---|
117 | Option "Buttons" "9"
|
---|
118 | Option "Device" "$old_mouse_dev"
|
---|
119 | Option "Name" "VirtualBox Mouse"
|
---|
120 | Option "Protocol" "explorerps/2"
|
---|
121 | Option "Vendor" "Sun Microsystems Inc"
|
---|
122 | Option "ZAxisMapping" "4 5"
|
---|
123 | Option "CorePointer"
|
---|
124 | EndSection
|
---|
125 |
|
---|
126 | Section "ServerLayout"
|
---|
127 | Identifier "Layout[all]"
|
---|
128 | $layout_kb InputDevice "Mouse[1]" "CorePointer"
|
---|
129 | Option "Clone" "off"
|
---|
130 | Option "Xinerama" "off"
|
---|
131 | Screen "Screen[0]"
|
---|
132 | EndSection
|
---|
133 | EOF
|
---|
134 | }
|
---|
135 |
|
---|
136 | if (!$auto_mouse && $new_mouse) {
|
---|
137 | print TMP <<EOF;
|
---|
138 |
|
---|
139 | Section "InputDevice"
|
---|
140 | Driver "mouse"
|
---|
141 | Identifier "Mouse[1]"
|
---|
142 | Option "Buttons" "9"
|
---|
143 | Option "Device" "/dev/input/mice"
|
---|
144 | Option "Name" "VirtualBox Mouse Buttons"
|
---|
145 | Option "Protocol" "explorerps/2"
|
---|
146 | Option "Vendor" "Sun Microsystems Inc"
|
---|
147 | Option "ZAxisMapping" "4 5"
|
---|
148 | Option "CorePointer"
|
---|
149 | EndSection
|
---|
150 |
|
---|
151 | Section "InputDevice"
|
---|
152 | Driver "vboxmouse"
|
---|
153 | Identifier "Mouse[2]"
|
---|
154 | Option "Device" "/dev/vboxguest"
|
---|
155 | Option "Name" "VirtualBox Mouse"
|
---|
156 | Option "Vendor" "Sun Microsystems Inc"
|
---|
157 | Option "SendCoreEvents"
|
---|
158 | EndSection
|
---|
159 |
|
---|
160 | Section "ServerLayout"
|
---|
161 | Identifier "Layout[all]"
|
---|
162 | InputDevice "Keyboard[0]" "CoreKeyboard"
|
---|
163 | InputDevice "Mouse[1]" "CorePointer"
|
---|
164 | InputDevice "Mouse[2]" "SendCoreEvents"
|
---|
165 | Option "Clone" "off"
|
---|
166 | Option "Xinerama" "off"
|
---|
167 | Screen "Screen[0]"
|
---|
168 | EndSection
|
---|
169 | EOF
|
---|
170 | }
|
---|
171 |
|
---|
172 | print TMP <<EOF;
|
---|
173 |
|
---|
174 | Section "Monitor"
|
---|
175 | Identifier "Monitor[0]"
|
---|
176 | ModelName "VirtualBox Virtual Output"
|
---|
177 | VendorName "Sun Microsystems Inc"
|
---|
178 | EndSection
|
---|
179 |
|
---|
180 | Section "Device"
|
---|
181 | BoardName "VirtualBox Graphics"
|
---|
182 | Driver "vboxvideo"
|
---|
183 | Identifier "Device[0]"
|
---|
184 | VendorName "Sun Microsystems Inc"
|
---|
185 | EndSection
|
---|
186 |
|
---|
187 | Section "Screen"
|
---|
188 | SubSection "Display"
|
---|
189 | Depth 24
|
---|
190 | EndSubSection
|
---|
191 | Device "Device[0]"
|
---|
192 | Identifier "Screen[0]"
|
---|
193 | Monitor "Monitor[0]"
|
---|
194 | EndSection
|
---|
195 | EOF
|
---|
196 | close(TMP);
|
---|
197 |
|
---|
198 | system("cp", $cfg, $cfg.".vbox") unless
|
---|
199 | ($no_bak eq 1 || -e $cfg.".vbox");
|
---|
200 | rename $cfg, $cfg.".bak" unless $no_bak eq 1;
|
---|
201 | rename $temp, $cfg;
|
---|
202 | }
|
---|
203 | }
|
---|
204 | }
|
---|
205 | exit 0
|
---|