summaryrefslogtreecommitdiffstats
path: root/os-plugins/plugins/xserver/files/suse-gfx-install.sh
blob: 3a36a3dc0bbb6f5a2cce6e14385763605f205811 (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
#!/bin/sh

#
# supported:
# nvidia: 
# 	* 10.2 (pkg-installer)
#	* 11.0 (zypper rpm packages)
# 	* not yet - soon - 11.1 
# 
# ati:
#	* 10.2 (pkg-installer)
#	* 11.0 (zypper rpm packages)
#	* 11.1 (zypper rpm packages)
#

# not right any more - removed from script
# is there any busybox in this environment
#BUSYBOX="/mnt/opt/openslx//busybox/busybox"

BASE=/opt/openslx/plugin-repo/xserver
DISTRO=$2
cd ${BASE} 

if [ -L /boot/vmlinuz ]; then 
    KSUFFIX=$(ls -l /boot/vmlinuz | grep -P -o -e "-[a-z]*$" )
	KVERS=$(ls -l /boot/vmlinuz | awk -F "->" '{print $2}'| grep -P -o "2.6.*")
else 
    KSUFFIX=$(ls /boot/vmlinuz-* | head -n1 | grep -P -o -e "-[a-z]*$" )
	KVERS=$(ls /boot/vmlinuz-* | head -n1 | awk -F "->" '{print $2}' | grep -P -o "2.6.*" )

fi

if [ -z "${KSUFFIX}" ]; then
    echo "Could not determine proper local kernel suffix!"
    echo "This is needed to install kernel modules for graphics drivers!"
    exit 1
#else
#	echo -e "Kernel-Suffix: ${KSUFFIX}"
#	echo -e "Kernel-version:${KVERS}"
fi


buildfglrx() {
    # build ATI kernel module
    cd ${BASE}/ati/usr/src/kernel-modules/fglrx
    rm -rf fglrx.ko >/dev/null 2>&1
    make KVER=${1} >/dev/null 2>&1
    if [ "$?" -eq "0" ]; then
        cp fglrx.ko ../../../../modules
    else
    	echo -e "Kernel module for kernel ${1} could not be built!"
    fi
    cd - >/dev/null 2>&1
}


##########################################################################
# NVidia section
##########################################################################
if [ "$1" = "nvidia" ]; then
  if [ ! -d nvidia ]; then
  	mkdir -p nvidia/{modules,usr,temp}
  fi
  cd nvidia/temp
  if [ -e nvidia/usr/lib/libGL.so.1 ]; then
    exit
  fi

  ############################################################
  ##                 SUSE 11.0 Section                      ##
  ############################################################

  case ${DISTRO} in
    suse-11.*)
      echo "* Downloading nvidia rpm packages... this could take some time..."
      # add repository for nvidia drivers
	  case ${DISTRO} in
	  suse-11.0*)
      zypper --no-gpg-checks addrepo http://download.nvidia.com/opensuse/11.0/ NVIDIA > /dev/null 2>&1
	  ;;
	  suse-11.1*)
      zypper --no-gpg-checks addrepo http://download.nvidia.com/opensuse/11.1/ NVIDIA > /dev/null 2>&1
	  ;;
	  esac
      # get URLs by virtually installing nvidia-OpenGL driver
      zypper --no-gpg-checks -n -vv install -D \
	  	nvidia-gfxG01-kmp${KSUFFIX}  > logfile 2>&1 
  
      # zypper refresh is requested if something is not found
      if [ "1" -le "$(cat logfile | grep -o "zypper refresh"| wc -l)" ]; then 
          zypper refresh >/dev/null 2>&1 
      fi
  
      # take unique urls from logfile
      URLS=$(cat logfile |  grep -P -o "http://.*?rpm " | sort -u | xargs)
      for RPM in $URLS; do
        RNAME=$(echo ${RPM} | sed -e 's,^.*/\(.*\)$,\1,g')
        if [ ! -e ${RNAME} ]; then
          wget ${RPM} > /dev/null 2>&1
        fi
        # We use rpm2cpio from suse to extract
        rpm2cpio ${RNAME} | cpio -id > /dev/null 2>&1
      done
      mv ./usr/X11R6/lib/* ./usr/lib/
  
      rm -rf ../usr
      mv ./usr ..
      find lib/ -name "*.ko" -exec mv '{}' ../modules \;
  
      cd .. 
    ;;
  esac

  rm -rf temp/
  cd ..

fi


############################################################################
# ATI section
############################################################################
if [ "$1" = "ati" ]; then
  if [ -e ati/usr/lib/libGL.so.1.2 ]; then
    exit
  fi

  mkdir -p ati/modules ati/temp

  case ${DISTRO} in
  suse-10.2*)
    ### SUSE 10.2 section ###
    echo "* Extracting ATI package (expected in xserver::pkgpath) ... this could take some time..."

    PKG=`find packages/ -name ati-driver*\.run | tail -n1`
    PKG_VERSION=`head ${PKG} | grep -P -o "[0-9]\.[0-9]{3}"`
    
    chmod +x ${PKG}

    ${PKG} --extract ati/temp >/dev/null 2>&1

    cd ati/temp/
    RPM=`./ati-installer.sh ${PKG_VERSION} --buildpkg SuSE/SUSE102-IA32 2>&1 | grep Package | awk '{print $2}' | tail -n1`

    cd ..
    rpm2cpio ${RPM} 2>/dev/null | cpio -id >/dev/null 2>&1 


    mv ./usr/X11R6/lib/* ./usr/lib/

    # cleanup
    rm -rf ${RPM}
    cd ..
    rm -rf ${PKG}

    buildfglrx ${KVERS}

  ;;
  suse-11.*)
    ### SUSE 11.0 Section ###

    echo "* Downloading ati rpm packages... this could take some time..."
    cd ati/temp

    # add repository for ATI drivers
	case ${DISTRO} in
	suse-11.0*)
    zypper --no-gpg-checks addrepo http://www2.ati.com/suse/11.0/ ATI > /dev/null 2>&1 
	;;
	suse-11.1*)
    zypper --no-gpg-checks addrepo http://www2.ati.com/suse/11.1/ ATI > /dev/null 2>&1 
	;;
	esac
    # get URLs by virtually installing fglrx-OpenGL driver
    zypper --no-gpg-checks -n -vv install -D ati-fglrxG01-kmp${KSUFFIX} \
    x11-video-fglrxG01 > logfile 2>&1

    # zypper refresh is requested if something is not found
    if [ "1" -le "$(cat logfile | grep -o "zypper refresh" | wc -l)" ]; then
        zypper refresh >/dev/null 2>&1
    fi

    # take unique urls from logfile
    URLS=$(cat logfile |  grep -P -o "http://.*?rpm " | grep fglrx | sort -u | xargs)
    for RPM in $URLS; do
      RNAME=$(echo ${RPM} | sed -e 's,^.*/\(.*\)$,\1,g')
      if [ ! -e ${RNAME} ]; then
        wget ${RPM} > /dev/null 2>&1 
      fi
      # We use rpm2cpio from suse to extract -> propably new rpm version
      rpm2cpio ${RNAME} | cpio -id > /dev/null 2>&1
    done

    mv ./usr/X11R6/lib/* ./usr/lib/
    mv ./usr ..
    mv ./etc ..

    find lib/ -name "*.ko" -exec mv {} ../modules \; >/dev/null 2>&1
    if [ $? -ne 0 ]; then
        echo "Could not find kernel module nvidia.ko!";
    fi

  ;;
  esac
  cd ..

  rm -rf temp/
fi