source: src-qt4/pc-xgui/resources/bin/rundetect.sh @ 5e26f0b

releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 5e26f0b was 5e26f0b, checked in by Kris Moore <kris@…>, 6 months ago

Add a important fix to video detection. For some reason on 10.x Xorg isn't detecting
video cards with difference BusID settings... This causes chaos when the board
is on a weird pci device, or has multiple video devices installed.

Now we will first probe for vgapci0, and setup an xorg.conf based upon that using
the correct BusID value.

If that fails, we will then test vgapci1, and lastly fallback to vesa mode

  • Property mode set to 100755
File size: 8.3 KB
Line 
1#!/bin/sh
2# xorg-gui startup script
3# Copyright 2009 PC-BSD Software
4# Descr: This script is called by /usr/local/etc/rc.d/gdm to run the time X setup
5#        wizard. It allows the user to select a resolution / refresh rate and
6#        test it before continuing into the normal KDE GUI.
7###############################################################################
8# Configuration Settings
9
10# Set all our path variables
11PATH="/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/bin:/usr/local/sbin"
12export PATH
13
14# Set the home directory for startx to run properly
15HOME="/root" ; export HOME
16
17# Set the log file location
18XLOG="/tmp/xsetup.log" ; export XLOG
19
20# Program Directory
21PROGDIR="/usr/local/share/pcbsd/xorg-gui" ; export PROGDIR
22
23XGUITMP="/tmp/.xgui" ; export XGUITMP
24
25TERM="cons25" ; export TERM
26clear
27
28###############################################################################
29# Start the script now
30
31cfg_card_busid()
32{
33  whichcard="$1"
34
35  # This is a script to try an xorg.conf file configured to use the second vgapci1 device
36  # For most systems this wont do anything, but on a number of newer hybrid
37  # intel/amd or intel/nvidia laptops this may fix a problem where the intel card (which works)
38  # is the secondary pcivga1 device, and the non-functional AMD/NVIDIA optimus  shows up first.
39  inCard=0
40  pciconf -lv > /tmp/.pciconf.$$
41  while read line
42  do
43    echo $line | grep -q "^vgapci"
44    if [ $? -eq 0 ] ; then
45       curCard=`echo $line | cut -d "@" -f 1 | sed 's|vgapci||g'`
46       busID="`echo $line | cut -d ':' -f 2-4`"
47       inCard=1
48       continue
49    fi
50
51    echo $line | grep -q "subclass"
52    if [ $? -eq 0 ] ; then inCard=0; continue; fi
53
54    if [ $inCard -eq 1 ] ; then
55       echo $line | grep -q "vendor"
56       if [ $? -eq 0 ]; then
57          case $curCard in
58             0) card1=`echo $line | cut -d "'" -f 2`
59                card1bus="$busID"
60                ;;
61             1) card2=`echo $line | cut -d "'" -f 2`
62                card2bus="$busID"
63                ;;
64             *) ;;
65          esac
66       fi
67    fi
68  done < /tmp/.pciconf.$$
69  rm /tmp/.pciconf.$$
70
71  # Which card are we configuring
72  if [ "$whichcard" = "1" ] ; then
73    cfgCard="$card1"
74    cfgCardBusID="$card1bus"
75  else
76    cfgCard="$card2"
77    cfgCardBusID="$card2bus"
78  fi
79
80  # No detected, return 1
81  if [ -z "$cfgCard" ] ; then return 1; fi
82
83  # Is this an Intel chipset?
84  echo "$cfgCard" | grep -q -i -e "intel"
85  if [ $? -eq 0 ] ; then
86     driver="intel"
87  fi
88  echo "$cfgCard" | grep -q -i -e "nvidia"
89  if [ $? -eq 0 ] ; then
90     driver="nvidia"
91  fi
92
93  # Found a card, lets try an xorg config for it
94  cp ${PROGDIR}/cardDetect/XF86Config.default /etc/X11/xorg.conf
95  if [ -n "$driver" ] ; then
96    echo "
97Section \"Device\"
98        Identifier      \"Card0\"
99        Driver          \"$driver\"
100        BusID           \"${cfgCardBusID}\"
101EndSection
102  " >> /etc/X11/xorg.conf
103  else
104    echo "
105Section \"Device\"
106        Identifier      \"Card0\"
107        BusID           \"${cfgCardBusID}\"
108EndSection
109  " >> /etc/X11/xorg.conf
110  fi
111
112  return 0
113}
114
115# Init our tmpdir
116if [ ! -d "${XGUITMP}" ] ; then
117        mkdir -p ${XGUITMP}
118fi
119
120echo "`clear`" >/dev/console
121
122# Move any existing xorg.conf file
123if [ -e "/etc/X11/xorg.conf" ] ; then
124   mv /etc/X11/xorg.conf /etc/X11/xorg.conf.bak
125fi
126
127echo "`clear`" >/dev/console
128echo "Please wait... Start X-Configuration Utility" >/dev/console
129
130# Check if we need to save an existing .xinitrc file
131if [ -e "/root/.xinitrc" ] ; then
132 mv /root/.xinitrc /root/.xinitrc.xbak
133fi
134
135# Check if we need to move the .fluxbox profile
136if [ -e "/root/.fluxbox" ] ; then
137  rm -rf /root/.fluxbox.xbak 2>/dev/null
138  mv /root/.fluxbox /root/.fluxbox.xbak 2>/dev/null
139fi
140
141rm -rf /root/.fluxbox
142cp -R ${PROGDIR}/conf/.fluxbox /root/.fluxbox
143
144cd /root/
145
146
147# Recreate our log file
148if [ -e "${XLOG}" ] ; then
149  mv ${XLOG} ${XLOG}.old
150fi
151
152# Create an empty log file for appending
153echo "" > ${XLOG}
154
155
156# Remove any files from a previous attempt
157rm ${XGUITMP}/.canceled >/dev/null 2>/dev/null
158rm ${XGUITMP}/.selected >/dev/null 2>/dev/null
159rm ${XGUITMP}/.rerunxsetup >/dev/null 2>/dev/null
160rm ${XGUITMP}/.done >/dev/null 2>/dev/null
161rm ${XGUITMP}/.failed >/dev/null 2>/dev/null
162
163
164# Set the attempt number to 0
165ATTEMPT="0"
166
167###############################################################################
168# Start the detection loop
169
170while
171i=1
172do
173
174  # Save the previous xorg.conf file for troubleshooting
175  if [ -e "/etc/X11/xorg.conf" ] ; then mv /etc/X11/xorg.conf /etc/X11/xorg.conf.previous ; fi
176
177  #  Don't keep displaying the autores question
178  AUTORES="NO"
179
180  if [ "${ATTEMPT}" = "0" ] ; then
181
182    # First check if we are running as a VirtualBox guest
183    pciconf -lv | grep -q "VirtualBox"
184    if [ $? -eq 0 ] ; then cp ${PROGDIR}/cardDetect/xorg.conf.virtualbox /etc/X11/xorg.conf; fi
185
186    # Check if we are supposed to run in vesa mode
187    xvesa="NO"
188    v=`kenv xvesa`
189    if [ $? -eq 0 ]; then xvesa=$v ; fi
190
191    # Check if user requested to run in vesa mode specifically and do it
192    if [ "$xvesa" = "YES" ] ; then
193      echo "`clear`" >/dev/console
194      echo "Using failsafe VESA 1024x768 mode..." >/dev/console
195      cp ${PROGDIR}/cardDetect/XF86Config.compat /etc/X11/xorg.conf
196    else
197      cfg_card_busid "1"
198      if [ $? -ne 0 ] ; then
199        # Check if this system has a nvidia device, and run nvidia-xconfig
200        kldstat | grep -q 'nvidia'
201        if [ $? -eq 0 ] ; then
202           echo "Detected NVIDIA, creating xorg.conf"
203           nvidia-xconfig 2>/dev/null
204        fi
205      fi
206      AUTORES="YES"
207    fi
208  elif [ "${ATTEMPT}" = "1" ] ; then
209    cfg_card_busid "2"
210
211    # Failed to start X
212    # Now lets have it try some magic itself
213    rm /etc/X11/xorg.conf 2>/dev/null
214
215    echo "`clear`" >/dev/console
216    echo "ERROR: Failed to start X with default video card... Trying secondary mode..." >/dev/console
217  else
218    # Still failed, drop to VESA failsafe
219    echo "`clear`" >/dev/console
220    echo "Detected settings failed... Using failsafe VESA 1024x768 mode..." >/dev/console
221    rm /etc/X11/xorg.conf
222    cp ${PROGDIR}/cardDetect/XF86Config.compat /etc/X11/xorg.conf
223  fi
224
225  # Check if the previous attempt failed
226  if [ -e "${XGUITMP}/.failed" ]
227  then
228  # Failed display, show the failed screen
229    rm ${XGUITMP}/.failed
230    cp ${PROGDIR}/scripts/xinit-failed /root/.xinitrc
231    chmod 755 /root/.xinitrc
232  elif [ "$AUTORES" = "YES" ] ; then
233  # First time running, ask user if they want to use auto-detected resolution
234    cp ${PROGDIR}/scripts/xinit-autodetect /root/.xinitrc
235    chmod 755 /root/.xinitrc
236  else
237  # Did not fail, create normal config
238    cp ${PROGDIR}/scripts/xinit-displaywiz /root/.xinitrc
239    chmod 755 /root/.xinitrc
240  fi
241
242  echo "`clear`" >/dev/console
243  echo "Please wait... Starting X..." >/dev/console
244  sleep 1
245  # Start the X gui
246  /usr/local/bin/startx 2>>${XLOG}
247
248  # The user canceled the dialog, and chose to use the default
249  if [ -e "${XGUITMP}/.canceled" ] ; then break ; fi
250
251  # Check if a new version of xorg.conf is ready to be tested
252  if [ -e "${XGUITMP}/.xsettings.sh" ]
253  then
254    rm ${XGUITMP}/.selected >/dev/null 2>/dev/null
255
256    #### Create the new XF86Config file with the user settings
257    echo "`clear`" >/dev/console
258    echo "Generating new Xorg configuration file..." >/dev/console
259    ${PROGDIR}/bin/setupconf.sh >>${XLOG} 2>>${XLOG}
260
261    ##### Copy the xinitrc file
262    cp ${PROGDIR}/scripts/xinit-check /root/.xinitrc
263    chmod 755 /root/.xinitrc
264
265    echo "`clear`" >/dev/console
266    echo "Please wait... Starting X..." >/dev/console
267    sleep 1
268    /usr/local/bin/startx 2>>${XLOG}
269  fi
270
271  if [ -e "${XGUITMP}/.selected" ] ; then
272    break
273  else
274    echo "failed" > ${XGUITMP}/.failed
275  fi
276
277  # Check if the X startup was a success
278  if [ ! -e "${XGUITMP}/.xstartupsuccess" ] ; then
279    ATTEMPT="`expr $ATTEMPT + 1`"
280    rm ${XGUITMP}/.failed
281  else
282    rm ${XGUITMP}/.xstartupsuccess
283  fi
284
285  # Removed any saved settings file
286  rm ${XGUITMP}/.xsettings.sh
287
288done
289
290
291rm /root/.xinitrc >/dev/null 2>/dev/null
292# Check if we need to save an existing .xinitrc file
293if [ -e "/root/.xinitrc.xbak" ] ; then
294   mv /root/.xinitrc.xbak /etc/.xinitrc
295fi
296
297# Check if we need to move the .fluxbox profile
298if [ -e "/root/.fluxbox.xbak" ] ; then
299  rm -rf /root/.fluxbox >/dev/null 2>/dev/null
300  mv /root/.fluxbox.xbak /root/.fluxbox
301fi
302
303rm ${XGUITMP}/.rerunxsetup >/dev/null 2>/dev/null
304rm ${XGUITMP}/.skipauto >/dev/null 2>/dev/null
305echo "`clear`" >/dev/console
306echo "Preparing to start the desktop..." >/dev/console
307sleep 1
308exit 0
Note: See TracBrowser for help on using the repository browser.