Ticket #13671: hardwarechecker.sh

File hardwarechecker.sh, 11.8 KB (added by vidrep, 7 years ago)
Line 
1#!/bin/sh
2# HardwareChecker.sh for Haiku
3#
4# Copyright 2011-2014, François Revol <revol@free.fr>.
5#
6# Distributed under the MIT License
7#
8# Created: 2011-10-25
9#
10
11
12netcat=nc
13report_site=fake.haikuware.com
14report_cgi=http://haikuware.com/hwreport.php
15packages="dmidecode netcat"
16
17do_notify ()
18{
19 p="$1"
20 m="$2"
21 shift
22 shift
23 notify --type progress \
24 --messageID hwck_$$ \
25 --icon /system/apps/Devices \
26 --group HardwareChecker \
27 --title "progress:" --progress "$p" "$m" "$@"
28
29
30}
31
32try_install_packages ()
33{
34 which pkgman >/dev/null 2>&1 || return
35
36 for p in $packages; do
37 pkgman install "$p" || alert "Unable to install package '$p'" "Ok"
38 done
39}
40
41start_fake_httpd ()
42{
43 report_port=8989
44 report_file="$(finddir B_DESKTOP_DIRECTORY)/hwchecker_report_$$.txt"
45 report_ack="<html><head></head><body><h1>Done! You can close this window now.</h1></body></html>"
46 report_cgi=http://127.0.0.1:$report_port/hwreport
47 (
48 # force a previous instance to close
49 $netcat 127.0.0.1 8989 < /dev/null > /dev/null
50 echo "listening on port $report_port"
51 #
52 (echo -e "HTTP/1.1 100 Continue\r\n\r\n"; echo -e "HTTP/1.1 200 OK\r\nDate: $(date)\r\nContent-Type: text/html\r\nContent-Length: ${#report_ack}\r\n\r\n$report_ack") | $netcat -q 1 -l -p $report_port > "$report_file"
53
54 # make sure we have something
55 if [ -s "$report_file" ]; then
56 open "$report_file"
57 sleep 1
58 alert "A file named $(basename $report_file) has been created on your desktop. You can copy this file to an external drive to submit it with another operating system." "Ok"
59 else
60 rm "$report_file"
61 fi
62 ) &
63}
64
65detect_network ()
66{
67 ping -c 1 "$report_site"
68 if [ "$?" -gt 0 ]; then
69 alert --stop "Cannot contact the hardware report site ($report_site).
70You can continue anyway and generate a local file to submit later on, or try to configure networking." "Cancel" "Configure Network" "Continue"
71 case "$?" in
72 0)
73 exit 0
74 ;;
75 1)
76 /system/preferences/Network
77 detect_network
78 ;;
79 2)
80 start_fake_httpd
81 ;;
82 *)
83 exit 1
84 ;;
85 esac
86 fi
87}
88
89check_pci ()
90{
91 echo "<h2>PCI devices</h2><dl>"
92 echo "<div><i>List of detected PCI devices. This does not indicate that every probed device is supported by a driver.</i></div><br />"
93 devn=0
94 bus="pci"
95 vendor=''
96 device=''
97 true;
98 listdev | while read line; do
99
100 case "$line" in
101 device*)
102 case "$vendor" in
103 "")
104 desc="${line/device /}"
105 echo "<dt><b>$desc</b></dt>"
106 ;;
107 *)
108 devicestr=${line#*:}
109 device="${line%:*}"
110 device="${device#device }"
111 echo "<dd>"
112 echo "<div>$vendor:$device <i>$vendorstr:$devicestr</i></div>"
113 descline="$vendor:$device \"$vendorstr\" \"$devicestr\" $desc"
114 echo "<div>Identification: <input type='text' id='$bus${devn}_desc' name='$bus${devn}_desc' value='$descline' readonly='readonly' size='80' /></div>"
115
116 echo "<div>"
117 echo "<table border='0'>"
118 echo "<tr><td>"
119 echo "Status: "
120 echo "</td><td>"
121 echo "<input type='radio' name='$bus${devn}_status' id='$bus${devn}_status_ok' value='ok' /><label for='$bus${devn}_status_ok' class='status_ok'>Working</label>"
122 echo "</td></tr><tr><td></td><td>"
123 #echo "<br />"
124 echo "<input type='radio' name='$bus${devn}_status' id='$bus${devn}_status_ko' value='ko' /><label for='$bus${devn}_status_ko' class='status_ko'>Not working</label>"
125 echo "</td></tr><tr><td></td><td>"
126 #echo "<br />"
127 echo "<input type='radio' name='$bus${devn}_status' id='$bus${devn}_status_unkn' value='unkn' checked='checked' /><label for='$bus${devn}_status_unkn' class='status_unkn'>Unknown</label>"
128 echo "</td></tr>"
129 echo "</table>"
130 echo "</div>"
131
132 echo "<div>"
133 echo "Is it an add-in card (not part of the motherboard) ? "
134 echo "<input type='checkbox' name='$bus${devn}_addin' id='$bus${devn}_addin' /><label for='$bus${devn}_addin'>Yes</label>"
135 echo "</div>"
136
137 echo "<div>"
138 echo "Comment: "
139 echo "<input type='text' name='$bus${devn}_comment' id='$bus${devn}_comment' placeholder='bug, missing feature...' size='30' />"
140 echo "</div>"
141
142 echo "<br />"
143
144 echo "</dd>"
145
146 vendor=''
147 devn=$(($devn+1))
148 ;;
149 esac
150 ;;
151 vendor*)
152 vendorstr=${line#*:}
153 vendor="${line%:*}"
154 vendor="${vendor#vendor }"
155 ;;
156 *)
157 ;;
158 esac
159 done
160}
161
162check_usb ()
163{
164 echo "<h2>USB devices</h2><dl>"
165 echo "<div><i>List ot detected USB devices. This does not indicate that every probed device is supported by a driver.</i></div><br />"
166 devn=0
167 bus="usb"
168 listusb | while read vpid dev desc; do
169 echo "<dt><b>$desc</b></dt>"
170 echo "<dd>"
171 echo "<div>Identification: <input type='text' id='$bus${devn}_desc' name='$bus${devn}_desc' value='$vpid $dev $desc' readonly='readonly' size='80' /></div>"
172 if [ "$vpid" != "0000:0000" ]; then
173 enabled=1
174 id=""
175
176 echo "<div>"
177 echo "<table border='0'>"
178 echo "<tr><td>"
179 echo "Status: "
180 echo "</td><td>"
181 echo "<input type='radio' name='$bus${devn}_status' id='$bus${devn}_status_ok' value='ok' /><label for='$bus${devn}_status_ok' class='status_ok'>Working</label>"
182 echo "</td></tr><tr><td></td><td>"
183 #echo "<br />"
184 echo "<input type='radio' name='$bus${devn}_status' id='$bus${devn}_status_ko' value='ko' /><label for='$bus${devn}_status_ko' class='status_ko'>Not working</label>"
185 echo "</td></tr><tr><td></td><td>"
186 #echo "<br />"
187 echo "<input type='radio' name='$bus${devn}_status' id='$bus${devn}_status_unkn' value='unkn' checked='checked' /><label for='$bus${devn}_status_unkn' class='status_unkn'>Unknown</label>"
188 echo "</td></tr>"
189 echo "</table>"
190 echo "</div>"
191
192 echo "<div>"
193 echo "Is it an external device (not part of the motherboard) ? "
194 echo "<input type='checkbox' name='$bus${devn}_addin' id='$bus${devn}_addin' name='$bus${devn}_addin' /><label for='$bus${devn}_addin'>Yes</label>"
195 echo "</div>"
196
197 echo "<div>"
198 echo "Comment: "
199 echo "<input type='text' name='$bus${devn}_comment' id='$bus${devn}_comment' placeholder='bug, missing feature...' size='30' />"
200 echo "</div>"
201 else
202 echo "<div><i>(virtual device)</i></div>"
203 fi
204
205 echo "<br />"
206 echo "</dd>"
207 devn=$(($devn+1))
208 done
209 echo "</dl>"
210}
211
212check_dmidecode () {
213 which dmidecode >/dev/null 2>&1 || return
214
215 # make sure /dev/mem is published
216 ls -l /dev/misc/mem > /dev/null
217
218 echo "<h2>DMIdecode output</h2>"
219 echo "<i>The output of dmidecode gives exact vendor and device identification.</i>"
220
221 echo "<h3><tt>dmidecode</tt></h3>"
222 echo "<i>(full output, stripped from the machine UUID)</i><br />"
223 echo "<textarea style='font-family: monospace' rows='10' cols='80' name='dmidecode_output' id='dmidecode_output' readonly='readonly'>"
224 dmidecode | grep -v 'UUID:'
225 echo "</textarea>"
226
227 dmidecode_bios_vendor="$(dmidecode -s bios-vendor)"
228 dmidecode_bios_version="$(dmidecode -s bios-version)"
229 dmidecode_bios_release_date="$(dmidecode -s bios-release-date)"
230 dmidecode_system_manufacturer="$(dmidecode -s system-manufacturer)"
231 dmidecode_system_product_name="$(dmidecode -s system-product-name)"
232 dmidecode_system_version="$(dmidecode -s system-version)"
233}
234
235check_machine ()
236{
237 echo "<h2>Machine</h2>"
238 echo "Vendor: <input type='text' name='machine_vendor' id='machine_vendor' placeholder='Lenovo,HP,Asus...' value='$dmidecode_system_manufacturer'/>"
239 echo "<br />"
240 echo "Model: <input type='text' name='machine_model' id='machine_model' placeholder='T510,l4500r...' value='$dmidecode_system_product_name' />"
241 echo "<br />"
242 echo "Specification page: <input type='url' name='machine_url' id='machine_url' placeholder='url of the model page on the vendor website' />"
243 echo "<br />"
244 echo "Comments: <br />"
245 echo "<textarea style='font-family: monospace' rows='10' cols='40' name='machine_comments' id='machine_comments' placeholder='specific options...'></textarea>"
246 echo "<br />"
247}
248
249check_haiku ()
250{
251 echo "<h2>Haiku</h2>"
252 uname_r="$(uname -r)"
253 uname_v="$(uname -v)"
254 echo "Release: <input type='text' name='uname_r' id='uname_r' value='$uname_r' readonly='readonly' size='6' />"
255 echo "<br />"
256 echo "Version: <input type='text' name='uname_v' id='uname_v' value='$uname_v' readonly='readonly' size='30' />"
257 echo "<br />"
258 echo "Comments: <br />"
259 echo "<textarea style='font-family: monospace' rows='4' cols='40' name='haiku_comments' id='haiku_comments' placeholder='Custom build, gcc4...' ></textarea>"
260 echo "<br />"
261}
262
263check_utils ()
264{
265 echo "<h2>Utilities output</h2>"
266 echo "<i>The output of some system utilities gives precious informations on the processor model and other stuff...</i>"
267
268 echo "<h3><tt>sysinfo</tt></h3>"
269 echo "<i>(system info)</i><br />"
270 echo "<textarea style='font-family: monospace' rows='10' cols='80' name='sysinfo_output' id='sysinfo_output' readonly='readonly'>"
271 sysinfo
272 echo "</textarea>"
273
274 echo "<h3><tt>listimage 1</tt></h3>"
275 echo "<i>(list of loaded kernel drivers)</i><br />"
276 echo "<textarea style='font-family: monospace' rows='10' cols='80' name='listimage_1_output' id='listimage_1_output' readonly='readonly'>"
277 listimage 1
278 echo "</textarea>"
279
280 echo "<h3><tt>ifconfig</tt></h3>"
281 echo "<i>(list of network interfaces)</i><br />"
282 echo "<textarea style='font-family: monospace' rows='10' cols='80' name='ifconfig_output' id='ifconfig_output' readonly='readonly'>"
283 ifconfig
284 echo "</textarea>"
285
286 echo "<h3><tt>pkgman list-repos</tt></h3>"
287 echo "<i>(list of configured package repositories)</i><br />"
288 echo "<textarea style='font-family: monospace' rows='10' cols='80' name='pkgman_list_repos_output' id='pkgman_list_repos_output' readonly='readonly'>"
289 pkgman list-repos
290 echo "</textarea>"
291
292 echo "<h3><tt>pkgman search -a</tt></h3>"
293 echo "<i>(list of installed packaged)</i><br />"
294 echo "<textarea style='font-family: monospace' rows='10' cols='80' name='pkgman_search_a_output' id='pkgman_search_a_output' readonly='readonly'>"
295 pkgman search -a
296 echo "</textarea>"
297
298 echo "<br />"
299}
300
301check_syslog ()
302{
303 echo "<h2>System log</h2>"
304 echo "<div><i>Part of the system boot log that could help developer understand why some devices are not recognized...</i></div>"
305 echo "<textarea style='font-family: monospace' rows='10' cols='80' name='syslog' id='syslog' readonly='readonly'>"
306 cat /var/log/syslog
307 echo "</textarea>"
308
309}
310
311check_sender ()
312{
313 echo "<h2>Sender info (optional)</h2>"
314 echo "Name: <input type='text' name='sender_name' id='sender_name' placeholder='Your name' />"
315 echo "<br />"
316 echo "Mail: <input type='email' name='sender_name' id='sender_name' placeholder='contact email' />"
317 echo "<br />"
318 echo "Other comments: <br />"
319 echo "<textarea style='font-family: monospace' rows='4' cols='40' name='sender_comments' id='sender_comments' placeholder='IRC nickname on freenode...' ></textarea>"
320 echo "<br />"
321}
322
323check_all ()
324{
325 echo "<html>"
326 echo "<head>"
327 echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">'
328 echo "<title>Hardware report</title>"
329 #echo '<link rel="stylesheet" type="text/css" href="http://svn.haiku-os.org/haiku/haiku/trunk/docs/welcome/Haiku-doc.css">'
330
331 echo "<style type='text/css'>"
332 echo ".status_ok { color: #008000 }"
333 echo ".status_ko { color: #800000 }"
334 echo ".status_unkn { color: #000080 }"
335 echo "</style>"
336 echo "</head>"
337 echo "<body>"
338 echo "<div id='content'>"
339 echo "<form method='POST' action='$report_cgi'>"
340
341 do_notify 0.1 "Checking for PCI hardware..."
342 check_pci
343
344 do_notify 0.2 "Checking for USB hardware..."
345 check_usb
346
347 do_notify 0.3 "Checking for utility outputs..."
348 check_utils
349
350 do_notify 0.7 "Dumping syslog output..."
351 check_syslog
352
353 do_notify 0.8 "Checking machine infos..."
354 check_dmidecode
355 check_machine
356
357 do_notify 0.9 "Checking for Haiku version..."
358 check_haiku
359
360 check_sender
361
362 do_notify 1.0 "Done!" --timeout 3
363
364 echo "<div><i>Note: this form will only send data that is visible on this page.</i></div>"
365
366 echo "<input type='submit' name='submit' value='submit'>"
367
368 echo "</form>"
369 echo "</div>"
370 echo "</body>"
371 echo "</html>"
372}
373
374tf=/tmp/hw_checker_$$.html
375
376do_notify 0.0 "Checking for needed packages..."
377try_install_packages
378
379do_notify 0.0 "Checking for network..."
380detect_network
381
382check_all > "$tf"
383
384open "$tf"