summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-config/xconfig.sh
blob: 3bd7d25d99bc98c6f09015ce610aea0a8bee0d9c (plain)
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
#!/bin/bash
#set -x
#SET DISPLAYRES to force Xres, ENV takes precendent over cmdline
#SET VGACARDTYPE to force card type:
    #VGACARDTYPE="ati" xconfig.sh
    #VGACARDTYPE="intel" xconfig.sh
    #VGACARDTYPE="nvidia" xconfig.sh
    #VGACARDTYPE="nvidia-390xx" xconfig.sh
    #VGACARDTYPE="nvidia-340xx" xconfig.sh
    #VGACARDTYPE="nvidia-304xx" xconfig.sh
    #VGACARDTYPE="vesa" xconfig.sh
    #VGACARDTYPE="VMware" xconfig.sh

LOGFILE=/tmp/xconfig.log
echo -e "\n\n--------------------------------------------------------------------------------" >> $LOGFILE 2>&1
echo -e `date`"\n" >> $LOGFILE 2>&1

#libxnvctrl is needed as a dep of mythtv so must be installed for every driver
ATI_PKGS="xf86-video-ati libva-mesa-driver libva-utils libglvnd libxnvctrl"
INTEL_PKGS="xf86-video-intel libva-intel-driver libva-utils libglvnd libxnvctrl"
NVIDIA_PKGS="nvidia nvidia-utils opencl-nvidia nvidia-settings libglvnd libxnvctrl"
NVIDIA_390xx_PKGS="nvidia-390xx nvidia-390xx-utils opencl-nvidia-390xx nvidia-390xx-settings libglvnd libxnvctrl-390xx"
NVIDIA_340xx_PKGS="nvidia-340xx nvidia-340xx-utils opencl-nvidia-340xx nvidia-340xx-settings libglvnd libxnvctrl-340xx"
NVIDIA_304xx_PKGS="nvidia-304xx nvidia-304xx-utils opencl-nvidia-304xx libglvnd libxnvctrl-340xx"
NVIDIA_ALL_PKGS=`echo $NVIDIA_PKGS $NVIDIA_390xx_PKGS $NVIDIA_340xx_PKGS $NVIDIA_304xx_PKGS|xargs -n1|sort -u`
VESA_PKGS="xf86-video-vesa libglvnd libxnvctrl"
VMWARE_PKGS="xf86-input-vmmouse xf86-video-vmware xf86-video-vesa libglvnd libxnvctrl"

for i in ati intel mga savage sis unichrome vmware
do
    templist=`echo $i-dri xf86-video-$i`
    OTHER_PKGS=`echo $OTHER_PKGS $templist`
done

BASE=""
MYTH_RUN_STATUS="1"
. /etc/profile

NVIDIA_304xx_SUPPORTED="$TEMPLATES/xorg/304xx_supported.txt"
NVIDIA_340xx_SUPPORTED="$TEMPLATES/xorg/340xx_supported.txt"
NVIDIA_390xx_SUPPORTED="$TEMPLATES/xorg/390xx_supported.txt"
NVIDIA_SUPPORTED="$TEMPLATES/xorg/nvidia_supported.txt"
NVIDIA_DISABLE_MSI="$TEMPLATES/xorg/nvidia_disable_msi.txt"
NVIDIA_MSI_MODPROBE="$BASE/etc/modprobe.d/nvidia_msi.conf"

. /usr/MythVantage/bin/install_functions.sh
home_check

function Xvalues {
    #echo $VGACARDTYPE
    VGAFORCED=0
    if [ "x$VGACARDTYPE" = "x" ]
    then
	    CMDLINE=$(cat /proc/cmdline)
        echo "$CMDLINE" | grep -q forceXvesa
        if [ $? = 0  ]
        then
            echo "Forcing driver to vesa from kernel cmdline" | tee -a $LOGFILE
            VGACARDTYPE=vesa
            Xcardtype=$VGACARDTYPE
        else
            VGACARDTYPE=`lspci | grep -i vga | grep -vi non-vga| sort -r | head -n 1 | cut -d: -f3 | cut -d" " -f2`
            VGAPCIID=`lspci | grep -i vga |grep -vi non-vga| sort -r | head -n 1 | cut -d" " -f1`
            CARDID=`lspci -n | grep "$VGAPCIID" | grep 10de | cut -d" " -f3 | cut -d: -f2`
            VENDORID=`lspci -n | grep "$VGAPCIID" | grep 10de | cut -d" " -f3 | cut -d: -f1`
            echo "Detected $VGACARDTYPE as the video card type" | tee -a $LOGFILE
        fi
    else
        echo "Video card type forced to $VGACARDTYPE" | tee -a $LOGFILE
        VGAFORCED=1
        CARDID="NOT_DETECTED"
    fi
    VGACARDTYPE=${VGACARDTYPE,,} #make lowercase
}

function presetupX {
    if [ "$XIgnoreConfig" = 1 ]
    then
        echo "Using User Supplied X" | tee -a $LOGFILE
        if [ -f "$MYTHHOME/templates/xorg.user" ]
        then
            cp -f "$MYTHHOME/templates/xorg.user" "$XORG_CONF"
        else
            echo "Didn't find the file" | tee -a $LOGFILE
            echo "Copy your config file to $MYTHHOME/templates/xorg.user" > "$XORG_CONF"
        fi
    else
        setupX
    fi
}

function nvidia_prepare {
    [[ -f "$NVIDIA_MSI_MODPROBE" ]] && rm -f "$NVIDIA_MSI_MODPROBE"
    echo "Remove all nvidia pkgs" >> $LOGFILE 2>&1
    for i in ${NVIDIA_ALL_PKGS}
    do
        pacman --noconfirm -Rdd $i >> $LOGFILE 2>&1
    done

    for i in ${OTHER_PKGS}
    do
        pacman --noconfirm -Rc $i >> $LOGFILE 2>&1
    done
}

function pkg_check () {
    echo "  Checking for $1 in cache or online" | tee -a $LOGFILE
    pacman --noconfirm -Sw $1 >> $LOGFILE 2>&1
    rc=$?
    if [ $rc != 0 ]
    then
        echo "  Couldn't find $1 for install, aborting" | tee -a $LOGFILE
        exit 1
    fi
}

function nvidia_driver_install {
    cp "$TEMPLATES/xorg/xorg.nvidia"  $BASE/etc/X11/xorg.conf.d/20-automv.conf

    INSTALLED=0

    CARDNAME=`grep -i "$CARDID" "$NVIDIA_SUPPORTED"`
    if [[ $? = 0 || $VGAFORCED -eq 1 && $VGACARDTYPE == "nvidia" ]]
    then
        echo "$CARDNAME" | tee -a $LOGFILE
        for i in ${NVIDIA_PKGS}
        do
            pkg_check $i
        done
        echo "Installing current nvidia driver" | tee -a $LOGFILE
        nvidia_prepare
        pacman --noconfirm -S ${NVIDIA_PKGS} >> $LOGFILE 2>&1
        if [[ $? != 0 ]]
        then
            echo "ERROR: Unable to install current nvidia driver" | tee -a $LOGFILE
        else
            echo "  Successfully Installed" | tee -a $LOGFILE
            INSTALLED=1
        fi
    fi

    if [ $INSTALLED -eq 0 ]
    then
        CARDNAME=`grep -i "$CARDID" "$NVIDIA_390xx_SUPPORTED"`
        if [[ $? = 0 || $VGAFORCED -eq 1 && $VGACARDTYPE == "nvidia-390xx" ]]
        then
            echo "$CARDNAME" | tee -a $LOGFILE
            for i in ${NVIDIA_390xx_PKGS}
            do
                pkg_check $i
            done
            echo "Installing nvidia-390xx driver" | tee -a $LOGFILE
            nvidia_prepare
            pacman --noconfirm -S ${NVIDIA_390xx_PKGS} >> $LOGFILE 2>&1
            if [[ $? != 0 ]]
            then
                echo "ERROR: Unable to install nvidia-390xx driver" | tee -a $LOGFILE
            else
                echo "  Successfully Installed" | tee -a $LOGFILE
                INSTALLED=1
            fi
        fi
    fi

    if [ $INSTALLED -eq 0 ]
    then
        CARDNAME=`grep -i "$CARDID" "$NVIDIA_340xx_SUPPORTED"`
        if [[ $? = 0 || $VGAFORCED -eq 1 && $VGACARDTYPE == "nvidia-340xx" ]]
        then
            echo "$CARDNAME" | tee -a $LOGFILE
            for i in ${NVIDIA_340xx_PKGS}
            do
                pkg_check $i
            done
            echo "Installing nvidia-340xx driver" | tee -a $LOGFILE
            nvidia_prepare
            pacman --noconfirm -S ${NVIDIA_340xx_PKGS} >> $LOGFILE 2>&1
            if [[ $? != 0 ]]
            then
                echo "ERROR: Unable to install nvidia-340xx driver" | tee -a $LOGFILE
            else
                echo "  Successfully Installed" | tee -a $LOGFILE
                INSTALLED=1
            fi
        fi
    fi

    if [ $INSTALLED -eq 0 ]
    then
        CARDNAME=`grep -i "$CARDID" "$NVIDIA_304xx_SUPPORTED"`
        if [[ $? = 0 || $VGAFORCED -eq 1 && $VGACARDTYPE == "nvidia-304xx" ]]
        then
            echo "$CARDNAME" | tee -a $LOGFILE
            for i in ${NVIDIA_304xx_PKGS}
            do
                pkg_check $i
            done
            echo "Installing nvidia-304xx driver" | tee -a $LOGFILE
            nvidia_prepare
            pacman --noconfirm -S ${NVIDIA_304xx_PKGS} >> $LOGFILE 2>&1
            if [[ $? != 0 ]]
            then
                echo "ERROR: Unable to install nvidia-304xx driver" | tee -a $LOGFILE
            else
                echo "  Successfully Installed" | tee -a $LOGFILE
                INSTALLED=1
            fi
        fi
    fi

    if [ $INSTALLED -eq 0 ]
    then
        #this is a failsafe, can't find the right driver, then use the latest'
        echo "Couldn't find the card ID. Installing current nvidia driver" | tee -a $LOGFILE
        for i in ${NVIDIA_PKGS}
        do
            pkg_check $i
        done
        echo "Installing current nvidia driver" | tee -a $LOGFILE
        nvidia_prepare
        pacman --noconfirm -S ${NVIDIA_PKGS} >> $LOGFILE 2>&1
        if [[ $? != 0 ]]
        then
            echo "ERROR: Unable to install current nvidia driver" | tee -a $LOGFILE
        else
            echo "  Successfully Installed" | tee -a $LOGFILE
            INSTALLED=1
        fi
    fi

    if [ $INSTALLED -eq 1 ]
    then
        grep -qi "$CARDID" "$NVIDIA_DISABLE_MSI"
        if [[ $? = 0 ]]
        then
            echo "Disabling MSI interrupts" | tee -a $LOGFILE
            echo "options nvidia NVreg_EnableMSI=0" > "$NVIDIA_MSI_MODPROBE"
        fi
    fi
}

function vmware_driver_install {
    for i in ${VMWARE_PKGS}
    do
        pkg_check $i
    done
    echo "Installing VMware driver" | tee -a $LOGFILE
    #this is used to remove nvidia
    nvidia_prepare
    pacman --noconfirm -S ${VMWARE_PKGS} >> $LOGFILE 2>&1
    if [[ $? != 0 ]]
    then
        echo "ERROR: Unable to install VMware driver" | tee -a $LOGFILE
    else
        echo "  Successfully Installed" | tee -a $LOGFILE
    fi
}

function vesa_driver_install {
    for i in ${VESA_PKGS}
    do
        pkg_check $i
    done
    echo "Installing Vesa driver" | tee -a $LOGFILE
    #this is used to remove nvidia
    nvidia_prepare
    pacman --noconfirm -S ${VESA_PKGS} >> $LOGFILE 2>&1
    if [[ $? != 0 ]]
    then
        echo "ERROR: Unable to install vesa driver" | tee -a $LOGFILE
    else
        echo "  Successfully Installed" | tee -a $LOGFILE
    fi
}

function intel_driver_install {
    for i in ${INTEL_PKGS}
    do
        pkg_check $i
    done
    echo "Installing Intel driver" | tee -a $LOGFILE
    #this is used to remove nvidia
    nvidia_prepare
    pacman --noconfirm -S ${INTEL_PKGS} >> $LOGFILE 2>&1
    if [[ $? != 0 ]]
    then
        echo "ERROR: Unable to install Intel driver" | tee -a $LOGFILE
    else
        echo "  Successfully Installed" | tee -a $LOGFILE
    fi
}

function ati_driver_install {
    for i in ${ATI_PKGS}
    do
        pkg_check $i
    done
    echo "Installing ATI driver" | tee -a $LOGFILE
    #this is used to remove nvidia
    nvidia_prepare
    pacman --noconfirm -S ${ATI_PKGS} >> $LOGFILE 2>&1
    if [[ $? != 0 ]]
    then
        echo "ERROR: Unable to install ATI driver" | tee -a $LOGFILE
    else
        echo "  Successfully Installed" | tee -a $LOGFILE
    fi
}

function set_res {
    echo "Setting resolution to ${Xres}" | tee -a $LOGFILE
    cat > /etc/X11/xorg.conf.d/30-screen.conf <<EOF
    Section "Screen"
        Identifier             "Screen0"  #Collapse Monitor and Device section to Screen section
        Device                 "Device0"
        Monitor                "Monitor0"
        DefaultDepth            24 #Choose the depth (16||24)
        SubSection             "Display"
            Depth               24
            Modes              "${Xres}"  #Choose the resolution
        EndSubSection
    EndSection
EOF
}

function setupX {
    Xvalues
    if [ x = x ]
    then
        case $VGACARDTYPE in
            nvidia|nvidia-390xx|nvidia-340xx|nvidia-304xx)
                    nvidia_driver_install
                    if [[ $Xres != "Auto" ]]
                    then
                        set_res
                    else
                        echo "Setting resolution to ${Xres}" | tee -a $LOGFILE
                        rm -f /etc/X11/xorg.conf.d/30-screen.conf
                    fi
                ;;

            vmware)
                    vmware_driver_install
                    cp $TEMPLATES/xorg/xorg.vmware  /etc/X11/xorg.conf.d/20-automv.conf
                    echo "copy in autostart functions" >> $LOGFILE 2>&1
                    mkdir -p /etc/X11/autostart  >> $LOGFILE 2>&1
                    echo "#!/bin/bash" > /etc/X11/autostart/vmware.sh
                    echo "/usr/bin/vmware-user-suid-wrapper" >> /etc/X11/autostart/vmware.sh
                    chmod 755 /etc/X11/autostart/vmware.sh
                    if [[ $Xres != "Auto" ]]
                    then
                        set_res
                    else
                        echo "Setting resolution to ${Xres}" | tee -a $LOGFILE
                        rm -f /etc/X11/xorg.conf.d/30-screen.conf
                    fi
                ;;

            intel)
                    intel_driver_install
                    cp $TEMPLATES/xorg/xorg.intel  /etc/X11/xorg.conf.d/20-automv.conf
                    if [[ $Xres != "Auto" ]]
                    then
                        set_res
                    else
                        echo "Setting resolution to ${Xres}" | tee -a $LOGFILE
                        rm -f /etc/X11/xorg.conf.d/30-screen.conf
                    fi
                ;;

            ati)
                    ati_driver_install
                    #cp $TEMPLATES/xorg/xorg.ati  /etc/X11/xorg.conf.d/20-automv.conf
                    if [[ $Xres != "Auto" ]]
                    then
                        set_res
                    else
                        echo "Setting resolution to ${Xres}" | tee -a $LOGFILE
                        rm -f /etc/X11/xorg.conf.d/30-screen.conf
                    fi
                ;;

            vesa|innotek|*) #leaving this as * and vesa for no real reason other then it's explicit to catch vesa
                    if [[ $VGACARDTYPE != "vesa" && $VGACARDTYPE != "innotek" ]]
                    then
                        echo "Unknown card type, using Vesa." | tee -a $LOGFILE
                    fi
                    vesa_driver_install
                    cp $TEMPLATES/xorg/xorg.vesa  /etc/X11/xorg.conf.d/20-automv.conf
                    if [[ $Xres != "Auto" ]]
                    then
                        set_res
                    else
                        echo "Setting resolution to ${Xres}" | tee -a $LOGFILE
                        rm -f /etc/X11/xorg.conf.d/30-screen.conf
                    fi

                ;;

        esac
        #configure the ramdisk for kms
        if [ x$RUNP != "x1" ]
        then
            echo "Running plymouth_config" | tee -a $LOGFILE
            plymouth_config.py >> $LOGFILE 2>&1
        fi
    fi

}

function pacman_wait {
    if [ -f /var/lib/pacman/db.lck ]
    then
        echo "Pacman is running and must quit before xconfig.sh can continue." | tee -a $LOGFILE
        echo "  Waiting for pacman to quit..." | tee -a $LOGFILE
        while [ -f /var/lib/pacman/db.lck ]
        do
            sleep 5
        done
    fi
}
#---------------------------------------------------------------------------------
#MAIN


LINE=`grep -i xorg /etc/mythvantage.cfg|grep -q False`
rc=$?
if [ $rc = 0 ]
then
    echo "**   xorg configuration disabled in /etc/mythvantage.cfg" | tee -a $LOGFILE
    exit 1
fi

if [ -f /etc/sysconfig/IGNORE_X ]
then
    echo "**   Will not run xconfig.sh due to presence of /etc/sysconfig/IGNORE_X" | tee -a $LOGFILE
    exit 1
fi

if [ -f /etc/systemconfig ]
then
    . /etc/systemconfig
else
    echo "    systemconfig not found." | tee -a $LOGFILE
fi

CMDLINE=$(cat /proc/cmdline)
echo $CMDLINE | grep -q displayres
if [ $? = 0 ]
then
    TEMPVAR=${CMDLINE#*displayres=}
    DSR=${TEMPVAR%% *}
fi
if [ ! x$DSR = x ]
then
    Xres=$DSR
    echo "    Setting resolution to ${Xres} from kernel cmdline" | tee -a $LOGFILE
fi
if [ ! x$DISPLAYRES = x ]
then
    Xres=$DISPLAYRES
    echo "Resolution forced to ${Xres}" | tee -a $LOGFILE
fi
if [ x$Xres = x ]
then
    Xres="Auto"
    echo "Resolution not set. Setting to ${Xres}" | tee -a $LOGFILE
fi


XORG_CONF="/etc/X11/xorg.conf"

pacman_wait
presetupX