Contents of /trunk/installer/hwdetection.sh
Parent Directory | Revision Log
Revision 576 -
(show annotations)
(download)
(as text)
Wed Sep 12 19:02:39 2007 UTC (16 years, 7 months ago) by niro
File MIME type: application/x-sh
File size: 4292 byte(s)
Wed Sep 12 19:02:39 2007 UTC (16 years, 7 months ago) by niro
File MIME type: application/x-sh
File size: 4292 byte(s)
-support special memory and smp cases within get_hwinfo()
1 | #!/bin/bash |
2 | |
3 | ## hwdetection, needs >= sys-apps/hwinfo |
4 | |
5 | # get_hwinfo $hw_item |
6 | get_hwinfo() |
7 | { |
8 | local enable_desc="0" |
9 | |
10 | if [[ $1 = --with-description ]] || [[ $1 = -d ]] |
11 | then |
12 | enable_desc=1 |
13 | shift |
14 | fi |
15 | |
16 | local item="$1" |
17 | local all |
18 | local i |
19 | |
20 | # handle special items |
21 | case ${item} in |
22 | memory) get_hwinfo_memory; return ;; |
23 | smp) get_hwinfo_smp; return ;; |
24 | esac |
25 | |
26 | all=$(hwinfo --short --"${item}") |
27 | |
28 | declare -i i=0 |
29 | while read device description |
30 | do |
31 | # skip the first line |
32 | (( i++ )) |
33 | [ ${i} -eq 1 ] && continue |
34 | |
35 | if [[ ${enable_desc} = 1 ]] |
36 | then |
37 | echo "${device};${description}" |
38 | else |
39 | echo "${device}" |
40 | fi |
41 | done <<< "${all}" |
42 | } |
43 | |
44 | |
45 | # special memory case |
46 | get_hwinfo_memory() |
47 | { |
48 | local memory=$(hwinfo --memory | grep "Memory Size" | cut -d: -f2 | sed "s:\ ::") |
49 | echo "${memory}" |
50 | } |
51 | |
52 | |
53 | # special smp case |
54 | get_hwinfo_smp() |
55 | { |
56 | local smp=$(hwinfo --smp | grep "SMP support:" | cut -d: -f2 | sed "s:\ ::") |
57 | echo "${smp}" |
58 | } |
59 | |
60 | |
61 | # get_driver_modules $hw_item |
62 | get_driver_modules() |
63 | { |
64 | local item="$1" |
65 | local modules |
66 | |
67 | # being little tricky here :) |
68 | # does following: |
69 | # grep: |
70 | # -> 'Driver Modules: "via82cxxx", "ide_cd"' |
71 | # cut: |
72 | # -> ' "via82cxxx", "ide_cd"' |
73 | # sed1: |
74 | # -> ' modules="via82cxxx", "ide_cd"' |
75 | # sed2: |
76 | # -> ' modules="via82cxxx ide_cd"' |
77 | # then evaluate -> eval modules="via82cxxx ide_cd" |
78 | # and we get a variable $modules with all mods |
79 | #eval $(hwinfo --"${item}" | grep "Driver Modules:" | cut -d: -f2 | sed -e "s:\":modules=\":" -e "s:\",\ \":\ :") |
80 | |
81 | local i |
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 | echo "${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 | # remove all ':' and show the cleaned list |
105 | # this way fixes double spaces also |
106 | for i in $(echo ${fixed_list} | sed "s|:| |g") |
107 | do |
108 | echo "${i}" |
109 | done |
110 | } |
111 | |
112 | get_x11_driver_modules() |
113 | { |
114 | local modules |
115 | modules="$(hwinfo --gfxcard | grep "XFree86 v4 Server Module:" | cut -d: -f2)" |
116 | |
117 | # remove duplicates from list and show it |
118 | remove_duplicates "${modules}" |
119 | } |
120 | |
121 | # create_initrd {/path/to/initrd kernelversion </path/to/config>} |
122 | # when nothing given then /boot/initrd-$(uname -r).img $(uname -r) will be used |
123 | # default config path is /etc/conf.d/mkinitrd |
124 | create_initrd() |
125 | { |
126 | local initrd="$1" |
127 | local kernel="$2" |
128 | local config="$3" |
129 | local modules |
130 | |
131 | [[ -z ${initrd} ]] && initrd="/boot/initrd-$(uname -r).img" |
132 | [[ -z ${kernel} ]] && kernel="$(uname -r)" |
133 | [[ -z ${config} ]] && config="/etc/conf.d/mkinitrd" |
134 | |
135 | # get various modules needed to boot |
136 | modules="${modules} $(get_driver_modules disk)" |
137 | modules="${modules} $(get_driver_modules scsi)" |
138 | modules="${modules} $(get_driver_modules cdrom)" |
139 | |
140 | # remove all duplicate modules |
141 | modules="$(remove_duplicates ${modules})" |
142 | |
143 | # create the config and an initrd |
144 | echo "# autogenerated config file" > ${config} |
145 | echo "MODULES=\"${modules}\"" >> ${config} |
146 | echo "IMAGE_TYPE=\"initramfs\"" >> ${config} |
147 | |
148 | mkinitrd -f ${initrd} ${kernel} |
149 | } |
150 | |
151 | # special: memory (size), floppy (modprobe floppy), smp (support y/n) |
152 | # sound (which module? -> eval $(hwinfo --sound | grep "Driver Modules:" | cut -d: -f2 | sed s:\":a=\":) ) |
153 | # |
154 | |
155 | # for i in cdrom cpu disk floppy gfxcard keyboard memory monitor mouse |
156 | # netcard pppoe scsi smp \ |
157 | # sound wlan |
158 | # do |
159 | # echo -------- ${i} |
160 | # get_hwinfo ${i} |
161 | # echo ------------------------------------------------- |
162 | # echo |
163 | # done |
164 | |
165 | # get_driver_modules sound |
166 | # get_driver_modules wlan |
167 | # get_driver_modules cdrom |
168 | # get_driver_modules disk |
169 | # get_driver_modules gfxcard |
170 | # get_x11_driver_modules |
171 | |
172 | # # get a modules list |
173 | # for i in sound wlan cdrom disk gfxcard |
174 | # do |
175 | # ALL_MODULES="${ALL_MODULES} $(get_driver_modules ${i})" |
176 | # done |
177 | # ALL_MODULES="${ALL_MODULES} $(get_x11_driver_modules)" |
178 | # # show a clean list |
179 | # for i in $(remove_duplicates ${ALL_MODULES}) |
180 | # do |
181 | # echo ${i} |
182 | # done |
183 | |
184 | #create_initrd /root/TEST/initrd |
185 | #get_driver_modules cdrom |
186 | #get_driver_modules disk |
187 | #get_driver_modules scsi |
188 | #get_driver_modules all |
189 | |
190 | # network |
191 | #get_hwinfo --with-description netcard |
192 | #get_driver_modules netcard |
193 | |
194 | #get_hwinfo disk |
195 | #get_hwinfo partition | grep /dev/hda |