1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # Guest Additions X11 config update script
|
---|
4 | #
|
---|
5 | # Copyright (C) 2006-2010 Oracle Corporation
|
---|
6 | #
|
---|
7 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | # available from http://www.virtualbox.org. This file is free software;
|
---|
9 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
10 | # General Public License (GPL) as published by the Free Software
|
---|
11 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
12 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
13 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | #
|
---|
15 |
|
---|
16 | auto_mouse=""
|
---|
17 | new_mouse=""
|
---|
18 | no_bak=""
|
---|
19 | old_mouse_dev="/dev/psaux"
|
---|
20 |
|
---|
21 | tab=`printf '\t'`
|
---|
22 |
|
---|
23 | ALL_SECTIONS=\
|
---|
24 | '^[ '$tab']*[Ss][Ee][Cc][Tt][Ii][Oo][Nn][ '$tab']*'\
|
---|
25 | '"\([Ii][Nn][Pp][Uu][Tt][Dd][Ee][Vv][Ii][Cc][Ee]\|'\
|
---|
26 | '[Dd][Ee][Vv][Ii][Cc][Ee]\|'\
|
---|
27 | '[Ss][Ee][Rr][Vv][Ee][Rr][Ll][Aa][Yy][Oo][Uu][Tt]\|'\
|
---|
28 | '[Ss][Cc][Rr][Ee][Ee][Nn]\|'\
|
---|
29 | '[Mm][Oo][Nn][Ii][Tt][Oo][Rr]\|'\
|
---|
30 | '[Kk][Ee][Yy][Bb][Oo][Aa][Rr][Dd]\|'\
|
---|
31 | '[Pp][Oo][Ii][Nn][Tt][Ee][Rr]\)"'
|
---|
32 | # ^\s*Section\s*"(InputDevice|Device|ServerLayout|Screen|Monitor|Keyboard|Pointer)"
|
---|
33 |
|
---|
34 | KBD_SECTION='[Kk][Ee][Yy][Bb][Oo][Aa][Rr][Dd]' # Keyboard
|
---|
35 |
|
---|
36 | END_SECTION='[Ee][Nn][Dd][Ss][Ee][Cc][Tt][Ii][Oo][Nn]' # EndSection
|
---|
37 |
|
---|
38 | OPT_XKB='^[ '$tab']*option[ '$tab'][ '$tab']*"xkb'
|
---|
39 |
|
---|
40 | DRIVER_KBD='^[ '$tab']*[Dd][Rr][Ii][Vv][Ee][Rr][ '$tab'][ '$tab']*'\
|
---|
41 | '"\(kbd\|keyboard\)"'
|
---|
42 | # ^\s*driver\s+\"(kbd|keyboard)\"
|
---|
43 |
|
---|
44 | reconfigure()
|
---|
45 | {
|
---|
46 | cfg="$1"
|
---|
47 | tmp="$cfg.vbox.tmp"
|
---|
48 | test -w "$cfg" || { echo "$cfg does not exist"; return; }
|
---|
49 | rm -f "$tmp"
|
---|
50 | test ! -e "$tmp" || { echo "Failed to delete $tmp"; return; }
|
---|
51 | touch "$tmp"
|
---|
52 | test -w "$tmp" || { echo "Failed to create $tmp"; return; }
|
---|
53 | xkb_opts="`cat "$cfg" | sed -n -e "/$KBD_SECTION/,/$END_SECTION/p" |
|
---|
54 | grep -i "$OPT_XKB"`"
|
---|
55 | kbd_drv="`cat "$cfg" | sed -n -e "/$KBD_SECTION/,/$END_SECTION/p" |
|
---|
56 | sed -n -e "0,/$DRIVER_KBD/s/$DRIVER_KBD/\\1/p"`"
|
---|
57 | cat > "$tmp" << EOF
|
---|
58 | # VirtualBox generated configuration file
|
---|
59 | # based on $cfg.
|
---|
60 | EOF
|
---|
61 | cat "$cfg" | sed -e "/$ALL_SECTIONS/,/$END_SECTION/s/\\(.*\\)/# \\1/" >> "$tmp"
|
---|
62 | test -n "$kbd_drv" && cat >> "$tmp" << EOF
|
---|
63 | Section "InputDevice"
|
---|
64 | Identifier "Keyboard[0]"
|
---|
65 | Driver "$kbd_drv"
|
---|
66 | $xkb_opts
|
---|
67 | Option "Protocol" "Standard"
|
---|
68 | Option "CoreKeyboard"
|
---|
69 | EndSection
|
---|
70 | EOF
|
---|
71 | kbd_layout=""
|
---|
72 | test -n "$kbd_drv" && kbd_layout=' InputDevice "Keyboard[0]" "CoreKeyboard"'
|
---|
73 | test -z "$auto_mouse" -a -z "$new_mouse" && cat >> $tmp << EOF
|
---|
74 |
|
---|
75 | Section "InputDevice"
|
---|
76 | Identifier "Mouse[1]"
|
---|
77 | Driver "vboxmouse"
|
---|
78 | Option "Buttons" "9"
|
---|
79 | Option "Device" "$old_mouse_dev"
|
---|
80 | Option "Name" "VirtualBox Mouse"
|
---|
81 | Option "Protocol" "explorerps/2"
|
---|
82 | Option "Vendor" "Oracle Corporation"
|
---|
83 | Option "ZAxisMapping" "4 5"
|
---|
84 | Option "CorePointer"
|
---|
85 | EndSection
|
---|
86 |
|
---|
87 | Section "ServerLayout"
|
---|
88 | Identifier "Layout[all]"
|
---|
89 | $kbd_layout
|
---|
90 | InputDevice "Mouse[1]" "CorePointer"
|
---|
91 | Option "Clone" "off"
|
---|
92 | Option "Xinerama" "off"
|
---|
93 | Screen "Screen[0]"
|
---|
94 | EndSection
|
---|
95 | EOF
|
---|
96 |
|
---|
97 | test -z "$auto_mouse" -a -n "$new_mouse" &&
|
---|
98 | cat >> "$tmp" << EOF
|
---|
99 |
|
---|
100 | Section "InputDevice"
|
---|
101 | Driver "mouse"
|
---|
102 | Identifier "Mouse[1]"
|
---|
103 | Option "Buttons" "9"
|
---|
104 | Option "Device" "/dev/input/mice"
|
---|
105 | Option "Name" "VirtualBox Mouse Buttons"
|
---|
106 | Option "Protocol" "explorerps/2"
|
---|
107 | Option "Vendor" "Oracle Corporation"
|
---|
108 | Option "ZAxisMapping" "4 5"
|
---|
109 | Option "CorePointer"
|
---|
110 | EndSection
|
---|
111 |
|
---|
112 | Section "InputDevice"
|
---|
113 | Driver "vboxmouse"
|
---|
114 | Identifier "Mouse[2]"
|
---|
115 | Option "Device" "/dev/vboxguest"
|
---|
116 | Option "Name" "VirtualBox Mouse"
|
---|
117 | Option "Vendor" "Oracle Corporation"
|
---|
118 | Option "SendCoreEvents"
|
---|
119 | EndSection
|
---|
120 |
|
---|
121 | Section "ServerLayout"
|
---|
122 | Identifier "Layout[all]"
|
---|
123 | InputDevice "Keyboard[0]" "CoreKeyboard"
|
---|
124 | InputDevice "Mouse[1]" "CorePointer"
|
---|
125 | InputDevice "Mouse[2]" "SendCoreEvents"
|
---|
126 | Option "Clone" "off"
|
---|
127 | Option "Xinerama" "off"
|
---|
128 | Screen "Screen[0]"
|
---|
129 | EndSection
|
---|
130 | EOF
|
---|
131 |
|
---|
132 | cat >> "$tmp" << EOF
|
---|
133 |
|
---|
134 | Section "Monitor"
|
---|
135 | Identifier "Monitor[0]"
|
---|
136 | ModelName "VirtualBox Virtual Output"
|
---|
137 | VendorName "Oracle Corporation"
|
---|
138 | EndSection
|
---|
139 |
|
---|
140 | Section "Device"
|
---|
141 | BoardName "VirtualBox Graphics"
|
---|
142 | Driver "vboxvideo"
|
---|
143 | Identifier "Device[0]"
|
---|
144 | VendorName "Oracle Corporation"
|
---|
145 | EndSection
|
---|
146 |
|
---|
147 | Section "Screen"
|
---|
148 | SubSection "Display"
|
---|
149 | Depth 24
|
---|
150 | EndSubSection
|
---|
151 | Device "Device[0]"
|
---|
152 | Identifier "Screen[0]"
|
---|
153 | Monitor "Monitor[0]"
|
---|
154 | EndSection
|
---|
155 | EOF
|
---|
156 |
|
---|
157 | test -n "$no_bak" -o -f "$cfg.vbox" || cp "$cfg" "$cfg.vbox"
|
---|
158 | test -n "$no_bak" || mv "$cfg" "$cfg.bak"
|
---|
159 | mv "$tmp" "$cfg"
|
---|
160 | }
|
---|
161 |
|
---|
162 | while test -n "$1"
|
---|
163 | do
|
---|
164 | case "$1" in
|
---|
165 | --autoMouse)
|
---|
166 | auto_mouse=1 ;;
|
---|
167 | --newMouse)
|
---|
168 | new_mouse=1 ;;
|
---|
169 | --noBak)
|
---|
170 | no_bak=1 ;;
|
---|
171 | --nopsaux)
|
---|
172 | old_mouse_dev="/dev/input/mice" ;;
|
---|
173 | *)
|
---|
174 | reconfigure "$1" ;;
|
---|
175 | esac
|
---|
176 | shift
|
---|
177 | done
|
---|