Magellan Linux

Annotation of /alx-src/branches/alxconf-060/bin/alx-hwdetection.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3201 - (hide annotations) (download) (as text)
Wed Sep 14 13:02:37 2011 UTC (12 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 3187 byte(s)
-added systemtype detection
1 niro 2622 #!/bin/bash
2    
3     # hwinfo wrapper to use hwinfo with sudo if requested
4     hwinfo()
5     {
6     local use_sudo=""
7     case ${SUDO} in
8     yes|y|true|1) use_sudo=sudo ;;
9     esac
10    
11     ${use_sudo} /usr/sbin/hwinfo $@
12     }
13    
14     # get_hwinfo $hw_item
15     get_hwinfo()
16     {
17     local enable_desc="0"
18    
19     if [[ $1 = --with-description ]] || [[ $1 = -d ]]
20     then
21     enable_desc=1
22     shift
23     fi
24    
25     local item="$1"
26     local all
27     local i
28    
29     # handle special items
30     case ${item} in
31     memory) get_hwinfo_memory; return ;;
32     smp) get_hwinfo_smp; return ;;
33     esac
34    
35     all=$(hwinfo --short --"${item}")
36    
37     declare -i i=0
38     while read device description
39     do
40     # skip the first line
41     (( i++ ))
42     [ ${i} -eq 1 ] && continue
43    
44     if [[ ${enable_desc} = 1 ]]
45     then
46     echo "${device};${description}"
47     else
48     echo "${device}"
49     fi
50     done <<< "${all}"
51     }
52    
53     # remove_duplicates $list
54     remove_duplicates()
55     {
56     local list="$@"
57     local fixed_list=":"
58     local i
59    
60     for i in ${list}
61     do
62     if [[ -z $(echo "${fixed_list}" | fgrep ":${i}:") ]]
63     then
64     fixed_list="${fixed_list}${i}:"
65     fi
66     done
67    
68     unset list
69    
70     # remove all ':' and show the cleaned list
71     # this way fixes double spaces also
72     local counter
73     declare -i counter=0
74     for i in $(echo ${fixed_list} | sed "s|:| |g")
75     do
76     (( counter++ ))
77     if [[ ${counter} -eq 1 ]]
78     then
79     list="${i}"
80     else
81     list+=" ${i}"
82     fi
83     done
84    
85     echo "${list}"
86     }
87    
88     get_x11_driver_modules()
89     {
90     local modules
91     modules="$(hwinfo --gfxcard | grep 'XFree86 v4 Server Module:' | sed 's/.*Module:\ \(.*\)/\1/')"
92    
93     # use vesa if nothing was found
94     [[ -z ${modules} ]] && modules="vesa"
95    
96     # remove duplicates from list and show it
97     remove_duplicates "${modules}"
98     }
99    
100     get_drm_driver_modules()
101     {
102     local modules
103     modules="$(hwinfo --gfxcard | grep 'Driver:' | sed 's/.*: \"\(.*\)\"/\1/;q')"
104    
105     # use vesa if nothing was found
106     [[ -z ${modules} ]] && modules="uvesafb"
107    
108     # remove duplicates from list and show it
109     remove_duplicates "${modules}"
110     }
111    
112     get_wlan_driver_modules()
113     {
114     local device="$1"
115     local modules
116    
117     if [[ -z ${device} ]]
118     then
119     echo "Error: get_netcard_driver_module(): no device given"
120     return 1
121     fi
122    
123     modules=$(hwinfo --wlan | grep -B1 "Device File: ${device}" | sed 's/.*Modules: \"\(.*\)\"/\1/;q')
124     remove_duplicates "${modules}"
125     }
126    
127     get_netcard_driver_modules()
128     {
129     local device="$1"
130     local modules
131    
132     if [[ -z ${device} ]]
133     then
134     echo "Error: get_netcard_driver_module(): no device given"
135     return 1
136     fi
137    
138     modules=$(hwinfo --netcard | grep -B1 "Device File: ${device}" | sed 's/.*Modules: \"\(.*\)\"/\1/;q')
139     remove_duplicates "${modules}"
140     }
141    
142 niro 3201 get_system_type()
143     {
144     local hwinfo
145     local systemtype
146    
147     hwinfo="$(hwinfo --bios --storage)"
148    
149     if [[ ! -z $(echo "${hwinfo}" | grep -i zotac) ]]
150     then
151     systemtype="zotac"
152     elif [[ ! -z $(echo "${hwinfo}" | grep -i CLE266) ]]
153     then
154     systemtype="rangee"
155     else
156     systemtype="standard"
157     fi
158    
159     echo "${systemtype}"
160     }
161    
162 niro 2622 # debug
163     #echo "LAN: $(get_netcard_driver_modules eth0)"
164     #echo "WLAN: $(get_wlan_driver_modules wlan0)"
165     #echo "X11: $(get_x11_driver_modules)"
166     #echo "KMS/FB: $(get_drm_driver_modules)"
167    
168     case $1 in
169     wlan) get_wlan_driver_modules wlan0 ;;
170     lan) get_netcard_driver_modules eth0 ;;
171     vga) get_x11_driver_modules ;;
172     console) get_drm_driver_modules ;;
173 niro 3201 system) get_system_type ;;
174 niro 2622 esac