Magellan Linux

Annotation of /trunk/installer/hwdetection.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 596 - (hide annotations) (download) (as text)
Mon Oct 15 20:49:40 2007 UTC (16 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 4579 byte(s)
-added hwinfo sudo-wrapper

1 niro 571 #!/bin/bash
2 niro 596 # $Header: /home/cvsd/magellan-cvs/magellan-src/installer/hwdetection.sh,v 1.7 2007-10-15 20:49:40 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     # remove all ':' and show the cleaned list
117 niro 573 # this way fixes double spaces also
118     for i in $(echo ${fixed_list} | sed "s|:| |g")
119     do
120     echo "${i}"
121     done
122 niro 571 }
123    
124     get_x11_driver_modules()
125     {
126     local modules
127     modules="$(hwinfo --gfxcard | grep "XFree86 v4 Server Module:" | cut -d: -f2)"
128    
129     # remove duplicates from list and show it
130     remove_duplicates "${modules}"
131     }
132    
133     # create_initrd {/path/to/initrd kernelversion </path/to/config>}
134     # when nothing given then /boot/initrd-$(uname -r).img $(uname -r) will be used
135     # default config path is /etc/conf.d/mkinitrd
136     create_initrd()
137     {
138     local initrd="$1"
139     local kernel="$2"
140     local config="$3"
141     local modules
142    
143     [[ -z ${initrd} ]] && initrd="/boot/initrd-$(uname -r).img"
144     [[ -z ${kernel} ]] && kernel="$(uname -r)"
145     [[ -z ${config} ]] && config="/etc/conf.d/mkinitrd"
146    
147     # get various modules needed to boot
148     modules="${modules} $(get_driver_modules disk)"
149     modules="${modules} $(get_driver_modules scsi)"
150     modules="${modules} $(get_driver_modules cdrom)"
151    
152     # remove all duplicate modules
153     modules="$(remove_duplicates ${modules})"
154    
155     # create the config and an initrd
156     echo "# autogenerated config file" > ${config}
157     echo "MODULES=\"${modules}\"" >> ${config}
158     echo "IMAGE_TYPE=\"initramfs\"" >> ${config}
159    
160     mkinitrd -f ${initrd} ${kernel}
161     }
162    
163     # special: memory (size), floppy (modprobe floppy), smp (support y/n)
164     # sound (which module? -> eval $(hwinfo --sound | grep "Driver Modules:" | cut -d: -f2 | sed s:\":a=\":) )
165     #
166    
167     # for i in cdrom cpu disk floppy gfxcard keyboard memory monitor mouse
168     # netcard pppoe scsi smp \
169     # sound wlan
170     # do
171     # echo -------- ${i}
172     # get_hwinfo ${i}
173     # echo -------------------------------------------------
174     # echo
175     # done
176    
177     # get_driver_modules sound
178     # get_driver_modules wlan
179     # get_driver_modules cdrom
180     # get_driver_modules disk
181     # get_driver_modules gfxcard
182     # get_x11_driver_modules
183    
184     # # get a modules list
185     # for i in sound wlan cdrom disk gfxcard
186     # do
187     # ALL_MODULES="${ALL_MODULES} $(get_driver_modules ${i})"
188     # done
189     # ALL_MODULES="${ALL_MODULES} $(get_x11_driver_modules)"
190     # # show a clean list
191     # for i in $(remove_duplicates ${ALL_MODULES})
192     # do
193     # echo ${i}
194     # done
195    
196     #create_initrd /root/TEST/initrd
197 niro 575 #get_driver_modules cdrom
198 niro 571 #get_driver_modules disk
199     #get_driver_modules scsi
200     #get_driver_modules all
201    
202     # network
203 niro 575 #get_hwinfo --with-description netcard
204 niro 572 #get_driver_modules netcard
205 niro 571
206     #get_hwinfo disk
207     #get_hwinfo partition | grep /dev/hda