Annotation of /trunk/installer/hwdetection.sh
Parent Directory | Revision Log
Revision 767 -
(hide annotations)
(download)
(as text)
Mon Sep 22 22:06:46 2008 UTC (15 years, 7 months ago) by niro
File MIME type: application/x-sh
File size: 4611 byte(s)
Mon Sep 22 22:06:46 2008 UTC (15 years, 7 months ago) by niro
File MIME type: application/x-sh
File size: 4611 byte(s)
-better double spaces fix
1 | niro | 571 | #!/bin/bash |
2 | niro | 767 | # $Header: /home/cvsd/magellan-cvs/magellan-src/installer/hwdetection.sh,v 1.8 2008-09-22 22:06:46 niro Exp $ |
3 | niro | 571 | |
4 | ## hwdetection, needs >= sys-apps/hwinfo | ||
5 | |||
6 | niro | 596 | # 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 | niro | 571 | # get_hwinfo $hw_item |
18 | get_hwinfo() | ||
19 | { | ||
20 | niro | 575 | local enable_desc="0" |
21 | |||
22 | if [[ $1 = --with-description ]] || [[ $1 = -d ]] | ||
23 | then | ||
24 | enable_desc=1 | ||
25 | shift | ||
26 | fi | ||
27 | |||
28 | niro | 571 | local item="$1" |
29 | local all | ||
30 | local i | ||
31 | niro | 576 | |
32 | # handle special items | ||
33 | case ${item} in | ||
34 | memory) get_hwinfo_memory; return ;; | ||
35 | smp) get_hwinfo_smp; return ;; | ||
36 | esac | ||
37 | |||
38 | niro | 571 | 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 | niro | 575 | if [[ ${enable_desc} = 1 ]] |
48 | then | ||
49 | echo "${device};${description}" | ||
50 | else | ||
51 | echo "${device}" | ||
52 | fi | ||
53 | niro | 571 | done <<< "${all}" |
54 | } | ||
55 | |||
56 | niro | 576 | |
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 | niro | 571 | # 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 | niro | 574 | eval $(echo "${i}" | sed -e "s:\":modules=\"\${modules}\ :" -e "s:,:\ :") |
97 | niro | 571 | 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 | niro | 767 | unset list |
117 | |||
118 | niro | 571 | # remove all ':' and show the cleaned list |
119 | niro | 573 | # this way fixes double spaces also |
120 | for i in $(echo ${fixed_list} | sed "s|:| |g") | ||
121 | do | ||
122 | niro | 767 | list+=" ${i}" |
123 | niro | 573 | done |
124 | niro | 767 | |
125 | echo "${list}" | ||
126 | niro | 571 | } |
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="$1" | ||
143 | local kernel="$2" | ||
144 | local config="$3" | ||
145 | local modules | ||
146 | |||
147 | [[ -z ${initrd} ]] && initrd="/boot/initrd-$(uname -r).img" | ||
148 | [[ -z ${kernel} ]] && kernel="$(uname -r)" | ||
149 | [[ -z ${config} ]] && config="/etc/conf.d/mkinitrd" | ||
150 | |||
151 | # get various modules needed to boot | ||
152 | modules="${modules} $(get_driver_modules disk)" | ||
153 | modules="${modules} $(get_driver_modules scsi)" | ||
154 | modules="${modules} $(get_driver_modules cdrom)" | ||
155 | |||
156 | # remove all duplicate modules | ||
157 | modules="$(remove_duplicates ${modules})" | ||
158 | |||
159 | # create the config and an initrd | ||
160 | echo "# autogenerated config file" > ${config} | ||
161 | echo "MODULES=\"${modules}\"" >> ${config} | ||
162 | echo "IMAGE_TYPE=\"initramfs\"" >> ${config} | ||
163 | |||
164 | mkinitrd -f ${initrd} ${kernel} | ||
165 | } | ||
166 | |||
167 | # special: memory (size), floppy (modprobe floppy), smp (support y/n) | ||
168 | # sound (which module? -> eval $(hwinfo --sound | grep "Driver Modules:" | cut -d: -f2 | sed s:\":a=\":) ) | ||
169 | # | ||
170 | |||
171 | # for i in cdrom cpu disk floppy gfxcard keyboard memory monitor mouse | ||
172 | # netcard pppoe scsi smp \ | ||
173 | # sound wlan | ||
174 | # do | ||
175 | # echo -------- ${i} | ||
176 | # get_hwinfo ${i} | ||
177 | # echo ------------------------------------------------- | ||
178 | # echo | ||
179 | # done | ||
180 | |||
181 | # get_driver_modules sound | ||
182 | # get_driver_modules wlan | ||
183 | # get_driver_modules cdrom | ||
184 | # get_driver_modules disk | ||
185 | # get_driver_modules gfxcard | ||
186 | # get_x11_driver_modules | ||
187 | |||
188 | # # get a modules list | ||
189 | # for i in sound wlan cdrom disk gfxcard | ||
190 | # do | ||
191 | # ALL_MODULES="${ALL_MODULES} $(get_driver_modules ${i})" | ||
192 | # done | ||
193 | # ALL_MODULES="${ALL_MODULES} $(get_x11_driver_modules)" | ||
194 | # # show a clean list | ||
195 | # for i in $(remove_duplicates ${ALL_MODULES}) | ||
196 | # do | ||
197 | # echo ${i} | ||
198 | # done | ||
199 | |||
200 | #create_initrd /root/TEST/initrd | ||
201 | niro | 575 | #get_driver_modules cdrom |
202 | niro | 571 | #get_driver_modules disk |
203 | #get_driver_modules scsi | ||
204 | #get_driver_modules all | ||
205 | |||
206 | # network | ||
207 | niro | 575 | #get_hwinfo --with-description netcard |
208 | niro | 572 | #get_driver_modules netcard |
209 | niro | 571 | |
210 | #get_hwinfo disk | ||
211 | #get_hwinfo partition | grep /dev/hda |