1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # Guest Additions X11 config update script for X.org 1.5
|
---|
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 | # What this script does: X.org 1.5 introduces full hardware autodetection
|
---|
17 | # and no longer requires the user to provide an X.org configuration file.
|
---|
18 | # However, if such a file is provided, it will override autodetection of
|
---|
19 | # the graphics card (not of vboxmouse as far as I can see). Although this
|
---|
20 | # would normally be the user's business, at least Fedora 9 still generates
|
---|
21 | # a configuration file by default, so we have to rewrite it if we want
|
---|
22 | # the additions to work on a default guest installation. So we simply go
|
---|
23 | # through any configuration files we may find on the system and replace
|
---|
24 | # references to VESA or framebuffer drivers (which might be autodetected
|
---|
25 | # for use on a VirtualBox guest) and replace them with vboxvideo.
|
---|
26 |
|
---|
27 | use File::Copy;
|
---|
28 |
|
---|
29 | my $temp="/tmp/xorg.conf";
|
---|
30 | # The list of possible names of X.org configuration files
|
---|
31 | my @cfg_files = ("/etc/X11/xorg.conf-4", "/etc/X11/xorg.conf", "/etc/X11/.xorg.conf", "/etc/xorg.conf",
|
---|
32 | "/usr/etc/X11/xorg.conf-4", "/usr/etc/X11/xorg.conf", "/usr/lib/X11/xorg.conf-4",
|
---|
33 | "/usr/lib/X11/xorg.conf");
|
---|
34 | my $CFG;
|
---|
35 | my $TMP;
|
---|
36 |
|
---|
37 | # Subroutine to roll back after a partial installation
|
---|
38 | sub do_fail {
|
---|
39 | foreach $cfg (@cfg_files) {
|
---|
40 | move $cfg.".vbox", $cfg;
|
---|
41 | unlink $cfg.".vbox";
|
---|
42 | }
|
---|
43 | die $1;
|
---|
44 | }
|
---|
45 |
|
---|
46 | # Perform the substitution on any configuration file we may find.
|
---|
47 | foreach $cfg (@cfg_files) {
|
---|
48 |
|
---|
49 | if (open(CFG, $cfg)) {
|
---|
50 | open(TMP, ">$temp")
|
---|
51 | or &do_fail("Can't create $TMP: $!\n");
|
---|
52 |
|
---|
53 | while (defined ($line = <CFG>)) {
|
---|
54 | if ($line =~ /^\s*Section\s*"([a-zA-Z]+)"/i) {
|
---|
55 | my $section = lc($1);
|
---|
56 | if ($section eq "device") {
|
---|
57 | $in_section = 1;
|
---|
58 | }
|
---|
59 | } else {
|
---|
60 | if ($line =~ /^\s*EndSection/i) {
|
---|
61 | $in_section = 0;
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | if ($in_section) {
|
---|
66 | if ($line =~ /^\s*driver\s+\"(fbdev|vga|vesa|vboxvideo|ChangeMe)\"/i) {
|
---|
67 | $line =~ s/(fbdev|vga|vesa|vboxvideo|ChangeMe)/vboxvideo/i;
|
---|
68 | }
|
---|
69 | }
|
---|
70 | print TMP $line;
|
---|
71 | }
|
---|
72 | close(TMP);
|
---|
73 |
|
---|
74 | # We do not overwrite existing $cfg.".vbox" files because that will
|
---|
75 | # likely ruin any future attempts to uninstall the additions
|
---|
76 | copy $cfg, $cfg.".bak";
|
---|
77 | if (! -e $cfg.".vbox") {
|
---|
78 | rename $cfg, $cfg.".vbox";
|
---|
79 | }
|
---|
80 | copy $temp, $cfg
|
---|
81 | or &do_fail("Could not overwrite configuration file $cfg! Exiting...");
|
---|
82 | unlink $temp;
|
---|
83 | }
|
---|
84 | }
|
---|