source: overlays/install-overlay/root/functions.sh @ 1a4b7a1

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

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

  • Property mode set to 100755
File size: 3.7 KB
Line 
1#!/bin/sh
2# Functions we source for starting the install / live mode
3###########################################################
4
5detect_x() 
6{
7  # Check if the user requested VESA mode
8  xvesa="NO"
9  v=`/bin/kenv xvesa 2>/dev/null`
10  if [ $? -eq 0 ]; then
11        xvesa=$v
12  fi
13
14  # If we are starting in VESA only mode
15  if [ "$xvesa" = "YES" ]; then
16    cp /root/cardDetect/XF86Config.compat /etc/X11/xorg.conf
17    return
18  fi
19
20  # First check if we are running as a VirtualBox guest
21  pciconf -lv | grep -q "VirtualBox"
22  if [ $? -eq 0 ] ; then cp /root/cardDetect/xorg.conf.virtualbox /etc/X11/xorg.conf ; return; fi
23
24  # Try the second card, since many optimus / amd hybrids have Intel on secondary
25  cfg_second_card
26  if [ $? -ne 0 ] ; then
27    # Check if this system has a nvidia device, and run nvidia-xconfig
28    kldstat | grep -q 'nvidia'
29    if [ $? -eq 0 ] ; then
30       echo "Detected NVIDIA, creating xorg.conf"
31       nvidia-xconfig 2>/dev/null
32    fi
33  fi
34
35
36}
37
38cfg_second_card()
39{
40  # This is a script to try an xorg.conf file configured to use the second vgapci1 device
41  # For most systems this wont do anything, but on a number of newer hybrid
42  # intel/amd or intel/nvidia laptops this may fix a problem where the intel card (which works)
43  # is the secondary pcivga1 device, and the non-functional AMD/NVIDIA optimus  shows up first.
44
45  inCard=0
46  pciconf -lv > /tmp/.pciconf.$$
47  while read line
48  do
49    echo $line | grep -q "^vgapci"
50    if [ $? -eq 0 ] ; then
51       curCard=`echo $line | cut -d "@" -f 1 | sed 's|vgapci||g'`
52       busID="`echo $line | cut -d ':' -f 2-4`"
53       inCard=1
54       continue
55    fi
56
57    echo $line | grep -q "subclass"
58    if [ $? -eq 0 ] ; then inCard=0; continue; fi
59
60    if [ $inCard -eq 1 ] ; then
61       echo $line | grep -q "vendor"
62       if [ $? -eq 0 ]; then
63          case $curCard in
64             0) card1=`echo $line | cut -d "'" -f 2`
65                card1bus="$busID"
66                ;;
67             1) card2=`echo $line | cut -d "'" -f 2`
68                card2bus="$busID"
69                ;;
70             *) ;;
71          esac
72       fi
73    fi
74  done < /tmp/.pciconf.$$
75  rm /tmp/.pciconf.$$
76
77  # No secondary card, return 1
78  if [ -z "$card2" ] ; then return 1; fi
79
80  # Is this secondary an Intel chipset?
81  echo "$card2" | grep -q -i -e "intel"
82  if [ $? -ne 0 ] ; then return 1 ; fi
83
84  # Found a second card, lets try an xorg config for it
85  cp /root/cardDetect/XF86Config.default /etc/X11/xorg.conf
86  echo "
87Section \"Device\"
88        Identifier      \"Card0\"
89        Driver          \"intel\"
90        BusID           \"${card2bus}\"
91EndSection
92  " >> /etc/X11/xorg.conf
93
94  echo "Hybrid video detected! Using Intel chipset..."
95  sleep 3
96
97  return 0
98}
99
100start_xorg()
101{
102
103  # Now run the X auto-detection
104  detect_x
105
106  # Run X Now
107  startx
108  if [ ! -e "/tmp/.xstarted" ]
109  then
110    # Failed to start X
111    # Lets try again with its own internal video detection
112    rm /etc/X11/xorg.conf 2>/dev/null
113
114    startx
115    if [ ! -e "/tmp/.xstarted" ]
116    then
117      echo "ERROR: Failed to start X in SAFE mode... Trying VESA mode..."
118      rm /etc/X11/xorg.conf
119      cp /root/cardDetect/XF86Config.compat /etc/X11/xorg.conf
120      startx
121     if [ ! -e "/tmp/.xstarted" ]
122      then
123        # Try the Intel driver, since nvidia/vesa will fail on optimus cards
124        cp /root/cardDetect/XF86Config.intel /etc/X11/xorg.conf
125        startx
126        if [ ! -e "/tmp/.xstarted" ]
127        then
128          echo "ERROR: Failed to start X..."
129          echo "Dropping to failsafe console... Edit /etc/X11/xorg.conf, and run #startx to bring up the GUI."
130          echo "[Press Enter to Continue]"
131          read tmp
132          /bin/sh
133        fi
134      fi
135    fi
136  fi
137
138}
139
140rtn()
141{
142   echo "Press ENTER to continue"
143   read tmp
144}
Note: See TracBrowser for help on using the repository browser.