VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/Installer/x11config15suse.pl@ 69498

Last change on this file since 69498 was 69498, checked in by vboxsync, 7 years ago

backed out r118835 as it incorrectly updated the 'This file is based on' file headers.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1#!/usr/bin/perl -w
2# $Id: x11config15suse.pl 69498 2017-10-28 15:07:25Z vboxsync $
3## @file
4# Guest Additions X11 config update script
5#
6
7#
8# Copyright (C) 2006-2010 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# Versions of (open)SUSE which ship X.Org Server 1.5 still do not enable
20# mouse autodetection, so on these systems we have to enable vboxmouse in the
21# X.Org configuration file as well as vboxvideo. When uninstalling, we enable
22# the fbdev driver, which SUSE prefers over vesa, and we leave the references
23# to vboxmouse in place, as without the driver they are harmless.
24
25use File::Copy;
26
27# This is the file name for the temporary file we write the new configuration
28# to.
29# @todo: perl must have an API for generating this
30my $temp="/tmp/xorg.conf";
31# The list of possible names of X.org configuration files
32my @cfg_files = ("/etc/X11/xorg.conf-4", "/etc/X11/xorg.conf", "/etc/X11/.xorg.conf", "/etc/xorg.conf",
33 "/usr/etc/X11/xorg.conf-4", "/usr/etc/X11/xorg.conf", "/usr/lib/X11/xorg.conf-4",
34 "/usr/lib/X11/xorg.conf");
35# File descriptor of the old configuration file
36my $CFG;
37# File descriptor of the temporary file
38my $TMP;
39
40# The name of the mouse driver we are enabling
41my $mousedrv = 'vboxmouse';
42# The name of the video driver we are enabling
43my $videodrv= 'vboxvideo';
44
45# If we are uninstalling, restore the old video driver
46if (@ARGV && "$ARGV[0]" eq 'uninstall')
47{
48 $videodrv = 'fbdev' # SUSE prefers this one
49}
50
51# How many different configuration files have we found?
52my $config_count = 0;
53
54# Subroutine to roll back after a partial installation
55sub do_fail {
56 foreach $cfg (@cfg_files) {
57 move "$cfg.vbox", $cfg;
58 unlink "$cfg.vbox";
59 }
60 die $_[0];
61}
62
63# Perform the substitution on any configuration file we may find.
64foreach $cfg (@cfg_files) {
65
66 if (open(CFG, $cfg)) {
67 open(TMP, ">$temp")
68 or &do_fail("Can't create $TMP: $!\n");
69
70 my $have_mouse = 0;
71 my $in_section = 0;
72 my $in_layout = 0;
73
74 # Go through the configuration file line by line
75 while (defined ($line = <CFG>)) {
76 # Look for the start of sections
77 if ($line =~ /^\s*Section\s*"([a-zA-Z]+)"/i) {
78 my $section = lc($1);
79 # And see if they are device or input device sections
80 if (($section eq "inputdevice") || $section eq "device") {
81 $in_section = 1;
82 }
83 # Or server layout sections
84 if ($section eq "serverlayout")
85 {
86 $in_section = 1;
87 $in_layout = 1;
88 }
89 } else {
90 if ($line =~ /^\s*EndSection/i && $in_layout) {
91 # We always add this to the end of the server layout.
92 print TMP " InputDevice \"VBoxMouse\"\n"
93 }
94 if ($line =~ /^\s*EndSection/i) {
95 $in_section = 0;
96 $in_layout = 0;
97 }
98 }
99
100 if ($in_section) {
101 # Inside sections, look for any graphics drivers and replace
102 # them with our one.
103 if ($line =~ /^\s*driver\s+\"(fbdev|vga|vesa|vboxvideo|ChangeMe)\"/i) {
104 $line =~ s/(fbdev|vga|vesa|vboxvideo|ChangeMe)/$videodrv/i;
105 }
106 # Also keep track of whether this configuration file contains
107 # an input device section for vboxmouse. If it does, we don't
108 # need to add one later.
109 if ($line =~ /^\s*driver\s+\"(?:vboxmouse)\"/i)
110 {
111 $have_mouse = 1
112 }
113
114 # We add vboxmouse to the server layout section ourselves, so
115 # remove any existing references to it.
116 if ( $line =~ /^\s*inputdevice.*\"vboxmouse\"/i)
117 {
118 $line = "";
119 }
120 }
121 print TMP $line;
122 }
123
124 # We always add a vboxmouse section at the end for SUSE guests using
125 # X.Org 1.5 if vboxmouse is not referenced anywhere else in the file,
126 # and we do not remove it when we uninstall the additions, as it will
127 # not do any harm if it is left.
128 if (!$have_mouse) {
129 print TMP "\n";
130 print TMP "Section \"InputDevice\"\n";
131 print TMP " Identifier \"VBoxMouse\"\n";
132 print TMP " Driver \"$mousedrv\"\n";
133 print TMP " Option \"Device\" \"\/dev\/vboxguest\"\n";
134 print TMP " Option \"SendCoreEvents\" \"on\"\n";
135 print TMP "EndSection\n";
136 }
137 close(TMP);
138
139 # We do not overwrite existing "$cfg.vbox" files in order to keep a
140 # record of what the configuration looked like before the very first
141 # installation of the additions.
142 copy $cfg, "$cfg.bak";
143 if (! -e "$cfg.vbox") {
144 rename $cfg, "$cfg.vbox";
145 }
146 copy $temp, $cfg
147 or &do_fail("Could not overwrite configuration file $cfg! Exiting...");
148 unlink $temp;
149
150 $config_count++;
151 }
152}
153
154# Warn if we did not find any configuration files
155$config_count != 0 or die "Could not find any X11 configuration files";
156
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette