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