Dash:
[t2.git] / package / xorg / xorg-server / xcfgt2.sh
blobc93df53f1fa8f8dc38d52d4034a8c06d848fb702
1 #!/bin/bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 #
5 # T2 SDE: package/.../xorg-server/xcfgt2.sh
6 # Copyright (C) 2005 - 2017 The T2 SDE Project
7 # Copyright (C) 2005 - 2020 Rene Rebe - ExactCODE
8 #
9 # More information can be found in the files COPYING and README.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; version 2 of the License. A copy of the
14 # GNU General Public License can be found in the file COPYING.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 # Quick T2 SDE live X driver matching ...
19 var_append() {
20 local x="${3// /}"
21 eval "[ \"\$$1\" ] && $1=\"\${$1}$2\"" || true
22 eval "$1=\"\${$1}\$x\""
25 tmp=`mktemp`
27 echo "XcfgT2 (C) 2005 - 2020 Rene Rebe, ExactCODE"
29 sysid=
30 if type -p dmidecode >/dev/null; then
31 sysid=" "
32 var_append sysid ':' "`dmidecode -s system-manufacturer`"
33 var_append sysid ':' "`dmidecode -s system-product-name`"
34 var_append sysid ':' "`dmidecode -s baseboard-manufacturer`"
35 var_append sysid ':' "`dmidecode -s baseboard-product-name`"
36 var_append sysid ':' "`dmidecode -s system-serial-number`"
37 var_append sysid ':' "`dmidecode -s baseboard-serial-number`"
38 sysid="${sysid# :}"
41 # Apple Inc.:MacBookPro3,1:Apple Inc.:Mac-F4238BC8::
42 # PhoenixAward:945GM:PhoenixAward:945GM:0123456789:
43 # ::IntelCorporation:D945GCLF2::
44 # ASUSTeK Computer INC.:900:ASUSTeK Computer INC.:900:EeePC-1234567890:EeePC
45 echo "SystemID: $sysid"
47 card="`lspci | sed -n 's/.*[^-]VGA[^:]*: //p'`" # not Non-VGA
48 [ "$card" ] || card="`cat /sys/class/graphics/fb0/name 2>/dev/null`"
50 echo "Video card: $card"
52 # defaults
53 depth=16 # safe default for even older cards
54 # fallback to either vesa or fbdev ...
55 case `uname -m` in
56 i*86*|x86*64) xdrv=vesa ;;
57 *) xdrv=fbdev ;;
58 esac
60 case `echo "$card" | tr A-Z a-z` in
61 *radeon*) xdrv=radeon ;;
62 *geforce*) xdrv=nv ;;
63 *cirrus*) xdrv=cirrus ;;
64 *savage*) xdrv=savage ;;
65 *unichrome*|*castlerock*) xdrv=via ;;
66 *virge*) xdrv=s3virge ;;
67 ps3*fb) xdrv=fbdev ;;
68 *s3*) xdrv=s3 ;;
70 *intel*8*|*intel*9*|*intel*mobile*) xdrv=intel ;;
71 *intel*7*) xdrv=i740 ;;
73 *trident*) xdrv=trident ;;
74 *rendition*) xdrv=rendition ;;
75 *neo*) xdrv=neomagic ;;
76 *tseng*) xdrv=tseng ;;
78 *parhelia*) xdrv=mtx ;;
79 *matrox*) xdrv=mga ;;
81 *cyrix*) xdrv=cyrix ;;
82 *silicon\ motion*) xdrv=siliconmotion ;;
83 *chips*) xdrv=chips ;;
85 *3dfx*) xdrv="tdfx" ;;
86 *permedia*|*glint*) xdrv="glint" ;;
88 *vmware*) xdrv="vmware" ;;
90 *ark\ logic*) xdrv="ark" ;;
91 *dec*tga*) xdrv="tga" ;;
93 *national\ semi*|*amd*) xdrv=nsc ;;
95 *ati\ *) xdrv=ati ;;
96 *sis*|*xgi*) xdrv=sis ;;
98 creator\ 3d|elite\ 3d) xdrv=sunffb ;;
99 tcx*) xdrv=suntcx; depth=8 ;;
100 gx* |tgx*) xdrv=suncg6; depth=8 ;;
102 # must be last so *nv* does not match one of the above
103 *nv*) xdrv=nv
104 esac
106 # maybe binary nvidia driver?
107 [ "$xdrv" = nv -a -f /usr/X11/lib/xorg/modules/drivers/nvidia_drv.so ] &&
108 xdrv=nvidia
110 # manual override
111 xdriver="xdriver= `cat /proc/cmdline`"; xdriver=${xdriver##*xdriver=}; xdriver=${xdriver%% *}
112 [ "$xdriver" ] && xdrv="$xdriver"
114 case "$xdrv" in
115 fbdev|nv|nvidia|sunffb) depth=24 ;;
116 vmware) depth= ;;
117 esac
119 # manual override
120 xdepth="xdepth= `cat /proc/cmdline`"; xdepth=${xdepth##*xdepth=}; xdepth=${xdepth%% *}
121 [ "$xdepth" ] && depth="$xdepth"
124 # use the nvidia binary only driver - if available ...
125 if [ "$xdrv" = "nvidia" ]; then
126 echo "Installing nvidia GL libraries and headers ..."
127 rm -rf /usr/X11/lib/libGL.*
128 cp -arv /usr/src/nvidia/lib/* /usr/X11/lib/
129 cp -arv /usr/src/nvidia/X11R6/lib/* /usr/X11/lib/
130 cp -arv /usr/src/nvidia/include/* /usr/X11/lib/GL/
131 ln -sf /usr/X11/lib/xorg/modules/extensions/{libglx.so.1.0.*,libglx.so}
133 echo "Updating dynamic library database ..."
134 ldconfig /usr/X11/lib
137 horiz_sync=
138 vert_refresh=
139 modes=
140 ddc=1
142 # manual, boot command line overrides
143 xmodes="xmodes= $(< /proc/cmdline)"; xmodes=${xmodes##*xmodes=}; xmodes=${xmodes%% *}
144 xddc="xddc= $(< /proc/cmdline)"; xddc=${xddc##*xddc=}; xddc=${xddc%% *}
146 [ "$xmodes" ] && modes="$(echo $xmodes | sed 's/,/ /g; s/[^ ]\+/"&"/g')"
147 [ "$xddc" ] && ddc="$xddc"
150 # if ddcprobe available, ddc not disabled and no manual modes
151 if type -p ddcprobe > /dev/null && [ "$ddc" = 1 ] && [ -z "$modes" ]; then
152 echo "Probing for DDC information ..."
153 ddcprobe > $tmp
155 if grep -q failed $tmp ; then
156 echo "DDC read failed"
157 else
158 defx=`grep "Horizontal blank time" $tmp | cut -d : -f 2 |
159 sort -nu | tail -n 1`
160 defy=`grep "Vertical blank time" $tmp | cut -d : -f 2 |
161 sort -nu | tail -n 1`
163 defx=${defx:-0}
164 defy=${defy:-0}
166 while read m ; do
167 x=${m/x*/}
168 y=${m/*x/}
169 if [ $defx -eq 0 -o $x -le $defx ] &&
170 [ $defy -eq 0 -o $y -le $defy ]; then
171 echo "mode $x $y ok"
172 modes="$modes \"${x}x${y}\""
173 else
174 echo "mode $x $y skipped"
176 done < <( grep -A 1000 '^Established' $tmp |
177 grep -B 1000 '^Standard\|^Detailed' |
178 sed -e 's/[\t ]*\([^ ]*\).*/\1/' -e '/^[A-Z]/d' |
179 sort -rn | uniq )
183 # if still no mode try to determine from FB (mostly for
184 # non PC workstations / embedded devices with system FB)
185 if [ -z "$modes" ]; then
186 for mode in `sed -n 's/.:\([[:digit:]]\+x[[:digit:]]\+\)[[:alpha:]]*-[[:digit:]]\+/\1/p' \
187 /sys/class/graphics/fb0/modes 2>/dev/null | sort -r -n -u`
189 modes="$modes \"$mode\""
190 done
191 modes="${modes# *}"
194 # still no modes, use backward / safe compatible defaults
195 if [ -z "$modes" ]; then
196 echo "No modes from DDC or FB detection, using defaults!"
197 modes='"1024x768" "800x600" "640x480"'
198 horiz_sync="HorizSync 24.0 - 65.0"
199 vert_refresh="VertRefresh 50 - 75"
203 echo "X Driver: $xdrv"
204 echo "Using modes: $modes"
205 echo " @ depth: $depth"
206 [ "$hoiz_sync" -o "$vert_refresh" ] &&
207 echo " horiz: $horiz_sync" &&
208 echo " vert: $vert_refresh"
210 [ -f /etc/X11/xorg.conf ] && cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak
212 sed -e "s/\$xdrv/$xdrv/g" -e "s/\$modes/$modes/g" -e "s/\$depth/$depth/g" \
213 -e "s/\$horiz_sync/$horiz_sync/g" \
214 -e "s/\$vert_refresh/$vert_refresh/g" \
215 /etc/X11/xorg.conf.template > /etc/X11/xorg.conf
217 if [ -z "$depth" ]; then
218 sed -i '/DefaultDepth/d' /etc/X11/xorg.conf
221 if [ "$ddc" = 0 ]; then
222 echo "Adding NoDDC option"
223 sed -i 's/.*Ident.*Card.*/&\n Option\t"NoDDC"\n/' /etc/X11/xorg.conf
226 rm $tmp