Magellan Linux

Annotation of /trunk/installer/hwdetection.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 573 - (hide annotations) (download) (as text)
Wed Sep 12 18:36:50 2007 UTC (16 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 3691 byte(s)
-fixed remove_duplicates to get rid of "double-spaces"

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