summaryrefslogtreecommitdiffstats
path: root/src/os-plugins/plugins/xserver/OpenSLX/Distro/Base.pm
blob: 51c1c60ba17a63266a5fe862c909bc31ec06c14a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Copyright (c) 2008..2010 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
# xserver/OpenSLX/Distro/Base.pm
#    - provides base implementation of the Distro API for the xserver plugin.
# -----------------------------------------------------------------------------
package xserver::OpenSLX::Distro::Base;

use strict;
use warnings;

our $VERSION = 1.01;        # API-version . implementation-version

use File::Basename;
use File::Path;
use Scalar::Util qw( weaken );

use OpenSLX::Basics;
use OpenSLX::Utils;

################################################################################
### interface methods
################################################################################
sub new
{
    my $class = shift;
    my $self = {};
    return bless $self, $class;
}

sub initialize
{
    my $self        = shift;
    $self->{engine} = shift;
    weaken($self->{engine});
        # avoid circular reference between plugin and its engine
    
    return 1;
}

sub setupXserverScript
{
    my $self     = shift;
    my $repoPath = shift;

    my $pathInfo   = $self->XserverPathInfo();
    my $configFile = $pathInfo->{config};

    my $script = unshiftHereDoc(<<'    End-of-Here');
        # xserver.sh (base part)
        # written by OpenSLX-plugin 'xserver' (via xserver/Distro/Base.pm module)

        # generating the base configuration file (might be split into several
        # files for newer Xorg servers)
        echo -e "# ${xfc#/mnt*}\n# autogenerated X hardware configuration by \
        the xserver plugin in OpenSLX stage3\n# DO NOT EDIT THIS FILE BUT THE PLUGIN \
        INSTEAD" >${xfc}
        # using variables defined in XX_xserver.sh
        echo -e "${x_modpath}\n${x_srvflags}\n${x_modules}" >>${xfc}
        echo -e "${x_keyboard}\n${x_mouse}\n${x_videocard}" >>${xfc}
        echo -e "${x_monitor}\n${x_screen}\n${x_srvlayout}\n${x_dri}" >>${xfc}
        # if no module was detected, stick to vesa module
        if [ -n "$xmodule" ] ; then
          sed "s/vesa/$xmodule/;s/\"us\"/\"${XKEYBOARD}\"/" -i ${xfc}
        else
          sed "s/\"us\"/\"${XKEYBOARD}\"/" -i ${xfc}
        fi
        if [ -n "${BUSID}" ]; then
          sed -e "s,^#.*BusID .*,  BusID \"${BUSID}\",g" -i ${xfc}
        fi
        # end of base xorg.conf generation

    End-of-Here
    
    return $script;
}

# not used yet, kept as example
sub XserverPathInfo
{
    my $self = shift;
    
    my $pathInfo = {
        config => '/etc/X11/xorg.conf',
        paths => [
            '/usr/bin',
        ],
    };

    return $pathInfo;
}


# looks for the NVIDIA-installer and extracts it
sub installNvidia
{
    my $self = shift;
    my $repopath = shift || "/opt/openslx/plugin-repo/xserver/";
    my $pkgpath = shift || "packages";
    
    my @paths = glob $repopath.$pkgpath."/NVIDIA-Linux-x86*\n";
    my $paths = @paths;
   
    if ($paths > 1)
    {
        print "Found more than one NVIDIA-Linux-x86 installer. Taking first one.\n";
    }
    if ($paths == 0)
    {
        print "Found no NVIDIA-Linux-x86 installer. Quitting NVIDIA installation!\n";
        return "error";
    }

    if ( ! -X $paths[0] )
    {
       system("chmod +x ".$paths[0]);
    }
    system($paths[0]." -x --target $repopath/nvidia/temp >/dev/null 2>&1");

    if($? == -1 ) 
    {
        print "Failed to execute ".$paths[0]."\n";
        return "error";
    }

    system("mv $repopath/nvidia/temp/usr/src $repopath/nvidia/temp/");
    system("mv $repopath/nvidia/temp/usr/ $repopath/nvidia/");
    rmtree("$repopath/nvidia/usr/share/");

    return "$repopath/nvidia/temp/src/nv";
}


sub installAti
{
    my $self = shift;
    my $repopath = shift || "/opt/openslx/plugin-repo/xserver/";
    my $pkgpath = shift || "packages";

    my @paths = glob $repopath."/".$pkgpath."/ati-driver-installer*";
    my $paths = @paths;

    if ($paths > 1)
    {
        print "Found more than one ati-driver-installer. Taking first one.\n";
    }
    if ($paths == 0)
    {
        print "Found no ati-driver-installer. Quitting ATI installation!\n";
        return "error";
    }

    if ( ! -X $paths[0] )
    {
       system("chmod +x ".$paths[0]);
    }
    system($paths[0]." --extract $repopath/ati/temp >/dev/null 2>&1");

    if($? == -1 ) 
    {
        print "Failed to execute ".$paths[0]."\n";
        return "error";
    }

    # TODO: allow x86_64 driver installation (libs)
    my $arch = "x86";

    rmtree("$repopath/ati/usr");
    system("mv $repopath/ati/temp/common/usr $repopath/ati/");
    if (!-d "$repopath/ati/usr/lib" ) {
        mkdir "$repopath/ati/usr/lib";
    }
    system("mv $repopath/ati/temp/arch/$arch/usr/X11R6/lib/* $repopath/ati/usr/lib/");
    system("mv $repopath/ati/temp/arch/$arch/usr/lib/* $repopath/ati/usr/lib/");
    rmtree("$repopath/ati/usr/share/");

    my $cmd='gcc --version | head -n 1 | sed -e "s/[^0-9. ]//g;s/^ *//;s/^\(.\)\..*$/\1/"';
    my $gcc_ver_maj =`$cmd`;
    chomp($gcc_ver_maj);

    system("mv $repopath/ati/temp/arch/$arch/lib/modules/fglrx/build_mod/libfglrx_ip.a.GCC$gcc_ver_maj $repopath/ati/temp/common/lib/modules/fglrx/build_mod/");


    return "$repopath/ati/temp/common/lib/modules/fglrx/build_mod";
}

# get dkms with wget/tar and put it into /sbin
sub getdkms
{
    if( !-f "/sbin/dkms") {
        if(!-f "dkms-2.0.21.1.tar.gz" ) {
            system("wget http://linux.dell.com/dkms/permalink/dkms-2.0.21.1.tar.gz >/dev/null 2>&1");
            die("Could not download dkms tarball! Exiting!") if($? > 0 );
        }
        if(!-f "dkms-2.0.21.1/dkms" ) {
            system("tar -zxvf dkms-2.0.21.1.tar.gz dkms-2.0.21.1/dkms >/dev/null 2>&1");
            die("Could not extract dkms script from tarball! Exiting!") if($? > 0 ); 
        }
        copyFile("dkms-2.0.21.1/dkms","/sbin");
        chmod 0755, "/sbin/dkms";
    }
}


1;