Annotation of /trunk/installer/include/hwdetection.sh
Parent Directory | Revision Log
Revision 773 -
(hide annotations)
(download)
(as text)
Wed Sep 24 10:54:00 2008 UTC (16 years ago) by niro
File MIME type: application/x-sh
File size: 5410 byte(s)
Wed Sep 24 10:54:00 2008 UTC (16 years ago) by niro
File MIME type: application/x-sh
File size: 5410 byte(s)
-moved helper-scripts into include/ directory
1 | niro | 773 | #!/bin/bash |
2 | # $Header: /home/cvsd/magellan-cvs/magellan-src/installer/include/hwdetection.sh,v 1.1 2008-09-24 10:54:00 niro Exp $ | ||
3 | |||
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 | |||
79 | # being little tricky here :) | ||
80 | # does following: | ||
81 | # grep: | ||
82 | # -> 'Driver Modules: "via82cxxx", "ide_cd"' | ||
83 | # cut: | ||
84 | # -> ' "via82cxxx", "ide_cd"' | ||
85 | # sed1: | ||
86 | # -> ' modules="via82cxxx", "ide_cd"' | ||
87 | # sed2: | ||
88 | # -> ' modules="via82cxxx ide_cd"' | ||
89 | # then evaluate -> eval modules="via82cxxx ide_cd" | ||
90 | # and we get a variable $modules with all mods | ||
91 | #eval $(hwinfo --"${item}" | grep "Driver Modules:" | cut -d: -f2 | sed -e "s:\":modules=\":" -e "s:\",\ \":\ :") | ||
92 | |||
93 | local i | ||
94 | for i in $(hwinfo --"${item}" | grep "Driver Modules:" | cut -d: -f2 ) | ||
95 | do | ||
96 | eval $(echo "${i}" | sed -e "s:\":modules=\"\${modules}\ :" -e "s:,:\ :") | ||
97 | done | ||
98 | echo "${modules}" | ||
99 | } | ||
100 | |||
101 | # remove_duplicates $list | ||
102 | remove_duplicates() | ||
103 | { | ||
104 | local list="$@" | ||
105 | local fixed_list=":" | ||
106 | local i | ||
107 | |||
108 | for i in ${list} | ||
109 | do | ||
110 | if [[ -z $(echo "${fixed_list}" | fgrep ":${i}:") ]] | ||
111 | then | ||
112 | fixed_list="${fixed_list}${i}:" | ||
113 | fi | ||
114 | done | ||
115 | |||
116 | unset list | ||
117 | |||
118 | # remove all ':' and show the cleaned list | ||
119 | # this way fixes double spaces also | ||
120 | for i in $(echo ${fixed_list} | sed "s|:| |g") | ||
121 | do | ||
122 | list+=" ${i}" | ||
123 | done | ||
124 | |||
125 | echo "${list}" | ||
126 | } | ||
127 | |||
128 | get_x11_driver_modules() | ||
129 | { | ||
130 | local modules | ||
131 | modules="$(hwinfo --gfxcard | grep "XFree86 v4 Server Module:" | cut -d: -f2)" | ||
132 | |||
133 | # remove duplicates from list and show it | ||
134 | remove_duplicates "${modules}" | ||
135 | } | ||
136 | |||
137 | # create_initrd {/path/to/initrd kernelversion </path/to/config>} | ||
138 | # when nothing given then /boot/initrd-$(uname -r).img $(uname -r) will be used | ||
139 | # default config path is /etc/conf.d/mkinitrd | ||
140 | create_initrd() | ||
141 | { | ||
142 | local initrd | ||
143 | local kernel | ||
144 | local config | ||
145 | local chroot | ||
146 | #local root | ||
147 | local modules | ||
148 | |||
149 | # very basic getops | ||
150 | for i in $* | ||
151 | do | ||
152 | case $1 in | ||
153 | #--root|-r) shift; root="$1" ;; | ||
154 | --initrd|-i) shift; initrd="$1" ;; | ||
155 | --config|-c) shift; config="$1" ;; | ||
156 | --kernelversion|-v) shift; kernel="$1" ;; | ||
157 | esac | ||
158 | shift | ||
159 | done | ||
160 | |||
161 | [[ -z ${initrd} ]] && initrd="/boot/initrd-$(uname -r).img" | ||
162 | [[ -z ${kernel} ]] && kernel="$(uname -r)" | ||
163 | [[ -z ${config} ]] && config="/etc/conf.d/mkinitrd" | ||
164 | |||
165 | if [[ ! -z ${INSTALL_ROOT} ]] | ||
166 | then | ||
167 | config="${INSTALL_ROOT}/${config}" | ||
168 | chroot="chrooted" | ||
169 | fi | ||
170 | |||
171 | # get various modules needed to boot | ||
172 | modules="$(get_driver_modules disk)" | ||
173 | modules+=" $(get_driver_modules scsi)" | ||
174 | modules+=" $(get_driver_modules cdrom)" | ||
175 | |||
176 | # check for special ide_disk drivers (ata support) | ||
177 | if [[ ! -z $(echo ${modules} | grep ide_disk) ]] | ||
178 | then | ||
179 | modules+=" $(grep ide_disk /proc/modules | cut -d' ' -f4 | sed '/-/d;s:,:\ :g')" | ||
180 | fi | ||
181 | |||
182 | # remove all duplicate modules | ||
183 | modules="$(remove_duplicates ${modules})" | ||
184 | |||
185 | # create the config and an initrd | ||
186 | echo "# autogenerated config file" > ${config} | ||
187 | echo "MODULES=\"${modules}\"" >> ${config} | ||
188 | echo "IMAGE_TYPE=\"initramfs\"" >> ${config} | ||
189 | |||
190 | ${chroot} mkinitrd -f ${initrd} ${kernel} | ||
191 | } | ||
192 | |||
193 | chrooted() | ||
194 | { | ||
195 | local cmd="$@" | ||
196 | |||
197 | mount -t sysfs sysfs ${INSTALL_ROOT}/sys | ||
198 | mount -t proc proc ${INSTALL_ROOT}/proc | ||
199 | mount -o bind /dev ${INSTALL_ROOT}/dev | ||
200 | |||
201 | chroot ${INSTALL_ROOT} ${cmd} | ||
202 | |||
203 | umount ${INSTALL_ROOT}/dev | ||
204 | umount ${INSTALL_ROOT}/proc | ||
205 | umount ${INSTALL_ROOT}/sys | ||
206 | } | ||
207 | |||
208 | # special: memory (size), floppy (modprobe floppy), smp (support y/n) | ||
209 | # sound (which module? -> eval $(hwinfo --sound | grep "Driver Modules:" | cut -d: -f2 | sed s:\":a=\":) ) | ||
210 | # | ||
211 | |||
212 | # for i in cdrom cpu disk floppy gfxcard keyboard memory monitor mouse | ||
213 | # netcard pppoe scsi smp \ | ||
214 | # sound wlan | ||
215 | # do | ||
216 | # echo -------- ${i} | ||
217 | # get_hwinfo ${i} | ||
218 | # echo ------------------------------------------------- | ||
219 | # echo | ||
220 | # done | ||
221 | |||
222 | # get_driver_modules sound | ||
223 | # get_driver_modules wlan | ||
224 | # get_driver_modules cdrom | ||
225 | # get_driver_modules disk | ||
226 | # get_driver_modules gfxcard | ||
227 | # get_x11_driver_modules | ||
228 | |||
229 | # # get a modules list | ||
230 | # for i in sound wlan cdrom disk gfxcard | ||
231 | # do | ||
232 | # ALL_MODULES="${ALL_MODULES} $(get_driver_modules ${i})" | ||
233 | # done | ||
234 | # ALL_MODULES="${ALL_MODULES} $(get_x11_driver_modules)" | ||
235 | # # show a clean list | ||
236 | # for i in $(remove_duplicates ${ALL_MODULES}) | ||
237 | # do | ||
238 | # echo ${i} | ||
239 | # done | ||
240 | |||
241 | #create_initrd /root/TEST/initrd | ||
242 | #get_driver_modules cdrom | ||
243 | #get_driver_modules disk | ||
244 | #get_driver_modules scsi | ||
245 | #get_driver_modules all | ||
246 | |||
247 | # network | ||
248 | #get_hwinfo --with-description netcard | ||
249 | #get_driver_modules netcard | ||
250 | |||
251 | #get_hwinfo disk | ||
252 | #get_hwinfo partition | grep /dev/hda |