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