x11config15suse.pl revision 2291faee92ebb5cc9722cd3f22e499900a5a411f
#
# Guest Additions X11 config update script
#
# Copyright (C) 2006-2010 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#
# Versions of (open)SUSE which ship X.Org Server 1.5 still do not enable
# mouse autodetection, so on these systems we have to enable vboxmouse in the
# X.Org configuration file as well as vboxvideo. When uninstalling, we enable
# the fbdev driver, which SUSE prefers over vesa, and we leave the references
# to vboxmouse in place, as without the driver they are harmless.
# This is the file name for the temporary file we write the new configuration
# to.
# @todo: perl must have an API for generating this
# The list of possible names of X.org configuration files
my @cfg_files = ("/etc/X11/xorg.conf-4", "/etc/X11/xorg.conf", "/etc/X11/.xorg.conf", "/etc/xorg.conf",
# File descriptor of the old configuration file
my $CFG;
# File descriptor of the temporary file
my $TMP;
# The name of the mouse driver we are enabling
my $mousedrv = 'vboxmouse';
# The name of the video driver we are enabling
my $videodrv= 'vboxvideo';
# If we are uninstalling, restore the old video driver
{
}
# How many different configuration files have we found?
my $config_count = 0;
# Subroutine to roll back after a partial installation
sub do_fail {
unlink "$cfg.vbox";
}
die $_[0];
}
# Perform the substitution on any configuration file we may find.
open(TMP, ">$temp")
or &do_fail("Can't create $TMP: $!\n");
my $have_mouse = 0;
my $in_section = 0;
my $in_layout = 0;
# Go through the configuration file line by line
# Look for the start of sections
my $section = lc($1);
# And see if they are device or input device sections
$in_section = 1;
}
# Or server layout sections
if ($section eq "serverlayout")
{
$in_section = 1;
$in_layout = 1;
}
} else {
# We always add this to the end of the server layout.
print TMP " InputDevice \"VBoxMouse\"\n"
}
if ($line =~ /^\s*EndSection/i) {
$in_section = 0;
$in_layout = 0;
}
}
if ($in_section) {
# Inside sections, look for any graphics drivers and replace
# them with our one.
}
# Also keep track of whether this configuration file contains
# an input device section for vboxmouse. If it does, we don't
# need to add one later.
{
$have_mouse = 1
}
# We add vboxmouse to the server layout section ourselves, so
# remove any existing references to it.
{
$line = "";
}
}
}
# We always add a vboxmouse section at the end for SUSE guests using
# X.Org 1.5 if vboxmouse is not referenced anywhere else in the file,
# and we do not remove it when we uninstall the additions, as it will
# not do any harm if it is left.
if (!$have_mouse) {
print TMP "\n";
print TMP "Section \"InputDevice\"\n";
print TMP " Identifier \"VBoxMouse\"\n";
print TMP " Driver \"$mousedrv\"\n";
print TMP " Option \"Device\" \"\/dev\/vboxguest\"\n";
print TMP " Option \"SendCoreEvents\" \"on\"\n";
print TMP "EndSection\n";
}
close(TMP);
# We do not overwrite existing "$cfg.vbox" files in order to keep a
# record of what the configuration looked like before the very first
# installation of the additions.
if (! -e "$cfg.vbox") {
rename $cfg, "$cfg.vbox";
}
or &do_fail("Could not overwrite configuration file $cfg! Exiting...");
unlink $temp;
$config_count++;
}
}
# Warn if we did not find any configuration files