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