Annotation of /mcore-src/trunk/mcore-tools/src/include/hwdetection.global.class.in
Parent Directory | Revision Log
Revision 2791 -
(hide annotations)
(download)
Fri Jun 10 10:21:38 2016 UTC (7 years, 11 months ago) by niro
File size: 7772 byte(s)
Fri Jun 10 10:21:38 2016 UTC (7 years, 11 months ago) by niro
File size: 7772 byte(s)
-retrieve the correct x11 drivers via the loaded dri module if no x11 driver was detected by hwinfo
1 | niro | 1307 | #!/bin/bash |
2 | niro | 1248 | # $Id$ |
3 | |||
4 | niro | 1265 | provide hwdetection |
5 | |||
6 | niro | 1248 | ## hwdetection, needs >= sys-apps/hwinfo |
7 | |||
8 | # hwinfo wrapper to use hwinfo with sudo if requested | ||
9 | hwinfo() | ||
10 | { | ||
11 | local use_sudo="" | ||
12 | case ${SUDO} in | ||
13 | yes|y|true|1) use_sudo=sudo ;; | ||
14 | esac | ||
15 | |||
16 | niro | 2235 | ${use_sudo} @@SBINDIR@@/hwinfo $@ |
17 | niro | 1248 | } |
18 | |||
19 | # get_hwinfo $hw_item | ||
20 | get_hwinfo() | ||
21 | { | ||
22 | local enable_desc="0" | ||
23 | |||
24 | if [[ $1 = --with-description ]] || [[ $1 = -d ]] | ||
25 | then | ||
26 | enable_desc=1 | ||
27 | shift | ||
28 | fi | ||
29 | |||
30 | local item="$1" | ||
31 | local all | ||
32 | local i | ||
33 | |||
34 | # handle special items | ||
35 | case ${item} in | ||
36 | memory) get_hwinfo_memory; return ;; | ||
37 | smp) get_hwinfo_smp; return ;; | ||
38 | esac | ||
39 | |||
40 | all=$(hwinfo --short --"${item}") | ||
41 | |||
42 | declare -i i=0 | ||
43 | while read device description | ||
44 | do | ||
45 | # skip the first line | ||
46 | (( i++ )) | ||
47 | [ ${i} -eq 1 ] && continue | ||
48 | |||
49 | if [[ ${enable_desc} = 1 ]] | ||
50 | then | ||
51 | echo "${device};${description}" | ||
52 | else | ||
53 | echo "${device}" | ||
54 | fi | ||
55 | done <<< "${all}" | ||
56 | } | ||
57 | |||
58 | |||
59 | # special memory case | ||
60 | get_hwinfo_memory() | ||
61 | { | ||
62 | local memory=$(hwinfo --memory | grep "Memory Size" | cut -d: -f2 | sed "s:\ ::") | ||
63 | echo "${memory}" | ||
64 | } | ||
65 | |||
66 | |||
67 | # special smp case | ||
68 | get_hwinfo_smp() | ||
69 | { | ||
70 | local smp=$(hwinfo --smp | grep "SMP support:" | cut -d: -f2 | sed "s:\ ::") | ||
71 | echo "${smp}" | ||
72 | } | ||
73 | |||
74 | niro | 1335 | get_hwinfo_monitor() |
75 | { | ||
76 | local all | ||
77 | local hsync | ||
78 | local vsync | ||
79 | local resolution | ||
80 | niro | 1248 | |
81 | niro | 1335 | all="$(hwinfo --monitor)" |
82 | hsync=$(echo "${all}" | grep 'Hor.*Sync' | sed 's:.*\:\ \(.*\)\ kHz:\1:') | ||
83 | vsync=$(echo "${all}" | grep 'Vert.*Sync' | sed 's:.*\:\ \(.*\)\ Hz:\1:') | ||
84 | resolution=$(echo "${all}" | grep 'Max.*Resolution' | sed 's:.*\:\ \(.*\):\1:') | ||
85 | |||
86 | #echo "hsync=\"${hsync}\"" | ||
87 | #echo "vsync=\"${vsync}\"" | ||
88 | #echo "resolution=\"${resolution}\"" | ||
89 | echo "${hsync};${vsync};${resolution}" | ||
90 | } | ||
91 | |||
92 | niro | 1248 | # get_driver_modules $hw_item |
93 | get_driver_modules() | ||
94 | { | ||
95 | local item="$1" | ||
96 | local modules | ||
97 | niro | 1307 | local i |
98 | niro | 1248 | |
99 | for i in $(hwinfo --"${item}" | grep "Driver Modules:" | cut -d: -f2 ) | ||
100 | do | ||
101 | eval $(echo "${i}" | sed -e "s:\":modules=\"\${modules}\ :" -e "s:,:\ :") | ||
102 | done | ||
103 | remove_duplicates "${modules}" | ||
104 | } | ||
105 | |||
106 | # remove_duplicates $list | ||
107 | remove_duplicates() | ||
108 | { | ||
109 | local list="$@" | ||
110 | local fixed_list=":" | ||
111 | local i | ||
112 | |||
113 | for i in ${list} | ||
114 | do | ||
115 | if [[ -z $(echo "${fixed_list}" | fgrep ":${i}:") ]] | ||
116 | then | ||
117 | fixed_list="${fixed_list}${i}:" | ||
118 | fi | ||
119 | done | ||
120 | |||
121 | unset list | ||
122 | |||
123 | # remove all ':' and show the cleaned list | ||
124 | # this way fixes double spaces also | ||
125 | local counter | ||
126 | declare -i counter=0 | ||
127 | for i in $(echo ${fixed_list} | sed "s|:| |g") | ||
128 | do | ||
129 | (( counter++ )) | ||
130 | if [[ ${counter} -eq 1 ]] | ||
131 | then | ||
132 | list="${i}" | ||
133 | else | ||
134 | list+=" ${i}" | ||
135 | fi | ||
136 | done | ||
137 | |||
138 | echo "${list}" | ||
139 | } | ||
140 | |||
141 | get_x11_driver_modules() | ||
142 | { | ||
143 | local modules | ||
144 | niro | 2791 | local temp |
145 | local i | ||
146 | niro | 1248 | modules="$(hwinfo --gfxcard | grep 'XFree86 v4 Server Module:' | sed 's/.*Module:\ \(.*\)/\1/')" |
147 | |||
148 | niro | 2791 | # catch drivers without any x11 driver defined |
149 | if [[ -z ${modules} ]] | ||
150 | then | ||
151 | temp="$(hwinfo --gfxcard | grep '[[:space:]]Driver:' | sed 's/.*Driver:\ \(.*\)/\1/')" | ||
152 | for i in ${temp} | ||
153 | do | ||
154 | case ${i} in | ||
155 | i915|i965) modules+=" intel" ;; | ||
156 | nouveau) modules+=" noveau" ;; | ||
157 | radeon) modules+=" radeon" ;; | ||
158 | esac | ||
159 | done | ||
160 | fi | ||
161 | |||
162 | niro | 1248 | # remove duplicates from list and show it |
163 | remove_duplicates "${modules}" | ||
164 | } | ||
165 | |||
166 | niro | 1307 | get_evdev_device_path() |
167 | { | ||
168 | local device="$1" | ||
169 | local path | ||
170 | |||
171 | case ${device} in | ||
172 | mouse|keyboard) true;; | ||
173 | niro | 2243 | *) die "unknown device";; |
174 | niro | 1307 | esac |
175 | |||
176 | path="$(hwinfo --${device} | grep 'Device Files:' | sed 's:.*\(/dev/input/event[0-5]\).*:\1:')" | ||
177 | echo "${path}" | ||
178 | } | ||
179 | |||
180 | niro | 1248 | # get_netcard_driver_modules device |
181 | # e.g. get_netcard_driver_modules eth0 | ||
182 | get_netcard_driver_modules() | ||
183 | { | ||
184 | local device="$1" | ||
185 | local modules | ||
186 | |||
187 | if [[ -z ${device} ]] | ||
188 | then | ||
189 | echo "Error: get_netcard_driver_module(): no device given" | ||
190 | return 1 | ||
191 | fi | ||
192 | |||
193 | modules=$(hwinfo --netcard | grep -B1 "Device File: ${device}" | sed 's/.*Modules: \"\(.*\)\"/\1/;q') | ||
194 | remove_duplicates "${modules}" | ||
195 | } | ||
196 | |||
197 | get_blkid_information() | ||
198 | { | ||
199 | local partition="$1" | ||
200 | local variable="$2" | ||
201 | local method | ||
202 | |||
203 | case $1 in | ||
204 | --uuid|-u) shift; method="-U"; partition="$1"; variable="$2" ;; | ||
205 | --label|-l) shift; method="-L"; partition="$1"; variable="$2" ;; | ||
206 | esac | ||
207 | |||
208 | if [[ -z ${partition} ]] | ||
209 | then | ||
210 | echo "Error: get_get_blkid_information()(): no partition given" | ||
211 | return 1 | ||
212 | fi | ||
213 | |||
214 | if [[ -z ${variable} ]] | ||
215 | then | ||
216 | echo "Error: get_get_blkid_information()(): no variable given" | ||
217 | return 1 | ||
218 | fi | ||
219 | |||
220 | blkid -o value -s "${variable}" "${method}" "${partition}" | ||
221 | } | ||
222 | |||
223 | get_fstype() | ||
224 | { | ||
225 | local partition="$1" | ||
226 | if [[ -z ${partition} ]] | ||
227 | then | ||
228 | echo "Error: get_fstype(): no partition given" | ||
229 | return 1 | ||
230 | fi | ||
231 | |||
232 | # does not work with uuids | ||
233 | #mount -f --guess-fstype ${partition} | ||
234 | |||
235 | get_blkid_information ${partition} TYPE | ||
236 | } | ||
237 | |||
238 | get_uuid() | ||
239 | { | ||
240 | local partition="$1" | ||
241 | if [[ -z ${partition} ]] | ||
242 | then | ||
243 | echo "Error: get_uuid(): no partition given" | ||
244 | return 1 | ||
245 | fi | ||
246 | |||
247 | # does not work with uuids | ||
248 | #mount -f --guess-fstype ${partition} | ||
249 | |||
250 | get_blkid_information ${partition} UUID | ||
251 | } | ||
252 | |||
253 | # create_initrd {/path/to/initrd kernelversion </path/to/config>} | ||
254 | # when nothing given then /boot/initrd-$(uname -r).img $(uname -r) will be used | ||
255 | # default config path is /etc/conf.d/mkinitrd | ||
256 | create_initrd() | ||
257 | { | ||
258 | local initrd | ||
259 | local kernel | ||
260 | local config | ||
261 | local chroot | ||
262 | #local root | ||
263 | local modules | ||
264 | # enabled framebuffer modules as default | ||
265 | local framebuffer=1 | ||
266 | niro | 2235 | local uvesafb_config="@@SYSCONFDIR@@/modprobe.d/uvesafb.conf" |
267 | niro | 1248 | |
268 | # very basic getops | ||
269 | for i in $* | ||
270 | do | ||
271 | case $1 in | ||
272 | --initrd|-i) shift; initrd="$1" ;; | ||
273 | --config|-c) shift; config="$1" ;; | ||
274 | --kernelversion|-v) shift; kernel="$1" ;; | ||
275 | --nofb) shift; framebuffer=0 | ||
276 | esac | ||
277 | shift | ||
278 | done | ||
279 | |||
280 | [[ -z ${initrd} ]] && initrd="/boot/initrd-$(uname -r).img" | ||
281 | [[ -z ${kernel} ]] && kernel="$(uname -r)" | ||
282 | niro | 2235 | [[ -z ${config} ]] && config="@@CONFDDIR@@/mkinitrd" |
283 | niro | 1248 | |
284 | if [[ ! -z ${INSTALL_ROOT} ]] | ||
285 | then | ||
286 | config="${INSTALL_ROOT}/${config}" | ||
287 | niro | 1307 | uvesafb_config="${INSTALL_ROOT}/${uvesafb_config}" |
288 | niro | 1248 | chroot="chrooted" |
289 | fi | ||
290 | |||
291 | # get various modules needed to boot | ||
292 | modules="$(get_driver_modules disk)" | ||
293 | modules+=" $(get_driver_modules scsi)" | ||
294 | modules+=" $(get_driver_modules cdrom)" | ||
295 | |||
296 | # check for special ide_disk drivers (ata support) | ||
297 | if [[ ! -z $(echo ${modules} | grep ide_disk) ]] | ||
298 | then | ||
299 | modules+=" $(grep ide_disk /proc/modules | cut -d' ' -f4 | sed '/-/d;s:,:\ :g')" | ||
300 | fi | ||
301 | |||
302 | niro | 1335 | # check for usb-storage and add usb host drivers |
303 | if [[ ! -z $(echo ${modules} | grep usb[_-]storage) ]] | ||
304 | then | ||
305 | # add usb1, usb1.1, usb2 and ubs3 hosts | ||
306 | modules+=" uhci-hcd ohci-hcd ehci-hcd xhci-hcd" | ||
307 | fi | ||
308 | |||
309 | niro | 1248 | # add some generic modules |
310 | modules+=" sg_mod sg loop sr_mod sd_mod ide-cd ide-cd_mod ide-disk" | ||
311 | |||
312 | # add generic framebuffer modules | ||
313 | niro | 1307 | if [[ ${framebuffer} = 1 ]] |
314 | then | ||
315 | modules+=" uvesafb" | ||
316 | niro | 1248 | |
317 | niro | 1307 | # setup modprobe conf too |
318 | [[ ! -d $(dirname ${uvesafb_config}) ]] && install -d $(dirname ${uvesafb_config}) | ||
319 | cat > ${uvesafb_config} << EOF | ||
320 | # This file sets the parameters for uvesafb module. | ||
321 | # The following format should be used: | ||
322 | # options uvesafb mode_option=<xres>x<yres>[-<bpp>][@<refresh>] scroll=<ywrap|ypan|redraw> ... | ||
323 | # | ||
324 | # For more details see: | ||
325 | # http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/fb/uvesafb.txt | ||
326 | # | ||
327 | EOF | ||
328 | # fix a issues with virtualbox and 'ywrap' | ||
329 | if [[ ! -z $(hwinfo --bios | grep -i virtualbox) ]] | ||
330 | then | ||
331 | # use redraw on virtualbox | ||
332 | echo "options uvesafb mode_option=1024x768-32@60 scroll=redraw" >> ${uvesafb_config} | ||
333 | else | ||
334 | # default config 1024x768 and 60 HZ | ||
335 | echo "options uvesafb mode_option=1024x768-32@60 scroll=ywrap" >> ${uvesafb_config} | ||
336 | fi | ||
337 | fi | ||
338 | |||
339 | niro | 1248 | # remove all duplicate modules |
340 | modules="$(remove_duplicates ${modules})" | ||
341 | |||
342 | # create the config and an initrd | ||
343 | echo "# autogenerated config file" > ${config} | ||
344 | echo "MODULES=\"${modules}\"" >> ${config} | ||
345 | echo "IMAGE_TYPE=\"initramfs\"" >> ${config} | ||
346 | |||
347 | ${chroot} mkinitrd -f ${initrd} ${kernel} | ||
348 | } | ||
349 | |||
350 | chrooted() | ||
351 | { | ||
352 | local cmd="$@" | ||
353 | |||
354 | mount -t sysfs sysfs ${INSTALL_ROOT}/sys | ||
355 | mount -t proc proc ${INSTALL_ROOT}/proc | ||
356 | mount -o bind /dev ${INSTALL_ROOT}/dev | ||
357 | |||
358 | chroot ${INSTALL_ROOT} ${cmd} | ||
359 | |||
360 | umount ${INSTALL_ROOT}/dev | ||
361 | umount ${INSTALL_ROOT}/proc | ||
362 | umount ${INSTALL_ROOT}/sys | ||
363 | } |