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