initial commit: 1.5.0
[systemrescuecd.git] / overlay-squashfs-x86 / usr / sbin / mkxf86config.sh
1 #!/bin/bash
2
3 source /etc/profile
4 source /sbin/functions.sh
5
6 # First, get the command line
7 CMDLINE="$(</proc/cmdline)"
8
9 # Most of this if for MIPS, except for the last one, which is for everything 
10 # else to select a default resolution.  Since the MIPS configs are ready to be
11 # used by default, we exit after calling a MIPS config.
12 for x in ${CMDLINE}
13 do
14         case "${x}" in
15                 ip22)
16                         # Newport for now, IP22 Impact later
17                         if [ ! -z "$(grep 'SGI Indigo2' /proc/cpuinfo)" ]
18                         then
19                                 sed -e '/^#@@@/s:\(^#@@@\|@@@$\)::g' \
20                                         /etc/X11/xorg.conf.newport > /etc/X11/xorg.conf
21                         fi
22                         exit 0
23                 ;;
24                 ip28)
25                         # This might support Newport too, but I2 Newport boards are rare.
26                         cp -f /etc/X11/xorg.conf.impact /etc/X11/xorg.conf
27                         exit 0
28                 ;;
29
30                 ip30)
31                         # Figure out if we're Impact, or VPro (Odyssey)
32                         if [ -e "/proc/fb" ]; then
33                                 ip30_impact="$(grep -i 'impact' /proc/fb)"
34                                 ip30_odyssey="$(grep -i 'odyssey' /proc/fb)"
35                                 if [ -n "${ip30_impact}" ]
36                                 then
37                                         cp -f /etc/X11/xorg.conf.impact /etc/X11/xorg.conf
38                                 elif [ -n "${ip30_odyssey}" ]
39                                 then
40                                         # Do nothing for now -- maybe one day we'll get an X driver
41                                         # cp -f /etc/X11/xorg.conf.odyssey /etc/X11/xorg.conf
42                                         ewarn "Currently, there is no X driver for Odyssey"
43                                 fi
44                         fi
45                         exit 0
46                 ;;
47                 ip32)
48                         # We use fbdev for now -- maybe one day we'll get a gbefb X driver
49                         cp -f /etc/X11/xorg.conf.o2-fbdev /etc/X11/xorg.conf
50                         exit 0
51                 ;;
52                 xres\=*)
53                         # We got a resolution on the command line, use it.
54                         NEWMODE=$(echo ${x} | cut -d= -f2)
55                         RAWMODES="\"${NEWMODE}\""
56         esac
57 done
58
59 TMPFILE="/tmp/mkxf86config-$$"
60 MONITORTMP="${TMPFILE}-monitor"
61
62 rm -f "${TMPFILE}" "${MONITORTMP}"
63
64 # Read in what hwsetup has found for X
65 [ -f /etc/sysconfig/xserver ] && . /etc/sysconfig/xserver
66
67 WHEEL='s|"PS/2"|"auto"\
68 Option          "ZAxisMapping"          "4 5"|g;'
69
70 # Read in changes
71 [ -f /etc/sysconfig/gentoo ] && . /etc/sysconfig/gentoo
72
73 # Read default keyboard from config file.
74 # There seems to be no reliable autoprobe possible.
75 [ -f /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
76
77 # Create mouse link and insert a mouse default type into xorg.conf
78 # if not already done by hwsetup
79 [ -f /etc/sysconfig/mouse ] && . /etc/sysconfig/mouse
80 # We create this link since hwsetup cannot properly detect serial mice
81 [ -e /dev/mouse ] || ln -sf /dev/ttyS0 /dev/mouse
82
83 PROTO="${XMOUSETYPE:-Microsoft}"
84 NOEMU=""
85 [ "${XEMU3}" = "no" ] && NOEMU='s|^.*Emulate3|# No 2 -> 3 Button emulation|g'
86
87 DEADKEYS=""
88 [ "${XKEYBOARD}" = "de" ] || DEADKEYS='s|^.*nodeadkeys.*$||g;'
89
90 if [ -n "${XMODULE}" ]
91 then
92         # Check for Framebuffer X-Modules and initialize framebuffer module
93         case "${XMODULE}" in
94                 pvr2fb)
95                         modprobe "${XMODULE}" >/dev/null 2>&1
96                         XMODULE="fbdev"
97                 ;;
98         esac
99 fi
100
101 # We used to use ddcxinfo-knoppix for monitor information, now we will just let
102 # X choose for itself.  This will probably break older machines.
103 # You can uncomment the following to re-enable dccxinfo-knoppix, but this only
104 # works on x86.
105 #MONITOR="$(ddcxinfo-knoppix -monitor)"
106 # Here we are setting a default set of HorizSync and VertRefresh.  These are
107 # "safe" values.  I am hoping to remove this completely in the future once more
108 # testing has been done on alternate architectures.
109 MONITOR='Section "Monitor"
110         Identifier   "Monitor0"
111         HorizSync    28.0 - 96.0
112         VertRefresh  50.0 - 75.0
113 EndSection'
114 RC="$?"
115 COMPLETE="$(awk '/EndSection/{print}' <<EOF
116 ${MONITOR}
117 EOF
118 )"
119
120 # Extract values for display
121 MODEL="$(awk '/^[        ]*ModelName/{print;exit}'<<EOF
122 ${MONITOR}
123 EOF
124 )"
125
126 MODEL="${MODEL#*\"}"
127 MODEL="${MODEL%\"*}"
128
129 HREFRESH="$(awk '/^[     ]*HorizSync/{print $2 $3 $4; exit}'<<EOF
130 ${MONITOR}
131 EOF
132 )"
133
134 VREFRESH="$(awk '/^[     ]*VertRefresh/{print $2 $3 $4; exit}'<<EOF
135 ${MONITOR}
136 EOF
137 )"
138
139 # Build line of allowed modes
140 # This is created from the Modelines created by ddcxinfo-knoppix and is not
141 # always accurate for your monitor.  This is currently set statically to give
142 # working support for alpha/amd64/ppc/x86 for the 2007.0 Gentoo release.  If
143 # anyone has more reliable, cross-platform methods, I'm all ears.
144 #RAWMODES=$(ddcxinfo-knoppix -monitor | grep ModeLine | sed -r "s/.*\"([0-9]+x[0-9]+)\".*/\1/g"| sort -rg | uniq | xargs echo | sed -r "s/([0-9]+x[0-9]+)/\"\1\"/g")
145 [ -z "${RAWMODES}" ] && RAWMODES="\"1024x768\" \"800x600\" \"640x480\""
146 MODES="Modes ${RAWMODES}"
147
148 # We need to check this because serial mice have long timeouts
149 SERIALMOUSE="$(ls -l1 /dev/mouse* 2>/dev/null | awk '/ttyS/{print $NF ; exit 0}')"
150 if [ -n "${SERIALMOUSE}" ]
151 then
152         SERIALMOUSE="s|/dev/ttyS0|${SERIALMOUSE}|g;"
153 else
154         SERIALMOUSE='s|^.*InputDevice.*"Serial Mouse".*$|# Serial Mouse not detected|g;'
155 fi
156
157 # PS/2 bug: Some keyboards are incorrectly used as mice in XFree. :-(
158 PSMOUSE="$(ls -l1 /dev/mouse* 2>/dev/null | awk '/input/{print $NF ; exit 0}')"
159 if [ -n "${PSMOUSE}" ]
160 then
161         PSMOUSE=""
162 else
163         PSMOUSE='s|^.*InputDevice.*"PS/2 Mouse".*$|# PS/2 Mouse not detected|g;'
164 fi
165
166 case "$(cat /proc/modules)" in
167         *usbmouse*|*mousedev*|*hid\ *)
168                 USBMOUSE=""
169         ;;
170         *)
171                 USBMOUSE='s|^.*InputDevice.*"USB Mouse".*$|# USB Mouse not detected|g;'
172         ;;
173 esac
174
175 # Kernel 2.6 reports psaux via /dev/input/mice like USB
176 case "$(uname -r)" in
177         2.6.*)
178                 if [ -n "${PSMOUSE}" ]
179                 then
180                         PSMOUSE='s|^.*InputDevice.*"PS/2 Mouse".*$|# PS/2 Mouse using /dev/input/mice in Kernel 2.6|g;'
181                         USBMOUSE=""
182                 fi
183         ;;
184 esac
185
186 if [ -a /proc/bus/input/devices ]
187 then
188         CHECK=$(cat /proc/bus/input/devices | grep -i synaptics | wc -l)
189         if [ ${CHECK} -gt 0 ]
190         then
191                 modprobe -q evdev
192                 SYNDEV=/dev/input/$(cat /proc/bus/input/devices | egrep -i -A 5 "^N: .*synaptics.*" | grep Handlers | sed -r "s/.*(event[0-9]+).*/\1/g")
193                 SYNMOUSE=""
194         else
195                 SYNMOUSE='s|^.*InputDevice.*"Synaptics".*$|#No Synaptics touchpad found|g;'
196         fi
197 fi
198
199 # Write Monitor data now
200 rm -f "${MONITORTMP}"
201 echo "${MONITOR}" > "${MONITORTMP}"
202
203 # Intel drivers have been renamed
204 if [ "${XMODULE}" = 'i810' ]
205 then
206         XMODULE='intel'
207 fi
208
209 # VMWare special handling
210 VMWARE=""
211 MOUSEDRIVER=""
212 if [ "${XMODULE}" = "vmware" ]
213 then
214         VMWARE='s|^.*BusID.*PCI.*$|BusID "PCI:0:15:0"|g;'
215         DEPTH='s|DefaultColorDepth |# DefaultColorDepth |g;'
216         if [ -e /usr/lib/xorg/modules/input/vmmouse_drv.so ] || \
217         [ -e /usr/lib/modules/input/vmmouse_drv.so ]
218         then
219                 MOUSEDRIVER='s|^.*Driver.*"mouse".*$|\tDriver\t"vmmouse"|g;'
220         fi
221 fi
222
223 #VirtualPC special handline
224 VPC=""
225 if [ "${XMODULE}" = "s3" ]
226 then
227         VPC='s|^.*BusID.*PCI.*$|BusID "PCI:0:8:0"|g;'
228         DEPTH='s|DefaultColorDepth 24|DefaultColorDepth 16|g;'
229 fi
230
231 # If we don't have a XMODULE set, use fbdev as fall-back
232 #
233 #[ -z "${XMODULE}" [ -z "${XMODULE}" ] ] && XMODULE="fbdev"] && XMODULE="fbdev" XMODULE="vesa"
234 [ -z "${XMODULE}" ] && XMODULE="vesa"
235
236 # Do NOT use a default colordepth setting if we are using the "fbdev" module
237 if [ "${XMODULE}" = "fbdev" ]
238 then
239         DEPTH='s|DefaultColorDepth |# DefaultColorDepth |g;'
240 fi
241
242 # These drivers need the sw_cursor option
243 SWCURSOR=""
244 MONITORLAYOUT=""
245 case "${XMODULE}" in
246         ati|nv|trident)
247                 SWCURSOR='s|^.*#Option.*"sw_cursor".*$|Option "sw_cursor"|g;'
248         ;;
249         radeon)
250                 SWCURSOR='s|^.*#Option.*"sw_cursor".*$|Option "sw_cursor"|g;'
251                 MONITORLAYOUT='s|^.*#Option.*"MonitorLayout".*$|Option "MonitorLayout"|g;'
252         ;;
253 esac
254
255 # We must use NoPM, because some machines freeze if Power management is beingi
256 # activated.
257 NOPM=""
258 DPMS=""
259
260 #checkbootparam noapm && NOPM='Option   "NoPM"  "true"' || DPMS='Option "DPMS"  "true"'
261
262 sed -e 's|@@PROTOCOL@@|'"${PROTO}"'|g;'"${NOEMU}" \
263     -e '/@@MONITOR@@/r '"${MONITORTMP}" \
264     -e 's|@@MONITOR@@||g' \
265     -e 's|@@NOPM@@|'"${NOPM}"'|g' \
266     -e 's|@@XMODULE@@|'"${XMODULE}"'|g;'"${VMWARE}""${VPC}""${SERIALMOUSE}""${USBMOUSE}""${PSMOUSE}""${SWCURSOR}""${MONITORLAYOUT}""${WHEEL}""${SYNMOUSE}""${MOUSEDRIVER}" \
267     -e 's|@@SYNDEV@@|'"${SYNDEV}"'|g' \
268     -e 's|@@MODES@@|'"${MODES}"'|g;'"${DEPTH}" \
269     -e 's|"XkbLayout" *"[^"]*"|"XkbLayout" "'"${XKEYBOARD}"'"|g;'"${DEADKEYS}" \
270     /etc/X11/xorg.conf.in >/etc/X11/xorg.conf
271
272 if [ -n "${DPMS}" ]
273 then
274     if [ -f /etc/X11/xorg.conf ]
275         then
276         sed -e 's|Identifier[    ]*"Monitor0"|Identifier        "Monitor0"\
277         '"${DPMS}"'|g' /etc/X11/xorg.conf >/etc/X11/xorg.conf.new
278                 mv -f /etc/X11/xorg.conf.new /etc/X11/xorg.conf
279     fi
280 fi
281
282 rm -f "${TMPFILE}" "${MONITORTMP}" 2>/dev/null
283
284 # Print info about selected X-Server
285 [ -n "${XDESC}" ] || XDESC="(yet) unknown card"
286 echo -n " ${GOOD}Video is"
287
288 [ -n "${XDESC}" ] && echo -n " ${HILITE}${XDESC}${NORMAL},"
289 echo -n " using ${GOOD}${XSERVER:-generic VESA}"
290 [ -n "${XMODULE}" ] && echo -n "(${HILITE}${XMODULE}${NORMAL})"
291 echo " Server${NORMAL}"
292
293 echo -n " ${GOOD}Monitor is ${HILITE}${MODEL:-Generic Monitor}${NORMAL}"
294 [ -n "${HREFRESH}" -a -n "${VREFRESH}" ] && echo "${GOOD}, ${GOOD}H:${HILITE}${HREFRESH}kHz${GOOD}, V:${HILITE}${VREFRESH}Hz${NORMAL}" || echo ""
295 [ -n "${XVREFRESH}" ] && echo " ${GOOD}Trying specified vrefresh rate of ${HILITE}${XVREFRESH}Hz.${NORMAL}"
296
297 [ -n "${MODES}" ] && echo " ${GOOD}Using Modes ${HILITE}${MODES##Modes }${NORMAL}"
298