1 | #!/usr/bin/perl
|
---|
2 | # $Id: x11config15sol.pl 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # Guest Additions X11 config update script
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox base platform packages, as
|
---|
11 | # available from https://www.virtualbox.org.
|
---|
12 | #
|
---|
13 | # This program is free software; you can redistribute it and/or
|
---|
14 | # modify it under the terms of the GNU General Public License
|
---|
15 | # as published by the Free Software Foundation, in version 3 of the
|
---|
16 | # License.
|
---|
17 | #
|
---|
18 | # This program is distributed in the hope that it will be useful, but
|
---|
19 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | # General Public License for more details.
|
---|
22 | #
|
---|
23 | # You should have received a copy of the GNU General Public License
|
---|
24 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
25 | #
|
---|
26 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
27 | #
|
---|
28 |
|
---|
29 | use strict;
|
---|
30 | use warnings;
|
---|
31 |
|
---|
32 | my $temp="/tmp/xorg.conf";
|
---|
33 | my $os_type=`uname -s`;
|
---|
34 | my @cfg_files = ("/etc/X11/xorg.conf", "/etc/X11/.xorg.conf", "/etc/X11/xorg.conf-4", "/etc/xorg.conf",
|
---|
35 | "/usr/etc/X11/xorg.conf-4", "/usr/etc/X11/xorg.conf", "/usr/lib/X11/xorg.conf-4",
|
---|
36 | "/usr/lib/X11/xorg.conf", "/etc/X11/XF86Config-4", "/etc/X11/XF86Config",
|
---|
37 | "/etc/XF86Config", "/usr/X11R6/etc/X11/XF86Config-4", "/usr/X11R6/etc/X11/XF86Config",
|
---|
38 | "/usr/X11R6/lib/X11/XF86Config-4", "/usr/X11R6/lib/X11/XF86Config");
|
---|
39 |
|
---|
40 | ## @todo: r=ramshankar: Hmm, why do we use the same variable name with upper/lower case for different variables?
|
---|
41 | my $cfg;
|
---|
42 | my $CFG;
|
---|
43 | my $TMP;
|
---|
44 | my $line;
|
---|
45 | my $config_count = 0;
|
---|
46 |
|
---|
47 | # Command line options
|
---|
48 | if ($#ARGV < 0)
|
---|
49 | {
|
---|
50 | die "x11config15sol.pl: Missing driver name argument to configure for X.org";
|
---|
51 | }
|
---|
52 | my $driver_name = $ARGV[0];
|
---|
53 |
|
---|
54 | # Loop through all possible config files and change them. It's done this wasy for hysterical raisins
|
---|
55 | # as we didn't know what the correct config file is so we update all of them. However, for Solaris it's
|
---|
56 | # most likely -only- one of the 2 config files (/etc/X11/xorg.conf, /etc/X11/.xorg.conf).
|
---|
57 | foreach $cfg (@cfg_files)
|
---|
58 | {
|
---|
59 |
|
---|
60 | if (($os_type =~ 'SunOS') && (defined $ENV{PKG_INSTALL_ROOT}))
|
---|
61 | {
|
---|
62 | $cfg = $ENV{PKG_INSTALL_ROOT}.$cfg;
|
---|
63 | }
|
---|
64 | if (open(CFG, $cfg))
|
---|
65 | {
|
---|
66 | open(TMP, ">$temp") or die "Can't create $TMP: $!\n";
|
---|
67 |
|
---|
68 | my $in_section = 0;
|
---|
69 |
|
---|
70 | while (defined ($line = <CFG>))
|
---|
71 | {
|
---|
72 | if ($line =~ /^\s*Section\s*"([a-zA-Z]+)"/i)
|
---|
73 | {
|
---|
74 | my $section = lc($1);
|
---|
75 | if ($section eq "device")
|
---|
76 | {
|
---|
77 | $in_section = 1;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | else
|
---|
81 | {
|
---|
82 | if ($line =~ /^\s*EndSection/i)
|
---|
83 | {
|
---|
84 | $in_section = 0;
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | if ($in_section)
|
---|
89 | {
|
---|
90 | if ($line =~ /^\s*driver\s+\"(?:fbdev|vga|vesa|vboxvideo|ChangeMe)\"/i)
|
---|
91 | {
|
---|
92 | $line = " Driver \"$driver_name\"\n";
|
---|
93 | }
|
---|
94 | }
|
---|
95 | print TMP $line;
|
---|
96 | }
|
---|
97 |
|
---|
98 | close(TMP);
|
---|
99 |
|
---|
100 | rename $cfg, $cfg.".bak";
|
---|
101 | system("cp $temp $cfg");
|
---|
102 | unlink $temp;
|
---|
103 |
|
---|
104 | # Solaris specific: Rename our modified .xorg.conf to xorg.conf for it to be used
|
---|
105 | if ((defined $ENV{PKG_INSTALL_ROOT}) &&
|
---|
106 | ($os_type =~ 'SunOS') && ($cfg =~ "$ENV{PKG_INSTALL_ROOT}/etc/X11/.xorg.conf"))
|
---|
107 | {
|
---|
108 | system("mv -f $cfg $ENV{PKG_INSTALL_ROOT}/etc/X11/xorg.conf");
|
---|
109 | }
|
---|
110 | else
|
---|
111 | {
|
---|
112 | if (($os_type =~ 'SunOS') && ($cfg =~ '/etc/X11/.xorg.conf'))
|
---|
113 | {
|
---|
114 | system("mv -f $cfg /etc/X11/xorg.conf");
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | $config_count++;
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | $config_count != 0 or die "Could not find any X11 configuration files.";
|
---|
123 |
|
---|