From f92249d347c09c6936074b94878d0892f13cdced Mon Sep 17 00:00:00 2001
From: Tom Culliton <culliton@x2.(none)>
Date: Sun, 25 Jan 2009 15:04:11 -0500
Subject: Cleanup a bunch of unquote variables which were causing interesting
 bugs. Did a general whitespace cleanup to cure mixed space and tab problems.
 Added support for setting an appropriate XvMC library. Started on better
 support for Via S3 video chips.

---
 abs/core-testing/LinHES-config/xconfig.sh | 392 ++++++++++++++++--------------
 1 file changed, 213 insertions(+), 179 deletions(-)

diff --git a/abs/core-testing/LinHES-config/xconfig.sh b/abs/core-testing/LinHES-config/xconfig.sh
index fdb6030..1f1d0f0 100755
--- a/abs/core-testing/LinHES-config/xconfig.sh
+++ b/abs/core-testing/LinHES-config/xconfig.sh
@@ -7,241 +7,276 @@ NVIDIA_96XX="$TEMPLATES/xorg/96xx_supported.txt"
 
 function Xvalues {
     CMDLINE=$(cat /proc/cmdline)
-    echo $CMDLINE |grep -q forceXvesa
+    echo "$CMDLINE" | grep -q forceXvesa
     if [ $? = 0 ]
     then
         VGACARDTYPE=vesa
     else
-        VGACARDTYPE=`lspci|grep -i vga|sort -r|head -n 1| cut -d: -f3|cut -d" " -f 2`
-        VGAPCIID=`lspci|grep -i 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`
+        VGACARDTYPE=`lspci | grep -i vga | sort -r | head -n 1 | cut -d: -f3 | cut -d" " -f2`
+        VGAPCIID=`lspci | grep -i 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`
     fi
-    echo $VGACARDTYPE
-    currentmode=`cat $BASE/etc/X11/xorg.conf |grep Modes|awk -Fs ' { print $2 } '`
+    echo "$VGACARDTYPE"
+    currentmode=`cat "$BASE/etc/X11/xorg.conf" | grep Modes | awk -Fs '{ print $2 }'`
 }
 
 function presetupX {
-if [ x$XUseAdvanced =  x1 ]
-then
-    if  [ x$XIgnoreConfig  = x1 ]
+    if [ "$XUseAdvanced" = 1 ]
     then
-        echo "Using User supplied X"
-        if [ -f  $BASE/data/home/mythtv/templates/xorg.user ]
+        if  [ "$XIgnoreConfig" = 1 ]
         then
-            cp -f  $BASE/data/home/mythtv/templates/xorg.user  $XORG_CONF
+            echo "Using User supplied X"
+            if [ -f "$BASE/data/home/mythtv/templates/xorg.user" ]
+            then
+                cp -f "$BASE/data/home/mythtv/templates/xorg.user" "$XORG_CONF"
+            else
+                echo "Didn't find the file"
+                echo "Copy your config file to $BASE/data/home/mythtv/templates/xorg.use" >> "$XORG_CONF"
+            fi
         else
-            echo "Didn't find the file"
-            echo "Copy your config file to $BASE/data/home/mythtv/templates/xorg.use  " >>  $XORG_CONF
+            setupAdvancedX
         fi
     else
-    setupAdvancedX
+        if [ -f /etc/sysconfig/IGNORE_X ]
+        then
+            echo "Will not run xconfig.sh due to presence of /etc/sysconfig/IGNORE_X"
+        else
+            setupX
+        fi
     fi
-else
-    if [ -f /etc/sysconfig/IGNORE_X ]
-    then
-        echo "Will not run xconfig.sh due to presence of /etc/sysconfig/IGNORE_X"
-    else
-        setupX
-      fi
-fi
-
 }
 
 function setupAdvancedX {
-echo "#doing the advanced" > /tmp/options
-        Xcatagory=` echo $Xresadvanced |cut -d_ -f1`
-        Xres=` echo $Xresadvanced |cut -d_ -f2`
-        echo $Xcatagory
-        if [ x$Xcatagory = "xNvidia" ]
+    echo "#doing the advanced" > /tmp/options
+    Xcategory=`echo "$Xresadvanced" | cut -d_ -f1`
+    Xres=`echo "$Xresadvanced" | cut -d_ -f2`
+    echo "$Xcategory"
+    if [ "$Xcategory" = "Nvidia" ]
+    then
+        Xres=""
+        if [ "$XnVidia1080p" = "1" ]
         then
-            Xres=""
-            if [  $XnVidia1080p = "1" ]
-            then
-                Xres="${Xres} \"1920x1080_60\""
-            fi
-            if [  $XnVidia1080i = "1" ]
-            then
-                Xres="${Xres}  \"1920x1080_60i\""
-            fi
-            if [  $XnVidia720p = "1" ]
+            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
+            ML="\t Modes ${Xres}"
+    else
+
+    ML="\t Modes \"${Xres}\""
+    fi
+#    echo $ML
+    case $Xcardtype in
+        NVIDIA|nVidia)
+            case $Xconnection in
+                DVI)    ConnectedMonitor=DFP ;;
+                vga)    ConnectedMonitor=CRT;;
+                Auto)   ConnectedMonitor=Auto;;
+                TV)     ConnectedMonitor=TV
+                        echo "Option \"TVStandard\" \"$XTVstandard\""  >>/tmp/options
+                        echo "Option \"TVOutFormat\" \"$XTVconnection\"" >> /tmp/options
+                    ;;
+            esac
+            if [ "$ConnectedMonitor" = Auto ]
             then
-                Xres="${Xres}  \"1280x720_60\""
+                echo "auto connection"
+            else
+                echo "Option \"ConnectedMonitor\" \"$ConnectedMonitor\"" >> /tmp/options
+                echo "Option \"FlatPanelProperties\" \"Scaling = centered, Dithering = enabled\"" >> /tmp/options
+                echo "Option \"DigitalVibrance\" \"0\"" >> /tmp/options
             fi
-            if [  $XnVidia480p = "1" ]
+
+            if  [ "$XignoreEDID" = 1 ]
             then
-                Xres="${Xres}  \"720x480_60\""
+                EDIDvalue=true
+                EDIDFREQ=false
+                DS="    DisplaySize $XDisplaysize"
+                HS="    HorizSync   $XHsync"
+                VR="    VertRefresh $XVrefresh"
+            else
+                EDIDvalue=false
+                EDIDFREQ=true
+                DS="# Display size edid used "
+                HS="# Hsync edid used "
+                VR="# Vertrefresh edid used "
             fi
-                ML="\t Modes ${Xres}"
-        else
-
-        ML="\t Modes \"${Xres}\""
-        fi
-#        echo $ML
-    case $Xcardtype in
-        NVIDIA|nVidia )
-                        case $Xconnection in
-                                DVI)    ConnectedMonitor=DFP ;;
-                                vga)    ConnectedMonitor=CRT;;
-                                Auto)   ConnectedMonitor=Auto;;
-                                TV)    ConnectedMonitor=TV
-                                        echo "Option \"TVStandard\" \"$XTVstandard\""  >>/tmp/options
-                                        echo "Option \"TVOutFormat\" \"$XTVconnection\"" >> /tmp/options
-                                        ;;
-                            esac
-                            if [ $ConnectedMonitor = Auto ]
-                            then
-                            echo "auto connection"
-                            else
-                            echo    "Option \"ConnectedMonitor\" \"$ConnectedMonitor\"" >> /tmp/options
-                            echo    "Option \"FlatPanelProperties\" \"Scaling = centered, Dithering = enabled\"" >> /tmp/options
-                            echo    "Option \"DigitalVibrance\" \"0\"" >> /tmp/options
-                            fi
+            echo "Option  \"UseEdidFreqs\" \"$EDIDFREQ\"" >> /tmp/options
+            echo "Option  \"IgnoreEDID\" \"$EDIDvalue\"" >> /tmp/options
 
-                            if  [ x$XignoreEDID = x1 ]
-                                    then
-                                        EDIDvalue=true
-                                        EDIDFREQ=false
-                                        DS="     DisplaySize $XDisplaysize"
-                                        HS="    HorizSync  $XHsync"
-                                        VR="    VertRefresh $XVrefresh"
-                                    else
-                                        EDIDvalue=false
-                                        EDIDFREQ=true
-                                        DS="# Display size edid used "
-                                        HS="#Hsync edid used "
-                                        VR="#Vertrefresh edid used "
-
-                            fi
-                            echo   "Option  \"UseEdidFreqs\" \"$EDIDFREQ\"" >> /tmp/options
-                            echo   "Option  \"IgnoreEDID\" \"$EDIDvalue\"" >> /tmp/options
-
-
-                sed -e "s/^.*Modes.*$/${ML}/" \
-                    -e "/INSERT MODELINE/r  $TEMPLATES/xorg/modeline.$Xcatagory" \
-                    -e "s/^.*DisplaySize.*$/  $DS/" \
-                    -e "s/^#.*HorizSync.*$/ $HS/g" \
-                    -e "s/^#.*VertRefresh.*$/ $VR/g" \
-                    -e "/INSERT HERE/r /tmp/options"  $TEMPLATES/xorg/xorg.conf.nvidia  > $XORG_CONF
 
+            sed -e "s/^.*Modes.*$/${ML}/" \
+                -e "/INSERT MODELINE/r  $TEMPLATES/xorg/modeline.$Xcategory" \
+                -e "s/^.*DisplaySize.*$/ $DS/" \
+                -e "s/^#.*HorizSync.*$/ $HS/g" \
+                -e "s/^#.*VertRefresh.*$/ $VR/g" \
+                -e "/INSERT HERE/r /tmp/options" "$TEMPLATES/xorg/xorg.conf.nvidia" > "$XORG_CONF"
             ;;
+
         ati|ATI)
-                case $Xconnection in
-                        DVI)    ConnectedMonitor="tmds1,nocrt1,notv";;
-                        VGA)    ConnectedMonitor="crt1,notmds1,notv" ;;
-                        TV)    ConnectedMonitor="tv,nocrt1,notmds1"
-                                echo "Option \"TVStandard\" \"$XTVstandard\""  >>/tmp/options
-                                echo "Option \"TVFormat\" \"$XTVconnection\"" >> /tmp/options
-                                ;;
-                        esac
-                if  [ x$XignoreEDID = x1 ]
-                        then
-                            DS="     DisplaySize $XDisplaysize"
-                            HS="    HorizSync  $XHsync"
-                            VR="    VertRefresh $XVrefresh"
-                        else
-                            DS="# Display size edid used "
-                            HS="#Hsync edid used "
-                            VR="#Vertrefresh edid used "
-                    fi
+            case $Xconnection in
+                DVI)    ConnectedMonitor="tmds1,nocrt1,notv";;
+                VGA)    ConnectedMonitor="crt1,notmds1,notv" ;;
+                TV)     ConnectedMonitor="tv,nocrt1,notmds1"
+                        echo "Option \"TVStandard\" \"$XTVstandard\""  >>/tmp/options
+                        echo "Option \"TVFormat\" \"$XTVconnection\"" >> /tmp/options
+                    ;;
+            esac
+            if  [ "$XignoreEDID" = 1 ]
+            then
+                DS="    DisplaySize $XDisplaysize"
+                HS="    HorizSync   $XHsync"
+                VR="    VertRefresh $XVrefresh"
+            else
+                DS="# Display size edid used "
+                HS="# Hsync edid used "
+                VR="# Vertrefresh edid used "
+            fi
 
-                echo "Option \"ForceMonitors\" \"$ConnectedMonitor\"" >> /tmp/options
+            echo "Option \"ForceMonitors\" \"$ConnectedMonitor\"" >> /tmp/options
 
-                sed -e "s/^.*Modes.*$/\t $ML/" \
-                -e "/INSERT MODELINE/r  $TEMPLATES/xorg/modeline.$Xcatagory" \
-                -e "s/^.*DisplaySize.*$/  $DS/" \
+            sed -e "s/^.*Modes.*$/\t $ML/" \
+                -e "/INSERT MODELINE/r  $TEMPLATES/xorg/modeline.$Xcategory" \
+                -e "s/^.*DisplaySize.*$/ $DS/" \
                 -e "s/^#.*HorizSync.*$/ $HS/g" \
                 -e "s/^#.*VertRefresh.*$/ $VR/g" \
-                -e "/INSERT HERE/r /tmp/options"  $TEMPLATES/xorg/xorg.conf.ati  > $XORG_CONF
-                ;;
+                -e "/INSERT HERE/r /tmp/options" "$TEMPLATES/xorg/xorg.conf.ati"  > "$XORG_CONF"
+            ;;
 
-        via|VIA|Via) echo "no via here"   ;;
+        via|VIA|Via|S3)
+            # Need to add appropriate Modules, Device and DRI sections
+            # See the http://www.mythtv.org/wiki/XvMC wiki page
+            echo "no via here"
+            ;;
 
-        *)    echo "unknown card type"        ;;
+        *)
+            echo "unknown card type"
+            ;;
     esac
 }
 
 
-
 function setupX {
     Xvalues
-    #echo "$currentmode  ____    ${Xres}"
-    #if [ !  x${currentmode} = x\"${Xres}\" ]
-    if [   x = x ]
+    #echo "$currentmode  ____   ${Xres}"
+    #if [ "${currentmode}" != \"${Xres}\" ]
+    if [ x = x ]
     then
         case $VGACARDTYPE in
-            nVidia )
-                    sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" $TEMPLATES/xorg/xorg.conf.nvidia > $XORG_CONF
-                    if [ !  x$TESTMODE = "xtest" ]
+            nVidia)
+                sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$TEMPLATES/xorg/xorg.conf.nvidia" > "$XORG_CONF"
+                if [ "$TESTMODE" != "test" ]
+                then
+                    #nvidia check right here
+                    grep -qi "$CARDID" "$NVIDIA_96XX"
+                    if [ $? = 0 ]
                     then
-			    #nvidia check right here
-                            grep -qi $CARDID $NVIDIA_96XX
-                            if [ $? = 0 ]
-                            then
-                                #install 96xx drivers
-                                echo "installing nvidia 96xx drivers"
-                                pacman --noconfirm  -R $NVPKGS > /dev/null 2>&1
-                                pacman --noconfirm  -S nvidia-96xx nvidia-96xx-utils  > /dev/null 2>&1
-                            else
-                                #install latest drivers
-                                echo "installing current nvidia drivers"
-                                pacman --noconfirm  -R $NVPKGS > /dev/null 2>&1
-                                pacman --noconfirm  -S nvidia nvidia-utils > /dev/null 2>&1
-                            fi
+                        #install 96xx drivers
+                        echo "installing nvidia 96xx drivers"
+                        pacman --noconfirm  -R $NVPKGS > /dev/null 2>&1
+                        pacman --noconfirm  -S nvidia-96xx nvidia-96xx-utils  > /dev/null 2>&1
+                    else
+                        #install latest drivers
+                        echo "installing current nvidia drivers"
+                        pacman --noconfirm  -R $NVPKGS > /dev/null 2>&1
+                        pacman --noconfirm  -S nvidia nvidia-utils > /dev/null 2>&1
                     fi
-                                ;;
-      #      VMware )
-      #              sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" $TEMPLATES/xorg/xorg.conf.vmware > $XORG_CONF
+                fi
+	        echo "/usr/lib/libXvMCNVIDIA_dynamic.so.1" > "$XVMC_CONFIG"
+                ;;
+
+      #      VMware)
+      #              sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$TEMPLATES/xorg/xorg.conf.vmware" > "$XORG_CONF"
       #              ;;
 
-            VIA )
-                    sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" $TEMPLATES/xorg/xorg.conf.via > $XORG_CONF
-                    if [ ! x$TESTMODE = "xtest" ]
+            VIA|S3)
+                # There are actually multiple options here
+                # xf86-video-openchrome
+                # xf86-video-unichrome
+                # There is also a seperate driver for the Unichrome Pro
+                sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$TEMPLATES/xorg/xorg.conf.via" > "$XORG_CONF"
+                if [ "$TESTMODE" != "test" ]
+                then
+                    if [ "$OPENCHROME" = "1" ]
                     then
                         pacman --noconfirm  -R nvidia nvidia-utils > /dev/null 2>&1
-                        pacman --noconfirm  -S libgl > /dev/null 2>&1
+                        pacman --noconfirm  -S libgl unichrome-dri xf86-video-openchrome > /dev/null 2>&1
+                    else
+                        pacman --noconfirm  -R nvidia nvidia-utils > /dev/null 2>&1
+                        pacman --noconfirm  -S libgl unichrome-dri xf86-video-unichrome > /dev/null 2>&1
                     fi
-
-                    ;;
-            Intel)
-                    sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" $TEMPLATES/xorg/xorg.conf.intel > $XORG_CONF
-                    if [ !  x$TESTMODE = "xtest" ]
+                fi
+                # I'm making educated guesses here...
+                if lspci | grep "VGA" | grep -qi "Unichrome Pro"
+                then
+                    if [ -f "/usr/lib/libchromeXvMCPro.so.1" ]
                     then
-                            pacman --noconfirm -R nvidia-utils > /dev/null 2>&1
-                            pacman --noconfirm -S libgl > /dev/null 2>&1
+	                echo "/usr/lib/libchromeXvMCPro.so.1" > "$XVMC_CONFIG"
+                    else
+	                echo "/usr/lib/libviaXvMCPro.so.1" > "$XVMC_CONFIG"
                     fi
-                                ;;
+                else
+                    if [ -f "/usr/lib/libchromeXvMC.so.1" ]
+                    then
+	                echo "/usr/lib/libchromeXvMC.so.1" > "$XVMC_CONFIG"
+                    else
+                        echo "/usr/lib/libviaXvMC.so.1" > "$XVMC_CONFIG"
+                    fi
+                fi
+                ;;
 
-        vesa)  sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" $TEMPLATES/xorg/xorg.conf.vesa > $XORG_CONF
-        ;;
-    *)
-            XCONF=/root/xorg.conf.new
-            XCONFB=/etc/X11/xorg.conf.install
-            X -configure
-            if [ -f $XCONF ]
-            then
-                echo "Using $XCONF"
-                grep -v Modes  $XCONF | sed -e "/Depth.*16/a Modes \"${Xres}\" " -e "/Depth.*24/a Modes \"${Xres}\""     -e 's/dev\/mouse/dev\/psaux/g'> $XORG_CONF
+            Intel)
+                sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$TEMPLATES/xorg/xorg.conf.intel" > "$XORG_CONF"
+                if [ "$TESTMODE" != "test" ]
+                then
+                    pacman --noconfirm -R nvidia-utils > /dev/null 2>&1
+                    pacman --noconfirm -S libgl > /dev/null 2>&1
+                fi
+	        echo "/usr/lib/libIntelXvMC.so.1" > "$XVMC_CONFIG"
+                ;;
 
-            elif [ -f $XCONFB ]
-            then
-                echo "Using $XCONFB"
-               sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" $XCONFB > $XORG_CONF
-            else
-                echo "Xorg configuration failed"
-            fi
-            rm -f $XCONF 2>&1 > /dev/null
-        ;;
+            vesa)
+                sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$TEMPLATES/xorg/xorg.conf.vesa" > "$XORG_CONF"
+                ;;
+
+            *)
+                XCONF=/root/xorg.conf.new
+                XCONFB=/etc/X11/xorg.conf.install
+                X -configure
+                if [ -f "$XCONF" ]
+                then
+                    echo "Using $XCONF"
+                    grep -v Modes "$XCONF" | sed -e "/Depth.*16/a Modes \"${Xres}\" " -e "/Depth.*24/a Modes \"${Xres}\""     -e 's/dev\/mouse/dev\/psaux/g'> "$XORG_CONF"
+                elif [ -f "$XCONFB" ]
+                then
+                    echo "Using $XCONFB"
+                    sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$XCONFB" > "$XORG_CONF"
+                else
+                    echo "Xorg configuration failed"
+                fi
+                rm -f "$XCONF" 2>&1 > /dev/null
+                ;;
         esac
     fi
 
 }
 
 #MAIN
-TESTMODE=$1
-if [ x$TESTMODE = "xtest" ]
+TESTMODE="$1"
+if [ "$TESTMODE" = "test" ]
 then
     XORG_CONF="/tmp/xorg.conf.test"
+    XVMC_CONFIG="/tmp/XvMCConfig.test"
     XUseAdvanced="1"
     XIgnoreConfig="${2}"
     Xcardtype="${3}"
@@ -254,14 +289,13 @@ then
     XTVconnection="${10}"
     XDisplaysize="${11}"
 else
-    if [ -f   /etc/systemconfig ]
+    if [ -f /etc/systemconfig ]
     then
         . /etc/systemconfig
     else
         Xres="800x600"
     fi
     XORG_CONF="/etc/X11/xorg.conf"
+    XVMC_CONFIG="/etc/X11/XvMCConfig"
 fi
 presetupX
-
-
-- 
cgit v0.12

