Annotation of /alx-src/branches/alxconf-060/bin/alx-hwdetection.sh
Parent Directory | Revision Log
Revision 2622 -
(hide annotations)
(download)
(as text)
Wed Jul 6 23:27:35 2011 UTC (13 years, 2 months ago) by niro
File MIME type: application/x-sh
File size: 2848 byte(s)
Wed Jul 6 23:27:35 2011 UTC (13 years, 2 months ago) by niro
File MIME type: application/x-sh
File size: 2848 byte(s)
-added hwdetection script for webfrontend
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 | # debug | ||
143 | #echo "LAN: $(get_netcard_driver_modules eth0)" | ||
144 | #echo "WLAN: $(get_wlan_driver_modules wlan0)" | ||
145 | #echo "X11: $(get_x11_driver_modules)" | ||
146 | #echo "KMS/FB: $(get_drm_driver_modules)" | ||
147 | |||
148 | case $1 in | ||
149 | wlan) get_wlan_driver_modules wlan0 ;; | ||
150 | lan) get_netcard_driver_modules eth0 ;; | ||
151 | vga) get_x11_driver_modules ;; | ||
152 | console) get_drm_driver_modules ;; | ||
153 | esac |