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