1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # Sun VirtualBox
|
---|
4 | #
|
---|
5 | # Guest Additions X11 config update script
|
---|
6 | #
|
---|
7 | # Copyright (C) 2006-2009 Sun Microsystems, Inc.
|
---|
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 | # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | # Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | # additional information or have any questions.
|
---|
20 | #
|
---|
21 |
|
---|
22 | my $use_hal = 0;
|
---|
23 | my $new_mouse = 0;
|
---|
24 | my $no_bak = 0;
|
---|
25 |
|
---|
26 | foreach $arg (@ARGV)
|
---|
27 | {
|
---|
28 | if (lc($arg) eq "--usehal")
|
---|
29 | {
|
---|
30 | $use_hal = 1;
|
---|
31 | }
|
---|
32 | elsif (lc($arg) eq "--newmouse")
|
---|
33 | {
|
---|
34 | $new_mouse = 1;
|
---|
35 | }
|
---|
36 | elsif (lc($arg) eq "--nobak")
|
---|
37 | {
|
---|
38 | $no_bak = 1;
|
---|
39 | }
|
---|
40 | else
|
---|
41 | {
|
---|
42 | my $cfg = $arg;
|
---|
43 | my $CFG;
|
---|
44 | my $xkbopts = "";
|
---|
45 | my $kb_driver = "";
|
---|
46 | if (open(CFG, $cfg))
|
---|
47 | {
|
---|
48 | my $TMP;
|
---|
49 | my $temp = $cfg.".vbox.tmp";
|
---|
50 | open(TMP, ">$temp") or die "Can't create $TMP: $!\n";
|
---|
51 |
|
---|
52 | my $in_section = 0;
|
---|
53 | print TMP "# VirtualBox generated configuration file\n";
|
---|
54 | print TMP "# based on $cfg.\n";
|
---|
55 |
|
---|
56 | while (defined ($line = <CFG>))
|
---|
57 | {
|
---|
58 | if ($line =~ /^\s*Section\s*"([a-zA-Z]+)"/i)
|
---|
59 | {
|
---|
60 | my $section = lc($1);
|
---|
61 | if ( ($section eq "inputdevice")
|
---|
62 | || ($section eq "device")
|
---|
63 | || ($section eq "serverlayout")
|
---|
64 | || ($section eq "screen")
|
---|
65 | || ($section eq "monitor")
|
---|
66 | || ($section eq "keyboard")
|
---|
67 | || ($section eq "pointer"))
|
---|
68 | {
|
---|
69 | $in_section = 1;
|
---|
70 | }
|
---|
71 | } else {
|
---|
72 | if ($line =~ /^\s*EndSection/i)
|
---|
73 | {
|
---|
74 | $line = "# " . $line unless $in_section eq 0;
|
---|
75 | $in_section = 0;
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | if ($in_section)
|
---|
80 | {
|
---|
81 | # Remember XKB options
|
---|
82 | if ($line =~ /^\s*option\s+\"xkb/i)
|
---|
83 | {
|
---|
84 | $xkbopts = $xkbopts . $line;
|
---|
85 | }
|
---|
86 | # If we find a keyboard driver, remember it
|
---|
87 | if ($line =~ /^\s*driver\s+\"(kbd|keyboard)\"/i)
|
---|
88 | {
|
---|
89 | $kb_driver = $1;
|
---|
90 | }
|
---|
91 | $line = "# " . $line;
|
---|
92 | }
|
---|
93 | print TMP $line;
|
---|
94 | }
|
---|
95 |
|
---|
96 | if ($kb_driver ne "")
|
---|
97 | {
|
---|
98 | print TMP <<EOF;
|
---|
99 | Section "InputDevice"
|
---|
100 | Identifier "keyboard[0]"
|
---|
101 | Driver "$kb_driver"
|
---|
102 | $xkbopts Option "Protocol" "Standard"
|
---|
103 | Option "CoreKeyboard"
|
---|
104 | EndSection
|
---|
105 | EOF
|
---|
106 | }
|
---|
107 |
|
---|
108 | if (!$use_hal && !$new_mouse) {
|
---|
109 | print TMP <<EOF;
|
---|
110 |
|
---|
111 | Section "InputDevice"
|
---|
112 | Identifier "mouse"
|
---|
113 | Driver "vboxmouse"
|
---|
114 | Option "Buttons" "9"
|
---|
115 | Option "Device" "/dev/input/mice"
|
---|
116 | Option "Name" "VirtualBox Mouse Buttons"
|
---|
117 | Option "Protocol" "explorerps/2"
|
---|
118 | Option "Vendor" "Sun Microsystems Inc"
|
---|
119 | Option "ZAxisMapping" "4 5"
|
---|
120 | Option "CorePointer"
|
---|
121 | EndSection
|
---|
122 | EOF
|
---|
123 | }
|
---|
124 |
|
---|
125 | if (!$use_hal && $new_mouse) {
|
---|
126 | print TMP <<EOF;
|
---|
127 |
|
---|
128 | Section "InputDevice"
|
---|
129 | Driver "mouse"
|
---|
130 | Identifier "Mouse[1]"
|
---|
131 | Option "Buttons" "9"
|
---|
132 | Option "Device" "/dev/input/mice"
|
---|
133 | Option "Name" "VirtualBox Mouse Buttons"
|
---|
134 | Option "Protocol" "explorerps/2"
|
---|
135 | Option "Vendor" "Sun Microsystems Inc"
|
---|
136 | Option "ZAxisMapping" "4 5"
|
---|
137 | Option "CorePointer"
|
---|
138 | EndSection
|
---|
139 |
|
---|
140 | Section "InputDevice"
|
---|
141 | Driver "vboxmouse"
|
---|
142 | Identifier "Mouse[2]"
|
---|
143 | Option "Device" "/dev/vboxguest"
|
---|
144 | Option "Name" "VirtualBox Mouse"
|
---|
145 | Option "Vendor" "Sun Microsystems Inc"
|
---|
146 | Option "SendCoreEvents"
|
---|
147 | EndSection
|
---|
148 |
|
---|
149 | Section "ServerLayout"
|
---|
150 | Identifier "Layout[all]"
|
---|
151 | InputDevice "Mouse[1]" "CorePointer"
|
---|
152 | InputDevice "Mouse[2]" "SendCoreEvents"
|
---|
153 | Option "Clone" "off"
|
---|
154 | Option "Xinerama" "off"
|
---|
155 | Screen "Screen[0]"
|
---|
156 | EndSection
|
---|
157 | EOF
|
---|
158 | }
|
---|
159 |
|
---|
160 | print TMP <<EOF;
|
---|
161 |
|
---|
162 | Section "Monitor"
|
---|
163 | Identifier "Monitor[0]"
|
---|
164 | ModelName "VirtualBox Virtual Output"
|
---|
165 | VendorName "Sun Microsystems Inc"
|
---|
166 | EndSection
|
---|
167 |
|
---|
168 | Section "Device"
|
---|
169 | BoardName "VirtualBox Graphics"
|
---|
170 | Driver "vboxvideo"
|
---|
171 | Identifier "Device[0]"
|
---|
172 | VendorName "Sun Microsystems Inc"
|
---|
173 | EndSection
|
---|
174 |
|
---|
175 | Section "Screen"
|
---|
176 | SubSection "Display"
|
---|
177 | Depth 24
|
---|
178 | EndSubSection
|
---|
179 | Device "Device[0]"
|
---|
180 | Identifier "Screen[0]"
|
---|
181 | Monitor "Monitor[0]"
|
---|
182 | EndSection
|
---|
183 | EOF
|
---|
184 | close(TMP);
|
---|
185 |
|
---|
186 | system("cp", $cfg, $cfg.".vbox") unless
|
---|
187 | ($no_bak eq 1 || -e $cfg.".vbox");
|
---|
188 | rename $cfg, $cfg.".bak" unless $no_bak eq 1;
|
---|
189 | rename $temp, $cfg;
|
---|
190 | }
|
---|
191 | }
|
---|
192 | }
|
---|
193 | exit 0
|
---|