xref: /haiku/3rdparty/mmu_man/scripts/HardwareChecker.sh (revision 25a7b01d15612846f332751841da3579db313082)
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_dmidecode () {
203	which dmidecode >/dev/null 2>&1 || return
204
205	# make sure /dev/mem is published
206	ls -l /dev/misc/mem > /dev/null
207
208	echo "<h2>DMIdecode output</h2>"
209	echo "<i>The output of dmidecode gives exact vendor and device identification.</i>"
210
211	echo "<h3><tt>dmidecode</tt></h3>"
212	echo "<i>(full output, stripped from the machine UUID)</i><br />"
213	echo "<textarea style='font-family: monospace' rows='10' cols='80' name='dmidecode_output' id='dmidecode_output' readonly='readonly'>"
214	dmidecode | grep -v 'UUID:'
215	echo "</textarea>"
216
217	dmidecode_bios_vendor="$(dmidecode -s bios-vendor)"
218	dmidecode_bios_version="$(dmidecode -s bios-version)"
219	dmidecode_bios_release_date="$(dmidecode -s bios-release-date)"
220	dmidecode_system_manufacturer="$(dmidecode -s system-manufacturer)"
221	dmidecode_system_product_name="$(dmidecode -s system-product-name)"
222	dmidecode_system_version="$(dmidecode -s system-version)"
223}
224
225check_machine ()
226{
227	echo "<h2>Machine</h2>"
228	echo "Vendor: <input type='text' name='machine_vendor' id='machine_vendor' placeholder='Lenovo,HP,Asus...' value='$dmidecode_system_manufacturer'/>"
229	echo "<br />"
230	echo "Model: <input type='text' name='machine_model' id='machine_model' placeholder='T510,l4500r...' value='$dmidecode_system_product_name' />"
231	echo "<br />"
232	echo "Specification page: <input type='url' name='machine_url' id='machine_url' placeholder='url of the model page on the vendor website' />"
233	echo "<br />"
234	echo "Comments: <br />"
235	echo "<textarea style='font-family: monospace' rows='10' cols='40' name='machine_comments' id='machine_comments' placeholder='specific options...'></textarea>"
236	echo "<br />"
237}
238
239check_haiku ()
240{
241	echo "<h2>Haiku</h2>"
242	uname_r="$(uname -r)"
243	uname_v="$(uname -v)"
244	echo "Release: <input type='text' name='uname_r' id='uname_r' value='$uname_r' readonly='readonly' size='6' />"
245	echo "<br />"
246	echo "Version: <input type='text' name='uname_v' id='uname_v' value='$uname_v' readonly='readonly' size='30' />"
247	echo "<br />"
248	echo "Comments: <br />"
249	echo "<textarea style='font-family: monospace' rows='4' cols='40' name='haiku_comments' id='haiku_comments' placeholder='Custom build, gcc4...' ></textarea>"
250	echo "<br />"
251}
252
253check_utils ()
254{
255	echo "<h2>Utilities output</h2>"
256	echo "<i>The output of some system utilities gives precious informations on the processor model and other stuff...</i>"
257
258	echo "<h3><tt>sysinfo</tt></h3>"
259	echo "<i>(system info)</i><br />"
260	echo "<textarea style='font-family: monospace' rows='10' cols='80' name='sysinfo_output' id='sysinfo_output' readonly='readonly'>"
261	sysinfo
262	echo "</textarea>"
263
264	echo "<h3><tt>listimage 1</tt></h3>"
265	echo "<i>(list of loaded kernel drivers)</i><br />"
266	echo "<textarea style='font-family: monospace' rows='10' cols='80' name='listimage_1_output' id='listimage_1_output' readonly='readonly'>"
267	listimage 1
268	echo "</textarea>"
269
270	echo "<h3><tt>ifconfig</tt></h3>"
271	echo "<i>(list of network interfaces)</i><br />"
272	echo "<textarea style='font-family: monospace' rows='10' cols='80' name='ifconfig_output' id='ifconfig_output' readonly='readonly'>"
273	ifconfig
274	echo "</textarea>"
275
276	echo "<h3><tt>installoptionalpackage -l</tt></h3>"
277	echo "<i>(list of installed packaged)</i><br />"
278	echo "<textarea style='font-family: monospace' rows='10' cols='80' name='installoptpkg_l_output' id='installoptpkg_l_output' readonly='readonly'>"
279	installoptionalpackage -l
280	echo "</textarea>"
281
282	echo "<br />"
283}
284
285check_syslog ()
286{
287	echo "<h2>System log</h2>"
288	echo "<div><i>Part of the system boot log that could help developer understand why some devices are not recognized...</i></div>"
289	echo "<textarea style='font-family: monospace' rows='10' cols='80' name='syslog' id='syslog' readonly='readonly'>"
290	cat /var/log/syslog
291	echo "</textarea>"
292
293}
294
295check_sender ()
296{
297	echo "<h2>Sender info (optional)</h2>"
298	echo "Name: <input type='text' name='sender_name' id='sender_name' placeholder='Your name' />"
299	echo "<br />"
300	echo "Mail: <input type='email' name='sender_name' id='sender_name' placeholder='contact email' />"
301	echo "<br />"
302	echo "Other comments: <br />"
303	echo "<textarea style='font-family: monospace' rows='4' cols='40' name='sender_comments' id='sender_comments' placeholder='IRC nickname on freenode...' ></textarea>"
304	echo "<br />"
305}
306
307check_all ()
308{
309	echo "<html>"
310	echo "<head>"
311	echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">'
312	echo "<title>Hardware report</title>"
313	#echo '<link rel="stylesheet" type="text/css" href="http://svn.haiku-os.org/haiku/haiku/trunk/docs/welcome/Haiku-doc.css">'
314
315	echo "<style type='text/css'>"
316	echo ".status_ok { color: #008000 }"
317	echo ".status_ko { color: #800000 }"
318	echo ".status_unkn { color: #000080 }"
319	echo "</style>"
320	echo "</head>"
321	echo "<body>"
322	echo "<div id='content'>"
323	echo "<form method='POST' action='$report_cgi'>"
324
325	do_notify 0.1 "Checking for PCI hardware..."
326	check_pci
327
328	do_notify 0.2 "Checking for USB hardware..."
329	check_usb
330
331	do_notify 0.3 "Checking for utility outputs..."
332	check_utils
333
334	do_notify 0.7 "Dumping syslog output..."
335	check_syslog
336
337	do_notify 0.8 "Checking machine infos..."
338	check_dmidecode
339	check_machine
340
341	do_notify 0.9 "Checking for Haiku version..."
342	check_haiku
343
344	check_sender
345
346	do_notify 1.0 "Done!" --timeout 3
347
348	echo "<div><i>Note: this form will only send data that is visible on this page.</i></div>"
349
350	echo "<input type='submit' name='submit' value='submit'>"
351
352	echo "</form>"
353	echo "</div>"
354	echo "</body>"
355	echo "</html>"
356}
357
358tf=/tmp/hw_checker_$$.html
359
360do_notify 0.0 "Checking for network..."
361detect_network
362
363check_all > "$tf"
364
365open "$tf"
366
367