source: src-qt4/pc-xgui/resources/bin/rundetect.sh @ 1a4b7a1

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

Add a bit more verbosity when we detect a hybrid intel laptop

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