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