xref: /haiku/3rdparty/mmu_man/scripts/HardwareChecker.sh (revision 6f6d1e36fd792356e7de5a99a3ba8141c16fb80e)
19829800dSFrançois Revol#!/bin/sh
29829800dSFrançois Revol#	HardwareChecker.sh for Haiku
39829800dSFrançois Revol#
49829800dSFrançois Revol#	Copyright 2011, François Revol <revol@free.fr>.
59829800dSFrançois Revol#
69829800dSFrançois Revol#	Distributed under the MIT License
79829800dSFrançois Revol#
89829800dSFrançois Revol#	Created: 2011-10-25
99829800dSFrançois Revol#
109829800dSFrançois Revol
119829800dSFrançois Revol
129829800dSFrançois Revolnetcat=netcat
139829800dSFrançois Revolreport_site=haikuware.con
149829800dSFrançois Revolreport_cgi=http://haikuware.com/hwreport.php
159829800dSFrançois Revol
1693b9886aSFrançois Revoldo_notify ()
1793b9886aSFrançois Revol{
1893b9886aSFrançois Revol	p="$1"
1993b9886aSFrançois Revol	m="$2"
2093b9886aSFrançois Revol	shift
2193b9886aSFrançois Revol	shift
2293b9886aSFrançois Revol	notify --type progress \
2393b9886aSFrançois Revol		--messageID hwck_$$ \
2493b9886aSFrançois Revol		--icon /system/apps/Devices \
2593b9886aSFrançois Revol		--app HardwareChecker \
2693b9886aSFrançois Revol		--title "progress:" --progress "$p" "$m" "$@"
2793b9886aSFrançois Revol
2893b9886aSFrançois Revol
2993b9886aSFrançois Revol}
3093b9886aSFrançois Revol
319829800dSFrançois Revolstart_fake_httpd ()
329829800dSFrançois Revol{
339829800dSFrançois Revol	report_port=8989
349829800dSFrançois Revol	report_file="$(finddir B_DESKTOP_DIRECTORY)/hwchecker_report_$$.txt"
3519618f8bSFrançois Revol	report_ack="<html><head></head><body><h1>Done! You can close this window now.</h1></body></html>"
369829800dSFrançois Revol	report_cgi=http://127.0.0.1:$report_port/hwreport
379829800dSFrançois Revol	(
386c278c3bSFrançois Revol		# force a previous isntance to close
396c278c3bSFrançois Revol		$netcat 127.0.0.1 8989 < /dev/null > /dev/null
409829800dSFrançois Revol		echo "listening on port $report_port"
419829800dSFrançois Revol		#
429829800dSFrançois Revol		(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"
439829800dSFrançois Revol
446c278c3bSFrançois Revol		# make sure we have something
456c278c3bSFrançois Revol		if [ -s "$report_file" ]; then
469829800dSFrançois Revol			open "$report_file"
479829800dSFrançois Revol			sleep 1
489829800dSFrançois Revol			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"
496c278c3bSFrançois Revol		else
506c278c3bSFrançois Revol			rm "$report_file"
516c278c3bSFrançois Revol		fi
529829800dSFrançois Revol	) &
539829800dSFrançois Revol}
549829800dSFrançois Revol
559829800dSFrançois Revoldetect_network ()
569829800dSFrançois Revol{
579829800dSFrançois Revol	ping -c 1 "$report_site"
589829800dSFrançois Revol	if [ "$?" -gt 0 ]; then
599829800dSFrançois Revol		alert --stop "Cannot contact the hardware report site ($report_site).
609829800dSFrançois RevolYou can continue anyway and generate a local file to submit later on, or try to configure networking." "Cancel" "Configure Network" "Continue"
619829800dSFrançois Revol		case "$?" in
629829800dSFrançois Revol		0)
639829800dSFrançois Revol			exit 0
649829800dSFrançois Revol			;;
659829800dSFrançois Revol		1)
669829800dSFrançois Revol			/system/preferences/Network
679829800dSFrançois Revol			detect_network
689829800dSFrançois Revol			;;
699829800dSFrançois Revol		2)
709829800dSFrançois Revol			start_fake_httpd
719829800dSFrançois Revol			;;
729829800dSFrançois Revol		*)
739829800dSFrançois Revol			exit 1
749829800dSFrançois Revol			;;
759829800dSFrançois Revol		esac
769829800dSFrançois Revol	fi
779829800dSFrançois Revol}
789829800dSFrançois Revol
799829800dSFrançois Revolcheck_pci ()
809829800dSFrançois Revol{
819829800dSFrançois Revol	echo "<h2>PCI devices</h2><dl>"
829829800dSFrançois Revol	echo "<div><i>List ot detected PCI devices. This does not indicate that every probed device is supported by a driver.</i></div><br />"
839829800dSFrançois Revol	devn=0
849829800dSFrançois Revol	bus="pci"
859829800dSFrançois Revol	vendor=''
869829800dSFrançois Revol	device=''
879829800dSFrançois Revol	true;
889829800dSFrançois Revol	listdev | while read line; do
899829800dSFrançois Revol
909829800dSFrançois Revol	case "$line" in
919829800dSFrançois Revol	device*)
929829800dSFrançois Revol		case "$vendor" in
939829800dSFrançois Revol		"")
949829800dSFrançois Revol			desc="${line/device /}"
959829800dSFrançois Revol			echo "<dt><b>$desc</b></dt>"
969829800dSFrançois Revol			;;
979829800dSFrançois Revol		*)
989829800dSFrançois Revol			devicestr=${line#*:}
999829800dSFrançois Revol			device="${line%:*}"
1009829800dSFrançois Revol			device="${device#device }"
1019829800dSFrançois Revol			echo "<dd>"
1029829800dSFrançois Revol			echo "<div>$vendor:$device <i>$vendorstr:$devicestr</i></div>"
1039829800dSFrançois Revol			descline="$vendor:$device \"$vendorstr\" \"$devicestr\" $desc"
10418b34d36SFrançois Revol			echo "<div>Identification: <input type='text' id='$bus${devn}_desc' name='$bus${devn}_desc' value='$descline' readonly='readonly' size='80' /></div>"
1059829800dSFrançois Revol
1069829800dSFrançois Revol			echo "<div>"
10718b34d36SFrançois Revol			echo "<table border='0'>"
10818b34d36SFrançois Revol			echo "<tr><td>"
1099829800dSFrançois Revol			echo "Status: "
11018b34d36SFrançois Revol			echo "</td><td>"
1112362652aSFrançois Revol			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>"
11218b34d36SFrançois Revol			echo "</td></tr><tr><td></td><td>"
11318b34d36SFrançois Revol			#echo "<br />"
1142362652aSFrançois Revol			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>"
11518b34d36SFrançois Revol			echo "</td></tr><tr><td></td><td>"
11618b34d36SFrançois Revol			#echo "<br />"
1172362652aSFrançois Revol			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>"
11818b34d36SFrançois Revol			echo "</td></tr>"
11918b34d36SFrançois Revol			echo "</table>"
1209829800dSFrançois Revol			echo "</div>"
1219829800dSFrançois Revol
1229829800dSFrançois Revol			echo "<div>"
1239829800dSFrançois Revol			echo "Is it an add-in card (not part of the motherboard) ? "
1249829800dSFrançois Revol			echo "<input type='checkbox' name='$bus${devn}_addin' id='$bus${devn}_addin' /><label for='$bus${devn}_addin'>Yes</label>"
1259829800dSFrançois Revol			echo "</div>"
1269829800dSFrançois Revol
1279829800dSFrançois Revol			echo "<div>"
1289829800dSFrançois Revol			echo "Comment: "
1299829800dSFrançois Revol			echo "<input type='text' name='$bus${devn}_comment' id='$bus${devn}_comment' placeholder='bug, missing feature...' size='30' />"
1309829800dSFrançois Revol			echo "</div>"
1319829800dSFrançois Revol
1322362652aSFrançois Revol			echo "<br />"
1332362652aSFrançois Revol
1349829800dSFrançois Revol			echo "</dd>"
1359829800dSFrançois Revol
1369829800dSFrançois Revol			vendor=''
1379829800dSFrançois Revol			devn=$(($devn+1))
1389829800dSFrançois Revol			;;
1399829800dSFrançois Revol		esac
1409829800dSFrançois Revol		;;
1419829800dSFrançois Revol	vendor*)
1429829800dSFrançois Revol		vendorstr=${line#*:}
1439829800dSFrançois Revol		vendor="${line%:*}"
1449829800dSFrançois Revol		vendor="${vendor#vendor }"
1459829800dSFrançois Revol		;;
1469829800dSFrançois Revol	*)
1479829800dSFrançois Revol		;;
1489829800dSFrançois Revol	esac
1499829800dSFrançois Revol	done
1509829800dSFrançois Revol}
1519829800dSFrançois Revol
1529829800dSFrançois Revolcheck_usb ()
1539829800dSFrançois Revol{
1549829800dSFrançois Revol	echo "<h2>USB devices</h2><dl>"
1559829800dSFrançois Revol	echo "<div><i>List ot detected USB devices. This does not indicate that every probed device is supported by a driver.</i></div><br />"
1569829800dSFrançois Revol	devn=0
1579829800dSFrançois Revol	bus="usb"
1589829800dSFrançois Revol	listusb | while read vpid dev desc; do
1599829800dSFrançois Revol		echo "<dt><b>$desc</b></dt>"
1609829800dSFrançois Revol		echo "<dd>"
16118b34d36SFrançois Revol		echo "<div>Identification: <input type='text' id='$bus${devn}_desc' name='$bus${devn}_desc' value='$vpid $dev $desc' readonly='readonly' size='80' /></div>"
1629829800dSFrançois Revol		if [ "$vpid" != "0000:0000" ]; then
1639829800dSFrançois Revol			enabled=1
1649829800dSFrançois Revol			id=""
16518b34d36SFrançois Revol
1669829800dSFrançois Revol			echo "<div>"
16718b34d36SFrançois Revol			echo "<table border='0'>"
16818b34d36SFrançois Revol			echo "<tr><td>"
1699829800dSFrançois Revol			echo "Status: "
17018b34d36SFrançois Revol			echo "</td><td>"
1712362652aSFrançois Revol			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>"
17218b34d36SFrançois Revol			echo "</td></tr><tr><td></td><td>"
17318b34d36SFrançois Revol			#echo "<br />"
1742362652aSFrançois Revol			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>"
17518b34d36SFrançois Revol			echo "</td></tr><tr><td></td><td>"
17618b34d36SFrançois Revol			#echo "<br />"
1772362652aSFrançois Revol			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>"
17818b34d36SFrançois Revol			echo "</td></tr>"
17918b34d36SFrançois Revol			echo "</table>"
1809829800dSFrançois Revol			echo "</div>"
1819829800dSFrançois Revol
1829829800dSFrançois Revol			echo "<div>"
1839829800dSFrançois Revol			echo "Is it an external device (not part of the motherboard) ? "
1849829800dSFrançois Revol			echo "<input type='checkbox' name='$bus${devn}_addin' id='$bus${devn}_addin' name='$bus${devn}_addin' /><label for='$bus${devn}_addin'>Yes</label>"
1859829800dSFrançois Revol			echo "</div>"
1869829800dSFrançois Revol
1879829800dSFrançois Revol			echo "<div>"
1889829800dSFrançois Revol			echo "Comment: "
1899829800dSFrançois Revol			echo "<input type='text' name='$bus${devn}_comment' id='$bus${devn}_comment' placeholder='bug, missing feature...' size='30' />"
1909829800dSFrançois Revol			echo "</div>"
1919829800dSFrançois Revol		else
1922362652aSFrançois Revol			echo "<div><i>(virtual device)</i></div>"
1939829800dSFrançois Revol		fi
1942362652aSFrançois Revol
1952362652aSFrançois Revol		echo "<br />"
1969829800dSFrançois Revol		echo "</dd>"
1979829800dSFrançois Revol		devn=$(($devn+1))
1989829800dSFrançois Revol	done
1999829800dSFrançois Revol	echo "</dl>"
2009829800dSFrançois Revol}
2019829800dSFrançois Revol
2029829800dSFrançois Revolcheck_machine ()
2039829800dSFrançois Revol{
2049829800dSFrançois Revol	echo "<h2>Machine</h2>"
205*6f6d1e36SFrançois Revol	echo "Vendor: <input type='text' name='machine_vendor' id='machine_vendor' placeholder='Lenovo,HP,Asus...' />"
2069829800dSFrançois Revol	echo "<br />"
2079829800dSFrançois Revol	echo "Model: <input type='text' name='machine_model' id='machine_model' placeholder='T510,l4500r...' />"
2089829800dSFrançois Revol	echo "<br />"
2099829800dSFrançois Revol	echo "Specification page: <input type='url' name='machine_url' id='machine_url' placeholder='url of the model page on the vendor website' />"
2109829800dSFrançois Revol	echo "<br />"
2119829800dSFrançois Revol	echo "Comments: <br />"
2129829800dSFrançois Revol	echo "<textarea style='font-family: monospace' rows='10' cols='40' name='machine_comments' id='machine_comments' placeholder='specific options...'></textarea>"
2139829800dSFrançois Revol	echo "<br />"
2149829800dSFrançois Revol}
2159829800dSFrançois Revol
2169829800dSFrançois Revolcheck_haiku ()
2179829800dSFrançois Revol{
2189829800dSFrançois Revol	echo "<h2>Haiku</h2>"
2199829800dSFrançois Revol	uname_r="$(uname -r)"
2209829800dSFrançois Revol	uname_v="$(uname -v)"
2219829800dSFrançois Revol	echo "Release: <input type='text' name='uname_r' id='uname_r' value='$uname_r' readonly='readonly' size='6' />"
2229829800dSFrançois Revol	echo "<br />"
2239829800dSFrançois Revol	echo "Version: <input type='text' name='uname_v' id='uname_v' value='$uname_v' readonly='readonly' size='30' />"
2249829800dSFrançois Revol	echo "<br />"
2259829800dSFrançois Revol	echo "Comments: <br />"
2269829800dSFrançois Revol	echo "<textarea style='font-family: monospace' rows='4' cols='40' name='haiku_comments' id='haiku_comments' placeholder='Custom build, gcc4...' ></textarea>"
2279829800dSFrançois Revol	echo "<br />"
2289829800dSFrançois Revol}
2299829800dSFrançois Revol
2309829800dSFrançois Revolcheck_utils ()
2319829800dSFrançois Revol{
2329829800dSFrançois Revol	echo "<h2>Utilities output</h2>"
2339829800dSFrançois Revol	echo "<i>The output of some system utilities gives precious informations on the processor model and other stuff...</i>"
2349829800dSFrançois Revol
2359829800dSFrançois Revol	echo "<h3><tt>sysinfo</tt></h3>"
2369829800dSFrançois Revol	echo "<i>(system info)</i><br />"
2379829800dSFrançois Revol	echo "<textarea style='font-family: monospace' rows='10' cols='80' name='sysinfo_output' id='sysinfo_output' readonly='readonly'>"
2389829800dSFrançois Revol	sysinfo
2399829800dSFrançois Revol	echo "</textarea>"
2409829800dSFrançois Revol
2419829800dSFrançois Revol	echo "<h3><tt>listimage 1</tt></h3>"
2429829800dSFrançois Revol	echo "<i>(list of loaded kernel drivers)</i><br />"
2439829800dSFrançois Revol	echo "<textarea style='font-family: monospace' rows='10' cols='80' name='listimage_1_output' id='listimage_1_output' readonly='readonly'>"
2449829800dSFrançois Revol	listimage 1
2459829800dSFrançois Revol	echo "</textarea>"
2469829800dSFrançois Revol
2479829800dSFrançois Revol	echo "<h3><tt>ifconfig</tt></h3>"
2489829800dSFrançois Revol	echo "<i>(list of network interfaces)</i><br />"
2499829800dSFrançois Revol	echo "<textarea style='font-family: monospace' rows='10' cols='80' name='ifconfig_output' id='ifconfig_output' readonly='readonly'>"
2509829800dSFrançois Revol	ifconfig
2519829800dSFrançois Revol	echo "</textarea>"
2529829800dSFrançois Revol
2539829800dSFrançois Revol	echo "<h3><tt>installoptionalpackage -l</tt></h3>"
2549829800dSFrançois Revol	echo "<i>(list of installed packaged)</i><br />"
2559829800dSFrançois Revol	echo "<textarea style='font-family: monospace' rows='10' cols='80' name='installoptpkg_l_output' id='installoptpkg_l_output' readonly='readonly'>"
2569829800dSFrançois Revol	installoptionalpackage -l
2579829800dSFrançois Revol	echo "</textarea>"
2589829800dSFrançois Revol
2599829800dSFrançois Revol	echo "<br />"
2609829800dSFrançois Revol}
2619829800dSFrançois Revol
2629829800dSFrançois Revolcheck_syslog ()
2639829800dSFrançois Revol{
2649829800dSFrançois Revol	echo "<h2>System log</h2>"
2659829800dSFrançois Revol	echo "<div><i>Part of the system boot log that could help developer understand why some devices are not recognized...</i></div>"
2669829800dSFrançois Revol	echo "<textarea style='font-family: monospace' rows='10' cols='80' name='syslog' id='syslog' readonly='readonly'>"
2679829800dSFrançois Revol	cat /var/log/syslog
2689829800dSFrançois Revol	echo "</textarea>"
2699829800dSFrançois Revol
2709829800dSFrançois Revol}
2719829800dSFrançois Revol
2729829800dSFrançois Revolcheck_sender ()
2739829800dSFrançois Revol{
2749829800dSFrançois Revol	echo "<h2>Sender info (optional)</h2>"
2759829800dSFrançois Revol	echo "Name: <input type='text' name='sender_name' id='sender_name' placeholder='Your name' />"
2769829800dSFrançois Revol	echo "<br />"
2779829800dSFrançois Revol	echo "Mail: <input type='email' name='sender_name' id='sender_name' placeholder='contact email' />"
2789829800dSFrançois Revol	echo "<br />"
2799829800dSFrançois Revol	echo "Other comments: <br />"
2809829800dSFrançois Revol	echo "<textarea style='font-family: monospace' rows='4' cols='40' name='sender_comments' id='sender_comments' placeholder='IRC nickname on freenode...' ></textarea>"
2819829800dSFrançois Revol	echo "<br />"
2829829800dSFrançois Revol}
2839829800dSFrançois Revol
2849829800dSFrançois Revolcheck_all ()
2859829800dSFrançois Revol{
2869829800dSFrançois Revol	echo "<html>"
2872362652aSFrançois Revol	echo "<head>"
28818b34d36SFrançois Revol	echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">'
2892362652aSFrançois Revol	echo "<title>Hardware report</title>"
29018b34d36SFrançois Revol	#echo '<link rel="stylesheet" type="text/css" href="http://svn.haiku-os.org/haiku/haiku/trunk/docs/welcome/Haiku-doc.css">'
29118b34d36SFrançois Revol
2922362652aSFrançois Revol	echo "<style type='text/css'>"
2932362652aSFrançois Revol	echo ".status_ok { color: #008000 }"
2942362652aSFrançois Revol	echo ".status_ko { color: #800000 }"
2952362652aSFrançois Revol	echo ".status_unkn { color: #000080 }"
2962362652aSFrançois Revol	echo "</style>"
2972362652aSFrançois Revol	echo "</head>"
2989829800dSFrançois Revol	echo "<body>"
29918b34d36SFrançois Revol	echo "<div id='content'>"
3009829800dSFrançois Revol	echo "<form method='POST' action='$report_cgi'>"
3019829800dSFrançois Revol
30293b9886aSFrançois Revol	do_notify 0.1 "Checking for PCI hardware..."
3039829800dSFrançois Revol	check_pci
30493b9886aSFrançois Revol
30593b9886aSFrançois Revol	do_notify 0.3 "Checking for USB hardware..."
3069829800dSFrançois Revol	check_usb
30793b9886aSFrançois Revol
30893b9886aSFrançois Revol	do_notify 0.5 "Checking for Haiku version..."
3099829800dSFrançois Revol	check_haiku
31093b9886aSFrançois Revol
31193b9886aSFrançois Revol	do_notify 0.6 "Checking for utility outputs..."
3129829800dSFrançois Revol	check_utils
31393b9886aSFrançois Revol
31493b9886aSFrançois Revol	do_notify 0.8 "Dumping syslog output..."
3159829800dSFrançois Revol	check_syslog
316*6f6d1e36SFrançois Revol
317*6f6d1e36SFrançois Revol	check_machine
3189829800dSFrançois Revol	check_sender
3199829800dSFrançois Revol
3206c278c3bSFrançois Revol	do_notify 1.0 "Done!" --timeout 3
32193b9886aSFrançois Revol
3229829800dSFrançois Revol	echo "<div><i>Note: this form will only send data that is visible on this page.</i></div>"
3239829800dSFrançois Revol
3249829800dSFrançois Revol	echo "<input type='submit' name='submit' value='submit'>"
3259829800dSFrançois Revol
3269829800dSFrançois Revol	echo "</form>"
32718b34d36SFrançois Revol	echo "</div>"
3289829800dSFrançois Revol	echo "</body>"
3299829800dSFrançois Revol	echo "</html>"
3309829800dSFrançois Revol}
3319829800dSFrançois Revol
3329829800dSFrançois Revoltf=/tmp/hw_checker_$$.html
3339829800dSFrançois Revol
33493b9886aSFrançois Revoldo_notify 0.0 "Checking for network..."
3359829800dSFrançois Revoldetect_network
3369829800dSFrançois Revol
3379829800dSFrançois Revolcheck_all > "$tf"
3389829800dSFrançois Revol
3399829800dSFrançois Revolopen "$tf"
3409829800dSFrançois Revol
341