summaryrefslogtreecommitdiffstats
path: root/src/os-plugins/plugins/xserver/OpenSLX/Distro/Suse_11_0.pm
blob: 4117c421a1200e389c07b826a03a0855c429bd0b (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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# 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/Suse_11_0.pm
#    - provides SUSE-specific overrides of the Distro API for the xserver
#      plugin.
# -----------------------------------------------------------------------------
package xserver::OpenSLX::Distro::Suse_11_0;

use strict;
use warnings;

use base qw(xserver::OpenSLX::Distro::Base);

use File::Path;

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

use Data::Dumper;

################################################################################
### interface methods
################################################################################

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

    my $script = $self->SUPER::setupXserverScript($repoPath);

    $script .= unshiftHereDoc(<<'    End-of-Here');
        # SuSE specific extension to stage3 xserver.sh
        testmkd /mnt/var/lib/xkb/compiled
        testmkd /mnt/var/X11R6/bin
        testmkd /mnt/var/lib/xdm/authdir/authfiles 0700
        ln -s /usr/bin/Xorg /mnt/var/X11R6/bin/X
        rm /mnt/etc/X11/xdm/SuSEconfig.xdm
    End-of-Here

    return $script;
}

# This function needs wget installed 
sub installNvidia
{
    my $self = shift;
    my $repopath = shift || "/opt/openslx/plugin-repo/xserver/";
    my $pkgpath = shift || "packages";

    my $tmpdir = "$repopath/nvidia/temp";
    if( !-d $tmpdir ) {
        mkdir( $tmpdir );
    }
    else {
        system("rm -rf $tmpdir/*");
    }

    my $mykernel = getKernelVersionForDistro("/boot");
    my $kver = $mykernel->{'version'};
    my $ksuffix = $mykernel->{'suffix'};

    my $srinfo = `head -n1 /etc/SuSE-release`;
    my @data = split (/ /, $srinfo);
    chomp(@data);

    my $version = $data[1];
    my $chost = substr($data[2],1,-1);

    my $url = "ftp://download.nvidia.com/opensuse/$version/$chost";

    print " * Downloading NVIDIA rpm from ftp://download.nvidia.com/opensuse/$version\n";

    system("wget -P $tmpdir -t2 -T2 $url/nvidia-gfxG01-kmp-$ksuffix* >/dev/null 2>&1");

    if($? > 0) {
        print "Could not download nvidia kernel module rpm!\n";
    }

    my @rpm = glob "$tmpdir/nvidia-gfxG01*.rpm";
    my $rpm = @rpm;
    $rpm[0] =~ /nvidia-gfxG01-kmp-$ksuffix-(.*?)_(.*?)-.*?\.$chost.rpm/;
    
    my $nv_kver = $2;
    $nv_kver =~ s/_/-/g;

    if($rpm == 0) {
        print "Could not download nvidia kernel module rpm!";
        return;
    }

    system("cd $tmpdir; rpm2cpio $rpm[0] | cpio -idv >/dev/null 2>&1");

    if(!-d "$repopath/nvidia/modules/")
    {
        mkdir("$repopath/nvidia/modules/");
    }


    # since kernel 2.6.25.20-0.1 there has to be a call to ld
    # ld -r -m elf_i386 -o ../modules/nvidia.ko  lib/modules/2.6.25.20-0.4-pae/updates/{nv-kernel,nv-linux}.o

    my $nv_path = glob "$tmpdir/lib/modules/*-$ksuffix/updates/";
    if ( -f "$nv_path/nv-kernel.o" ) {
        # we have to link our kernel module here
        system("ld -r -m elf_i386 -o $nv_path/nvidia.ko $nv_path/{nv-kernel,nv-linux}.o");
    }

    copyFile("$nv_path/nvidia.ko", "$repopath/nvidia/modules");

    
    my @versions = split(/-/, $rpm[0]);
    my @nv_versions = split('_',$versions[5]);
    my $nv_version = $nv_versions[0];

    system("wget -P $tmpdir -t2 -T2 $url/x11-video-nvidiaG01-$nv_version* >/dev/null 2>&1");

    @rpm = glob "$tmpdir/x11-video-nvidiaG01-$nv_version*";
    $rpm = @rpm;

    if($rpm == 0) 
    {
        print "Could not download x11-video-nvidiaG01-$nv_version*.rpm!\n";
        print "Exiting nvidia driver installation!\n";
        return;
    }

    system("cd $tmpdir; rpm2cpio $rpm[0] | cpio -idv >/dev/null 2>&1");

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

    rmtree($tmpdir);
   
}

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

    my $tmpdir = "$repopath/ati/temp";
    if( !-d $tmpdir ) {
        mkdir( $tmpdir );
    }
    else {
        system("rm -rf $tmpdir/*");
    }

    my $mykernel = getKernelVersionForDistro("/boot");
    my $kver = $mykernel->{'version'};
    my $kver_ati = $kver;
    $kver_ati =~ s/-/_/;

    my $ksuffix = $mykernel->{'suffix'};

    my $srinfo = `head -n1 /etc/SuSE-release`;
    my @data = split (/ /, $srinfo);
    chomp(@data);

    my $version = $data[1];
    my $chost = substr($data[2],1,-1);

    my $url = "http://www2.ati.com/suse/$version/";
    
    print " * Downloading ATI rpm from http://www2.ati.com/suse/$version\n";

    system("wget -P $tmpdir -t2 -T2 $url/repodata/primary.xml.gz >/dev/null 2>&1");

    my $url2 = `zcat $tmpdir/primary.xml.gz | grep -P -o "$chost/ati-fglrxG01-kmp-$ksuffix.*?$kver_ati.*?$chost.rpm"`;
    chomp($url2);

    if($url2 eq '') {
        # Taking more general kernel version (minus local suse version)
        my $newkernvers = '';
        if($kver_ati =~ /(.*)_(.*?)$/) {
            # if we have a match here
            $newkernvers = $1;
        }
        else {
            # just try the old method
            $newkernvers = substr $kver_ati, 0, -4;
        }
        $url2 = `zcat $tmpdir/primary.xml.gz | grep -P -o "$chost/ati-fglrxG01-kmp-$ksuffix.*?$newkernvers.*?$chost.rpm"`;
        chomp($url2);
        if(! $url2 eq '') {
            $kver = $newkernvers;
        }
        else {
            # Minus local Suse version number - hoping, there was no ABI change
            if($newkernvers =~ /(.*).(.*?)$/) {
                # here we try with yet another older kernel version
                $newkernvers = $1;
            }
            else {
                $newkernvers = substr $kver_ati, 0, -7;
            }
            $url2 = `zcat $tmpdir/primary.xml.gz | grep -P -o "$chost/ati-fglrxG01-kmp-$ksuffix.*?$newkernvers.*?$chost.rpm"`;
            chomp($url2);
            if(! $url2 eq '') {
                $kver = $newkernvers;
            }

        }
    }

#    print "KVER = $kver; CHOST = $chost; ksuffix=$ksuffix\n";
#    system("bash");

    if($url2 eq '') {
        print "No ATI module rpm for the chosen kernel version ($kver) found! Exiting!\n";
	return;
    }
    system("wget -P $tmpdir -t2 -T2 $url/$url2 >/dev/null 2>&1");

    my @rpm = glob "$tmpdir/ati-fglrxG01-kmp-$ksuffix*$chost.rpm";
    my $rpm = @rpm;

    if($rpm == 0) {
        print "Could not download ATI kernel module rpm (for kernel $kver)!\n";
        print "Consider downgrading your Kernel! \nTrying package-install!\n";
        $self->installAtiOldStyle(@_);
        return;
    }

    system("cd $tmpdir; rpm2cpio $rpm[0] | cpio -idv >/dev/null 2>&1");

    if(!-d "$repopath/ati/modules/")
    {
        mkdir("$repopath/ati/modules/");
    }
    copyFile("$tmpdir/lib/modules/$kver*-$ksuffix/updates/fglrx.ko",
        "$repopath/ati/modules");

    my @versions = split(/-/, $rpm[0]);
    my @ati_versions = split('_',$versions[5]);
    my $ati_version = $ati_versions[0];

    $url2 = `zcat $tmpdir/primary.xml.gz | grep -P -o "$chost/x11-video-fglrxG01-$ati_version-.*?.$chost.rpm"`;
    chomp($url2);
    system("wget -P $tmpdir -t2 -T2 $url/$url2 >/dev/null 2>&1");

    @rpm = glob "$tmpdir/x11-video-fglrxG01-$ati_version*";
    $rpm = @rpm;

    if($rpm == 0) 
    {
        print " Could not download x11-video-fglrxG01-$ati_version*.rpm!\n";
        print " Exiting ATI driver installation!\n";
        return;
    }

    system("cd $tmpdir; rpm2cpio $rpm[0] | cpio -idv >/dev/null 2>&1");

    rmtree("$tmpdir/usr/share");
    system("mv $tmpdir/usr $repopath/ati/");
    system("mv $tmpdir/etc $repopath/ati/");
    if( ! -d "/usr/X11R6/lib/modules/dri/" ) {
        system("mkdir -p /usr/X11R6/lib/modules/dri/");
    }
    symlink("$repopath/ati/usr/lib/dri/fglrx_dri.so","/usr/X11R6/lib/modules/dri/fglrx_dri.so");

    rmtree($tmpdir);
}



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

    
    my $ret = $self->SUPER::installAti(@_);

    if($ret =~ /^error$/) {
        print "Something went wrong installing ATI files!\n";
        return;
    }

    $self->SUPER::getdkms();
    my $mykernel = getKernelVersionForDistro("/boot");
    my $kver = $mykernel->{'version'};
    my $kver_ati = $kver;
    $kver_ati =~ s/-/_/;

    my $ksuffix = $mykernel->{'suffix'};

    my $srinfo = `head -n1 /etc/SuSE-release`;
    my @data = split (/ /, $srinfo);
    chomp(@data);

    my $version = $data[1];
    my $chost = substr($data[2],1,-1);

    # here we have to compile the kernel modules for all kernels
    #
    my $ati_version =  `head $repopath/$pkgpath/ati-driver-installer-*.run | grep -P -o '[0-9]+\.[0-9]{3}' | tail -n1`;
    chomp($ati_version);

    system("mv $ret /usr/src/fglrx-$ati_version >/dev/null 2>&1");

    open FH,">/usr/src/fglrx-$ati_version/dkms.conf";
    print FH "DEST_MODULE_LOCATION=/updates\n";
    print FH "PACKAGE_NAME=fglrx\n";
    print FH "PACKAGE_VERSION=$ati_version\n";
    close FH;

    my $cmd = "#============= Executing following command =============\n".
        "/sbin/dkms ".
        " -m fglrx -v $ati_version ".
        " -k $kver-$ksuffix ".
        " --kernelsourcedir /usr/src/linux-$kver-obj/i586/$ksuffix ".
        " --no-prepare-kernel ".
        " --no-clean-kernel ".
        " build >/dev/null 2>&1 \n".
        "#==========================================================";

#print $cmd;
    if(!-f "/var/lib/dkms/fglrx/$ati_version/$kver-$ksuffix/$chost/module/fglrx.ko") {
        system("/sbin/dkms add -m fglrx -v $ati_version >/dev/null 2>&1");
        system($cmd);
        #if ($? > 0) {
        #    print "\n\nCould not compile module! Exit with Ctrl-D\n";
        #    system("/bin/bash");
        #}
    }


    if(!-d  "$repopath/ati/modules/")
    {
        mkdir( "$repopath/ati/modules/" );
    }

    if( -e "/var/lib/dkms/fglrx/$ati_version/$kver-$ksuffix/$chost/module/fglrx.ko") {
        copyFile("/var/lib/dkms/fglrx/$ati_version/$kver-$ksuffix/$chost/module/fglrx.ko",
            "$repopath/ati/modules");
    }
    else {
       print "Could not install ati driver via pkg-installer!\n";
       rmtree($repopath."/ati");
       return;
    }
    rmtree("$repopath/ati/temp");

}

1;