Magellan Linux

Annotation of /trunk/installer/hwdetection.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 572 - (hide annotations) (download) (as text)
Thu Sep 6 10:35:46 2007 UTC (16 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 3620 byte(s)
-disabled examples

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     echo "${fixed_list}" | sed "s|:| |g"
69     }
70    
71     get_x11_driver_modules()
72     {
73     local modules
74     modules="$(hwinfo --gfxcard | grep "XFree86 v4 Server Module:" | cut -d: -f2)"
75    
76     # remove duplicates from list and show it
77     remove_duplicates "${modules}"
78     }
79    
80     # create_initrd {/path/to/initrd kernelversion </path/to/config>}
81     # when nothing given then /boot/initrd-$(uname -r).img $(uname -r) will be used
82     # default config path is /etc/conf.d/mkinitrd
83     create_initrd()
84     {
85     local initrd="$1"
86     local kernel="$2"
87     local config="$3"
88     local modules
89    
90     [[ -z ${initrd} ]] && initrd="/boot/initrd-$(uname -r).img"
91     [[ -z ${kernel} ]] && kernel="$(uname -r)"
92     [[ -z ${config} ]] && config="/etc/conf.d/mkinitrd"
93    
94     # get various modules needed to boot
95     modules="${modules} $(get_driver_modules disk)"
96     modules="${modules} $(get_driver_modules scsi)"
97     modules="${modules} $(get_driver_modules cdrom)"
98    
99     # remove all duplicate modules
100     modules="$(remove_duplicates ${modules})"
101    
102     # create the config and an initrd
103     echo "# autogenerated config file" > ${config}
104     echo "MODULES=\"${modules}\"" >> ${config}
105     echo "IMAGE_TYPE=\"initramfs\"" >> ${config}
106    
107     mkinitrd -f ${initrd} ${kernel}
108     }
109    
110     # special: memory (size), floppy (modprobe floppy), smp (support y/n)
111     # sound (which module? -> eval $(hwinfo --sound | grep "Driver Modules:" | cut -d: -f2 | sed s:\":a=\":) )
112     #
113    
114     # for i in cdrom cpu disk floppy gfxcard keyboard memory monitor mouse
115     # netcard pppoe scsi smp \
116     # sound wlan
117     # do
118     # echo -------- ${i}
119     # get_hwinfo ${i}
120     # echo -------------------------------------------------
121     # echo
122     # done
123    
124     # get_driver_modules sound
125     # get_driver_modules wlan
126     # get_driver_modules cdrom
127     # get_driver_modules disk
128     # get_driver_modules gfxcard
129     # get_x11_driver_modules
130    
131     # # get a modules list
132     # for i in sound wlan cdrom disk gfxcard
133     # do
134     # ALL_MODULES="${ALL_MODULES} $(get_driver_modules ${i})"
135     # done
136     # ALL_MODULES="${ALL_MODULES} $(get_x11_driver_modules)"
137     # # show a clean list
138     # for i in $(remove_duplicates ${ALL_MODULES})
139     # do
140     # echo ${i}
141     # done
142    
143     #create_initrd /root/TEST/initrd
144     #get_driver_modules cdrom
145     #get_driver_modules disk
146     #get_driver_modules scsi
147     #get_driver_modules all
148    
149     # network
150 niro 572 #get_hwinfo netcard
151     #get_driver_modules netcard
152 niro 571
153     #get_hwinfo disk
154     #get_hwinfo partition | grep /dev/hda