Magellan Linux

Contents of /mcore-src/trunk/mcore-tools/src/include/hwdetection.global.class.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1307 - (show annotations) (download)
Sun Feb 6 23:47:09 2011 UTC (13 years, 4 months ago) by niro
Original Path: mcore-src/trunk/mcore-tools/daemon/include/hwdetection.global.class
File size: 6721 byte(s)
updated hwdetection from upstream installer
1 #!/bin/bash
2 # $Id$
3
4 provide hwdetection
5
6 ## 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 ${use_sudo} /usr/sbin/hwinfo $@
17 }
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
75 # get_driver_modules $hw_item
76 get_driver_modules()
77 {
78 local item="$1"
79 local modules
80 local i
81
82 for i in $(hwinfo --"${item}" | grep "Driver Modules:" | cut -d: -f2 )
83 do
84 eval $(echo "${i}" | sed -e "s:\":modules=\"\${modules}\ :" -e "s:,:\ :")
85 done
86 remove_duplicates "${modules}"
87 }
88
89 # remove_duplicates $list
90 remove_duplicates()
91 {
92 local list="$@"
93 local fixed_list=":"
94 local i
95
96 for i in ${list}
97 do
98 if [[ -z $(echo "${fixed_list}" | fgrep ":${i}:") ]]
99 then
100 fixed_list="${fixed_list}${i}:"
101 fi
102 done
103
104 unset list
105
106 # remove all ':' and show the cleaned list
107 # this way fixes double spaces also
108 local counter
109 declare -i counter=0
110 for i in $(echo ${fixed_list} | sed "s|:| |g")
111 do
112 (( counter++ ))
113 if [[ ${counter} -eq 1 ]]
114 then
115 list="${i}"
116 else
117 list+=" ${i}"
118 fi
119 done
120
121 echo "${list}"
122 }
123
124 get_x11_driver_modules()
125 {
126 local modules
127 modules="$(hwinfo --gfxcard | grep 'XFree86 v4 Server Module:' | sed 's/.*Module:\ \(.*\)/\1/')"
128
129 # remove duplicates from list and show it
130 remove_duplicates "${modules}"
131 }
132
133 get_evdev_device_path()
134 {
135 local device="$1"
136 local path
137
138 case ${device} in
139 mouse|keyboard) true;;
140 *) die "unkown device";;
141 esac
142
143 path="$(hwinfo --${device} | grep 'Device Files:' | sed 's:.*\(/dev/input/event[0-5]\).*:\1:')"
144 echo "${path}"
145 }
146
147 # get_netcard_driver_modules device
148 # e.g. get_netcard_driver_modules eth0
149 get_netcard_driver_modules()
150 {
151 local device="$1"
152 local modules
153
154 if [[ -z ${device} ]]
155 then
156 echo "Error: get_netcard_driver_module(): no device given"
157 return 1
158 fi
159
160 modules=$(hwinfo --netcard | grep -B1 "Device File: ${device}" | sed 's/.*Modules: \"\(.*\)\"/\1/;q')
161 remove_duplicates "${modules}"
162 }
163
164 get_blkid_information()
165 {
166 local partition="$1"
167 local variable="$2"
168 local method
169
170 case $1 in
171 --uuid|-u) shift; method="-U"; partition="$1"; variable="$2" ;;
172 --label|-l) shift; method="-L"; partition="$1"; variable="$2" ;;
173 esac
174
175 if [[ -z ${partition} ]]
176 then
177 echo "Error: get_get_blkid_information()(): no partition given"
178 return 1
179 fi
180
181 if [[ -z ${variable} ]]
182 then
183 echo "Error: get_get_blkid_information()(): no variable given"
184 return 1
185 fi
186
187 blkid -o value -s "${variable}" "${method}" "${partition}"
188 }
189
190 get_fstype()
191 {
192 local partition="$1"
193 if [[ -z ${partition} ]]
194 then
195 echo "Error: get_fstype(): no partition given"
196 return 1
197 fi
198
199 # does not work with uuids
200 #mount -f --guess-fstype ${partition}
201
202 get_blkid_information ${partition} TYPE
203 }
204
205 get_uuid()
206 {
207 local partition="$1"
208 if [[ -z ${partition} ]]
209 then
210 echo "Error: get_uuid(): no partition given"
211 return 1
212 fi
213
214 # does not work with uuids
215 #mount -f --guess-fstype ${partition}
216
217 get_blkid_information ${partition} UUID
218 }
219
220 # create_initrd {/path/to/initrd kernelversion </path/to/config>}
221 # when nothing given then /boot/initrd-$(uname -r).img $(uname -r) will be used
222 # default config path is /etc/conf.d/mkinitrd
223 create_initrd()
224 {
225 local initrd
226 local kernel
227 local config
228 local chroot
229 #local root
230 local modules
231 # enabled framebuffer modules as default
232 local framebuffer=1
233 local uvesafb_config="/etc/modprobe.d/uvesafb.conf"
234
235 # very basic getops
236 for i in $*
237 do
238 case $1 in
239 --initrd|-i) shift; initrd="$1" ;;
240 --config|-c) shift; config="$1" ;;
241 --kernelversion|-v) shift; kernel="$1" ;;
242 --nofb) shift; framebuffer=0
243 esac
244 shift
245 done
246
247 [[ -z ${initrd} ]] && initrd="/boot/initrd-$(uname -r).img"
248 [[ -z ${kernel} ]] && kernel="$(uname -r)"
249 [[ -z ${config} ]] && config="/etc/conf.d/mkinitrd"
250
251 if [[ ! -z ${INSTALL_ROOT} ]]
252 then
253 config="${INSTALL_ROOT}/${config}"
254 uvesafb_config="${INSTALL_ROOT}/${uvesafb_config}"
255 chroot="chrooted"
256 fi
257
258 # get various modules needed to boot
259 modules="$(get_driver_modules disk)"
260 modules+=" $(get_driver_modules scsi)"
261 modules+=" $(get_driver_modules cdrom)"
262
263 # check for special ide_disk drivers (ata support)
264 if [[ ! -z $(echo ${modules} | grep ide_disk) ]]
265 then
266 modules+=" $(grep ide_disk /proc/modules | cut -d' ' -f4 | sed '/-/d;s:,:\ :g')"
267 fi
268
269 # add some generic modules
270 modules+=" sg_mod sg loop sr_mod sd_mod ide-cd ide-cd_mod ide-disk"
271
272 # add generic framebuffer modules
273 if [[ ${framebuffer} = 1 ]]
274 then
275 modules+=" uvesafb"
276
277 # setup modprobe conf too
278 [[ ! -d $(dirname ${uvesafb_config}) ]] && install -d $(dirname ${uvesafb_config})
279 cat > ${uvesafb_config} << EOF
280 # This file sets the parameters for uvesafb module.
281 # The following format should be used:
282 # options uvesafb mode_option=<xres>x<yres>[-<bpp>][@<refresh>] scroll=<ywrap|ypan|redraw> ...
283 #
284 # For more details see:
285 # http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/fb/uvesafb.txt
286 #
287 EOF
288 # fix a issues with virtualbox and 'ywrap'
289 if [[ ! -z $(hwinfo --bios | grep -i virtualbox) ]]
290 then
291 # use redraw on virtualbox
292 echo "options uvesafb mode_option=1024x768-32@60 scroll=redraw" >> ${uvesafb_config}
293 else
294 # default config 1024x768 and 60 HZ
295 echo "options uvesafb mode_option=1024x768-32@60 scroll=ywrap" >> ${uvesafb_config}
296 fi
297 fi
298
299 # remove all duplicate modules
300 modules="$(remove_duplicates ${modules})"
301
302 # create the config and an initrd
303 echo "# autogenerated config file" > ${config}
304 echo "MODULES=\"${modules}\"" >> ${config}
305 echo "IMAGE_TYPE=\"initramfs\"" >> ${config}
306
307 ${chroot} mkinitrd -f ${initrd} ${kernel}
308 }
309
310 chrooted()
311 {
312 local cmd="$@"
313
314 mount -t sysfs sysfs ${INSTALL_ROOT}/sys
315 mount -t proc proc ${INSTALL_ROOT}/proc
316 mount -o bind /dev ${INSTALL_ROOT}/dev
317
318 chroot ${INSTALL_ROOT} ${cmd}
319
320 umount ${INSTALL_ROOT}/dev
321 umount ${INSTALL_ROOT}/proc
322 umount ${INSTALL_ROOT}/sys
323 }