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=haikuware.con 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 ot 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 "Identification: <input type='text' id='$bus${devn}_desc' name='$bus${devn}_desc' value='$descline' readonly='readonly' size='80' />" 105 106 echo "<div>" 107 echo "Status: " 108 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>" 109 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>" 110 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>" 111 echo "</div>" 112 113 echo "<div>" 114 echo "Is it an add-in card (not part of the motherboard) ? " 115 echo "<input type='checkbox' name='$bus${devn}_addin' id='$bus${devn}_addin' /><label for='$bus${devn}_addin'>Yes</label>" 116 echo "</div>" 117 118 echo "<div>" 119 echo "Comment: " 120 echo "<input type='text' name='$bus${devn}_comment' id='$bus${devn}_comment' placeholder='bug, missing feature...' size='30' />" 121 echo "</div>" 122 123 echo "<br />" 124 125 echo "</dd>" 126 127 vendor='' 128 devn=$(($devn+1)) 129 ;; 130 esac 131 ;; 132 vendor*) 133 vendorstr=${line#*:} 134 vendor="${line%:*}" 135 vendor="${vendor#vendor }" 136 ;; 137 *) 138 ;; 139 esac 140 done 141} 142 143check_usb () 144{ 145 echo "<h2>USB devices</h2><dl>" 146 echo "<div><i>List ot detected USB devices. This does not indicate that every probed device is supported by a driver.</i></div><br />" 147 devn=0 148 bus="usb" 149 listusb | while read vpid dev desc; do 150 echo "<dt><b>$desc</b></dt>" 151 echo "<dd>" 152 echo "Identification: <input type='text' id='$bus${devn}_desc' name='$bus${devn}_desc' value='$vpid $dev $desc' readonly='readonly' disabled='disabled' size='80' />" 153 if [ "$vpid" != "0000:0000" ]; then 154 enabled=1 155 id="" 156 echo "<div>" 157 echo "Status: " 158 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>" 159 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>" 160 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>" 161 echo "</div>" 162 163 echo "<div>" 164 echo "Is it an external device (not part of the motherboard) ? " 165 echo "<input type='checkbox' name='$bus${devn}_addin' id='$bus${devn}_addin' name='$bus${devn}_addin' /><label for='$bus${devn}_addin'>Yes</label>" 166 echo "</div>" 167 168 echo "<div>" 169 echo "Comment: " 170 echo "<input type='text' name='$bus${devn}_comment' id='$bus${devn}_comment' placeholder='bug, missing feature...' size='30' />" 171 echo "</div>" 172 else 173 echo "<div><i>(virtual device)</i></div>" 174 fi 175 176 echo "<br />" 177 echo "</dd>" 178 devn=$(($devn+1)) 179 done 180 echo "</dl>" 181} 182 183check_machine () 184{ 185 echo "<h2>Machine</h2>" 186 echo "Vendor: <input type='text' name='machine_vendor' id='machine_vendor' value='Lenovo,HP,Asus...' />" 187 echo "<br />" 188 echo "Model: <input type='text' name='machine_model' id='machine_model' placeholder='T510,l4500r...' />" 189 echo "<br />" 190 echo "Specification page: <input type='url' name='machine_url' id='machine_url' placeholder='url of the model page on the vendor website' />" 191 echo "<br />" 192 echo "Comments: <br />" 193 echo "<textarea style='font-family: monospace' rows='10' cols='40' name='machine_comments' id='machine_comments' placeholder='specific options...'></textarea>" 194 echo "<br />" 195} 196 197check_haiku () 198{ 199 echo "<h2>Haiku</h2>" 200 uname_r="$(uname -r)" 201 uname_v="$(uname -v)" 202 echo "Release: <input type='text' name='uname_r' id='uname_r' value='$uname_r' readonly='readonly' size='6' />" 203 echo "<br />" 204 echo "Version: <input type='text' name='uname_v' id='uname_v' value='$uname_v' readonly='readonly' size='30' />" 205 echo "<br />" 206 echo "Comments: <br />" 207 echo "<textarea style='font-family: monospace' rows='4' cols='40' name='haiku_comments' id='haiku_comments' placeholder='Custom build, gcc4...' ></textarea>" 208 echo "<br />" 209} 210 211check_utils () 212{ 213 echo "<h2>Utilities output</h2>" 214 echo "<i>The output of some system utilities gives precious informations on the processor model and other stuff...</i>" 215 216 echo "<h3><tt>sysinfo</tt></h3>" 217 echo "<i>(system info)</i><br />" 218 echo "<textarea style='font-family: monospace' rows='10' cols='80' name='sysinfo_output' id='sysinfo_output' readonly='readonly'>" 219 sysinfo 220 echo "</textarea>" 221 222 echo "<h3><tt>listimage 1</tt></h3>" 223 echo "<i>(list of loaded kernel drivers)</i><br />" 224 echo "<textarea style='font-family: monospace' rows='10' cols='80' name='listimage_1_output' id='listimage_1_output' readonly='readonly'>" 225 listimage 1 226 echo "</textarea>" 227 228 echo "<h3><tt>ifconfig</tt></h3>" 229 echo "<i>(list of network interfaces)</i><br />" 230 echo "<textarea style='font-family: monospace' rows='10' cols='80' name='ifconfig_output' id='ifconfig_output' readonly='readonly'>" 231 ifconfig 232 echo "</textarea>" 233 234 echo "<h3><tt>installoptionalpackage -l</tt></h3>" 235 echo "<i>(list of installed packaged)</i><br />" 236 echo "<textarea style='font-family: monospace' rows='10' cols='80' name='installoptpkg_l_output' id='installoptpkg_l_output' readonly='readonly'>" 237 installoptionalpackage -l 238 echo "</textarea>" 239 240 echo "<br />" 241} 242 243check_syslog () 244{ 245 echo "<h2>System log</h2>" 246 echo "<div><i>Part of the system boot log that could help developer understand why some devices are not recognized...</i></div>" 247 echo "<textarea style='font-family: monospace' rows='10' cols='80' name='syslog' id='syslog' readonly='readonly'>" 248 cat /var/log/syslog 249 echo "</textarea>" 250 251} 252 253check_sender () 254{ 255 echo "<h2>Sender info (optional)</h2>" 256 echo "Name: <input type='text' name='sender_name' id='sender_name' placeholder='Your name' />" 257 echo "<br />" 258 echo "Mail: <input type='email' name='sender_name' id='sender_name' placeholder='contact email' />" 259 echo "<br />" 260 echo "Other comments: <br />" 261 echo "<textarea style='font-family: monospace' rows='4' cols='40' name='sender_comments' id='sender_comments' placeholder='IRC nickname on freenode...' ></textarea>" 262 echo "<br />" 263} 264 265check_all () 266{ 267 echo "<html>" 268 echo "<head>" 269 echo "<title>Hardware report</title>" 270 echo "<style type='text/css'>" 271 echo ".status_ok { color: #008000 }" 272 echo ".status_ko { color: #800000 }" 273 echo ".status_unkn { color: #000080 }" 274 echo "</style>" 275 echo "</head>" 276 echo "<body>" 277 echo "<form method='POST' action='$report_cgi'>" 278 279 do_notify 0.1 "Checking for PCI hardware..." 280 check_pci 281 282 do_notify 0.3 "Checking for USB hardware..." 283 check_usb 284 285 do_notify 0.5 "Checking for Haiku version..." 286 check_haiku 287 288 do_notify 0.6 "Checking for utility outputs..." 289 check_utils 290 291 do_notify 0.8 "Dumping syslog output..." 292 check_syslog 293 check_sender 294 295 do_notify 1.0 "Done!" --timeout 3 296 297 echo "<div><i>Note: this form will only send data that is visible on this page.</i></div>" 298 299 echo "<input type='submit' name='submit' value='submit'>" 300 301 echo "</form>" 302 echo "</body>" 303 echo "</html>" 304} 305 306tf=/tmp/hw_checker_$$.html 307 308do_notify 0.0 "Checking for network..." 309detect_network 310 311check_all > "$tf" 312 313open "$tf" 314 315