VirtualBox

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

Last change on this file since 61908 was 32388, checked in by vboxsync, 14 years ago

more branding fixes

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