From c93ca2d34629de7b0d6c6a98711738cb613671cc Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Mon, 12 Jan 2015 18:11:28 +0000
Subject: LinHES-config: xconfig.sh: install nvidia and legacy nvidia driver.
 refs #986

xconfig.cron: run xconfig.sh from cron and then remove cron job. Used from nvidia post_upgrade install.
---
 abs/core/LinHES-config/PKGBUILD     |   7 +-
 abs/core/LinHES-config/xconfig.cron |   7 ++
 abs/core/LinHES-config/xconfig.sh   | 199 +++++++++++++++++++++++++-----------
 3 files changed, 151 insertions(+), 62 deletions(-)
 create mode 100755 abs/core/LinHES-config/xconfig.cron

diff --git a/abs/core/LinHES-config/PKGBUILD b/abs/core/LinHES-config/PKGBUILD
index 786d7d6..cd36f22 100755
--- a/abs/core/LinHES-config/PKGBUILD
+++ b/abs/core/LinHES-config/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=LinHES-config
 pkgver=8.3
-pkgrel=3
+pkgrel=4
 conflicts=(MythVantage-config MythVantage-config-dev LinHES-config-dev LinHes-config )
 pkgdesc="Install and configure your system"
 depends=('bc' 'libstatgrab' 'mysql-python' 'expect' 'curl' 'dnsutils' 'parted'
@@ -20,6 +20,7 @@ source=(mv_install.py 09_mythvantge_runit_grub
 	restore_default_settings.sh
 	myth_settings_wrapper.sh
     xconfig.sh
+    xconfig.cron
 	timezip.py
 	soundconfig.sh
 	LinHES-release
@@ -76,6 +77,7 @@ package() {
     install -m 0755 install_functions.sh  $MVDIR/bin/install_functions.sh
     install -m 0755 systemconfig.sh  $MVDIR/bin/systemconfig.sh
     install -m 0755 xconfig.sh  $MVDIR/bin/xconfig.sh
+    install -m 0644 xconfig.cron  $MVDIR/bin/xconfig.cron
     install -m 0755 install_db_chroot.sh $MVDIR/bin/install_db_chroot.sh
     install -m 0755 restore_km_db_chroot.sh $MVDIR/bin/restore_km_db_chroot.sh
 #    install -m 0755 restore_default_settings.sh $MVDIR/bin/restore_default_settings.sh
@@ -144,7 +146,8 @@ md5sums=('17d9dd5a097fbbd4dae75dff8e2677ff'
          'b8becf69d4309b938ceba3178c799270'
          '2a7f3b34e522acfd08283b86c8926aba'
          'b596d2e3779a434435bc0f0277b1ba3e'
-         '9b3d200e101d2ba814de00318a41db8f'
+         '6e5639fff82fa2ba76113ac1ab8f2016'
+         'f0376c98a7986897406d393186c0365e'
          '157e73d0f90d7b306aba8f5921aeedd3'
          'f8f803cb5738ce0021cd37c1ab514c45'
          '879c692ebfd86cdd60d93278f1df8041'
diff --git a/abs/core/LinHES-config/xconfig.cron b/abs/core/LinHES-config/xconfig.cron
new file mode 100755
index 0000000..ec44803
--- /dev/null
+++ b/abs/core/LinHES-config/xconfig.cron
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+/usr/MythVantage/bin/xconfig.sh >> /dev/null 2>&1 &
+#remove xconfig.cron from root crontab
+grep -v "* * * * *    /usr/bin/bash /usr/MythVantage/bin/xconfig.cron" /var/spool/cron/root > /var/spool/cron/root2
+mv /var/spool/cron/root2 /var/spool/cron/root
+echo "root" >> /var/spool/cron/cron.update
diff --git a/abs/core/LinHES-config/xconfig.sh b/abs/core/LinHES-config/xconfig.sh
index 52dc952..acc949c 100755
--- a/abs/core/LinHES-config/xconfig.sh
+++ b/abs/core/LinHES-config/xconfig.sh
@@ -8,23 +8,25 @@ for i in ati intel mga savage sis unichrome
 do
     templist=`echo $i-dri xf86-video-$i`
     NVPKGS=`echo $NVPKGS  $templist`
-
 done
+
 BASE=""
 MYTH_RUN_STATUS="1"
 . /etc/profile
 
-#MYTHHOME=$BASE/home/mythtv
+NVIDIA_304xx="$TEMPLATES/xorg/304xx_supported.txt"
+NVIDIA_340xx="$TEMPLATES/xorg/340xx_supported.txt"
+NVIDIA_SUPPORTED="$TEMPLATES/xorg/nvidia_supported.txt"
 
 . /usr/MythVantage/bin/install_functions.sh
 home_check
 
-
 function Xvalues {
-    echo $VGACARDTYPE
+    #echo $VGACARDTYPE
+    VGAFORCED=0
     if [ "x$VGACARDTYPE" = "x" ]
     then
-        CMDLINE=$(cat /proc/cmdline)
+	CMDLINE=$(cat /proc/cmdline)
         echo "$CMDLINE" | grep -q forceXvesa
         if [ $? = 0  ]
         then
@@ -36,17 +38,20 @@ function Xvalues {
             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"
         fi
     else
-       echo "VGACARDTYPE already set"
+        echo "Video card type forced to $VGACARDTYPE"
+        VGAFORCED=1
+        CARDID="NOT_DETECTED"
     fi
-    echo "Detected $VGACARDTYPE as the video card type"
+    VGACARDTYPE=${VGACARDTYPE,,} #make lowercase
 }
 
 function presetupX {
     if  [ "$XIgnoreConfig" = 1 ]
     then
-        echo "Using User supplied X"
+        echo "Using User Supplied X"
         if [ -f "$MYTHHOME/templates/xorg.user" ]
         then
             cp -f "$MYTHHOME/templates/xorg.user" "$XORG_CONF"
@@ -60,14 +65,14 @@ function presetupX {
 }
 
 function nvidia_prepare {
-    for i in mesa-libgl nvidia nvidia-utils nvidia-libgl nvidia-173xx nvidia-173xx-utils nvidia-96xx nvidia-96xx-utils
+    for i in mesa-libgl nvidia nvidia-utils nvidia-libgl opencl-nvidia nvidia-304xx nvidia-304xx-utils nvidia-304xx-libgl opencl-nvidia-304xx nvidia-340xx nvidia-340xx-utils nvidia-340xx-libgl opencl-nvidia-340xx
     do
         pacman --noconfirm -Rdd $i >> $LOGFILE 2>&1
     done
 
     for i in `echo ${NVPKGS}`
     do
-        pacman --noconfirm  -Rc $i >> $LOGFILE 2>&1
+        pacman --noconfirm -Rc $i >> $LOGFILE 2>&1
     done
 }
 
@@ -84,32 +89,113 @@ function pkg_check () {
 }
 
 function nvidia_driver_install {
-    echo "Installing Nvidia driver"
     cp "$TEMPLATES/xorg/xorg.nvidia"  $BASE/etc/X11/xorg.conf.d/20-automv.conf
-    #install latest drivers
-    LIST="nvidia nvidia-libgl nvidia-utils"
-    for i in `echo ${LIST}`
-    do
-        pkg_check $i
-    done
-    #this is used to remove nvidia
-    nvidia_prepare
-    for i in `echo ${LIST}`
-    do
-        pacman -S --noconfirm $i >> $LOGFILE 2>&1
-    done
-    installed=1
+
+    INSTALLED=0
+
+    grep -qi "$CARDID" "$NVIDIA_SUPPORTED"
+    if [[ $? = 0 || $VGAFORCED -eq 1 && $VGACARDTYPE == "nvidia" ]]
+    then
+        LIST="nvidia nvidia-libgl nvidia-utils opencl-nvidia"
+        for i in `echo ${LIST}`
+        do
+            pkg_check $i
+        done
+        echo "Installing current nvidia driver"
+        echo "Installing current nvidia driver" >> $LOGFILE 2>&1
+        nvidia_prepare
+        pacman --noconfirm -S ${LIST} >> $LOGFILE 2>&1
+        if [[ $? != 0 ]]
+        then
+            echo "ERROR: Unable to install current nvidia driver"
+            echo "ERROR: Unable to install current nvidia driver" >> $LOGFILE 2>&1
+        else
+            INSTALLED=1
+        fi
+    fi
+
+    if [ $INSTALLED -eq 0 ]
+    then
+        grep -qi "$CARDID" "$NVIDIA_340xx"
+        if [[ $? = 0 || $VGAFORCED -eq 1 && $VGACARDTYPE == "nvidia-340xx" ]]
+        then
+            LIST="nvidia-340xx nvidia-340xx-libgl nvidia-340xx-utils opencl-nvidia-340xx"
+            for i in `echo ${LIST}`
+            do
+                pkg_check $i
+            done
+            echo "Installing nvidia-340xx driver"
+            echo "Installing nvidia-340xx driver" >> $LOGFILE 2>&1
+            nvidia_prepare
+            pacman --noconfirm -S ${LIST} >> $LOGFILE 2>&1
+            if [[ $? != 0 ]]
+            then
+                echo "ERROR: Unable to install nvidia-340xx driver"
+                echo "ERROR: Unable to install nvidia-340xx driver" >> $LOGFILE 2>&1
+            else
+                INSTALLED=1
+            fi
+        fi
+    fi
+
+    if [ $INSTALLED -eq 0 ]
+    then
+        grep -qi "$CARDID" "$NVIDIA_304xx"
+        if [[ $? = 0 || $VGAFORCED -eq 1 && $VGACARDTYPE == "nvidia-304xx" ]]
+        then
+            LIST="nvidia-304xx nvidia-304xx-libgl nvidia-304xx-utils opencl-nvidia-304xx"
+            for i in `echo ${LIST}`
+            do
+                pkg_check $i
+            done
+            echo "Installing nvidia-304xx driver"
+            echo "Installing nvidia-304xx driver" >> $LOGFILE 2>&1
+            nvidia_prepare
+            pacman --noconfirm -S ${LIST} >> $LOGFILE 2>&1
+            if [[ $? != 0 ]]
+            then
+                echo "ERROR: Unable to install nvidia-304xx driver"
+                echo "ERROR: Unable to install nvidia-304xx driver" >> $LOGFILE 2>&1
+            else
+                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 in any list"
+        echo "  Couldn't find the card id in any list" >> $LOGFILE 2>&1
+        LIST="nvidia nvidia-libgl nvidia-utils opencl-nvidia"
+        for i in `echo ${LIST}`
+        do
+            pkg_check $i
+        done
+        echo "Installing current nvidia driver"
+        echo "Installing current nvidia driver" >> $LOGFILE 2>&1
+        nvidia_prepare
+        pacman --noconfirm -S ${LIST} >> $LOGFILE 2>&1
+        if [[ $? != 0 ]]
+        then
+            echo "ERROR: Unable to install current nvidia driver"
+            echo "ERROR: Unable to install current nvidia driver" >> $LOGFILE 2>&1
+        else
+            INSTALLED=1
+        fi
+    fi
+
     echo "/usr/lib/libXvMCNVIDIA_dynamic.so.1" > "$XVMC_CONFIG"
 }
 
 function vmware_driver_install {
-    echo "Installing VMware driver"
-    echo "Installing VMware driver" >> $LOGFILE 2>&1
     LIST="xf86-input-vmmouse xf86-video-vmware xf86-video-vesa svga-dri mesa-libgl"
     for i in `echo ${LIST}`
     do
         pkg_check $i
     done
+    echo "Installing VMware driver"
+    echo "Installing VMware driver" >> $LOGFILE 2>&1
     #this is used to remove nvidia
     nvidia_prepare
     for i in `echo ${LIST}`
@@ -119,46 +205,26 @@ function vmware_driver_install {
 }
 
 function vesa_driver_install {
-    echo "Installing Vesa driver"
-    echo "Installing Vesa driver" >> $LOGFILE 2>&1
     pkg_check xf86-video-vesa
     pkg_check mesa-libgl
+    echo "Installing Vesa driver"
+    echo "Installing Vesa driver" >> $LOGFILE 2>&1
     #this is used to remove nvidia
     nvidia_prepare
     pacman -S --noconfirm xf86-video-vesa mesa-libgl  >> $LOGFILE 2>&1
 }
 
 function intel_driver_install {
-    echo "Installing Intel driver"
-    echo "Installing Intel driver" >> $LOGFILE 2>&1
     pkg_check xf86-video-intel
     pkg_check mesa-libgl
+    echo "Installing Intel driver"
+    echo "Installing Intel driver" >> $LOGFILE 2>&1
     #this is used to remove nvidia
     nvidia_prepare
     pacman -S --noconfirm xf86-video-intel mesa-libgl >> $LOGFILE 2>&1
     echo "/usr/lib/libIntelXvMC.so.1" > "$XVMC_CONFIG"
 }
 
-# if [ "$Xcategory" = "Nvidia" ]
-# then
-# #Xres=""
-# if [ "$XnVidia1080p" = "1" ]
-# then
-# Xres="${Xres} 1920x1080_60"
-# fi
-# if [ "$XnVidia1080i" = "1" ]
-# then
-# Xres="${Xres} 1920x1080_60i"
-# fi
-# if [ "$XnVidia720p" = "1" ]
-# then
-# Xres="${Xres} 1280x720_60"
-# fi
-# if [ "$XnVidia480p" = "1" ]
-# then
-# Xres="${Xres} 720x480_60"
-# fi
-
 function set_res {
     echo "    Setting modeline to ${Xres}"
     echo "    Setting modeline to ${Xres}" >> $LOGFILE 2>&1
@@ -176,13 +242,12 @@ function set_res {
 EOF
 }
 
-
 function setupX {
     Xvalues
     if [ x = x ]
     then
         case $VGACARDTYPE in
-            NVIDIA|nVidia|nvidia)
+            nvidia|nvidia-340xx|nvidia-304xx)
                     nvidia_driver_install
                     if [ \"$Xres\" = "Auto" ]
                     then
@@ -197,7 +262,7 @@ function setupX {
                     fi
                 ;;
 
-            VMware)
+            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
@@ -211,9 +276,9 @@ function setupX {
                     else
                         rm -f /etc/X11/xorg.conf.d/30-screen.conf
                     fi
-                    ;;
+                ;;
 
-            Intel|intel)
+            intel)
                     intel_driver_install
                     cp $TEMPLATES/xorg/xorg.intel  /etc/X11/xorg.conf.d/20-automv.conf
                     if [ ${Xres} != "Auto" ]
@@ -222,9 +287,13 @@ function setupX {
                     else
                         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
+            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."
+                  fi
                   vesa_driver_install
                   cp $TEMPLATES/xorg/xorg.vesa  /etc/X11/xorg.conf.d/20-automv.conf
                   if [ ${Xres} != "Auto" ]
@@ -247,7 +316,17 @@ function setupX {
 
 }
 
-
+function pacman_wait {
+    if [ -f /var/lib/pacman/db.lck ]
+    then
+        echo "Pacman is running and must quit before xconfig.sh can continue."
+        echo "  Waiting for pacman to quit..."
+        while [ -f /var/lib/pacman/db.lck ]
+        do
+	    sleep 5
+        done
+    fi
+}
 #---------------------------------------------------------------------------------
 #MAIN
 
@@ -267,7 +346,6 @@ then
 fi
 
 
-
 if [ -f /etc/systemconfig ]
 then
     . /etc/systemconfig
@@ -291,8 +369,9 @@ then
 fi
 
 
-
 XORG_CONF="/etc/X11/xorg.conf"
 XVMC_CONFIG="/etc/X11/XvMCConfig"
 
+
+pacman_wait
 presetupX
-- 
cgit v0.12

