Magellan Linux

Annotation of /trunk/installer/include/hwdetection.sh

Parent Directory Parent Directory | Revision Log Revision Log


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