pupscan 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. #!/bin/sh
  2. #(c) Copyright 2006 Barry Kauler www.puppylinux.com
  3. #2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  4. #v3.01 BK 11oct07: bugfix, crash when choose usb button.
  5. #BK v3.98: improve create mono font in status log.
  6. #v425 rerwin: read device IDs from modules.alias and dialup-modem rules, instead of pci/usbmaps; choose last match, corresponding to backend_modprobe.
  7. #v431 rerwin: Add --silent option to only generate files, without display.
  8. #100108 BK 'scanpci' is not working properly xorg 7.5. actually it is no longer part of libpciaccess pkg.
  9. #101221 yaf-splash fix.
  10. #110814 01micko: convert script from gtkdialog2 to gtkdialog3+.
  11. #110816 distinguish between inbuilt drivers and modules.
  12. #110910 BK: gtkdialog3 (patriot-e version) syntax error, bump to gtkdialog4.
  13. #120202 BK: internationalized.
  14. #130326 3.5+ kernel no longer supports /proc/bus/usb, use script usb-devices.
  15. #130331 change "Mono 12" to "Mono 10", for 96 dpi.
  16. #140211 zigbert: gui (gtkdialog) improvements.
  17. export TEXTDOMAIN=pupscan
  18. export OUTPUT_CHARSET=UTF-8
  19. [ "`echo $@ | grep ' *--silent *'`" != "" ] && SILENT=true || SILENT=false #v431
  20. KERNVER="`uname -r`"
  21. ZDRV='' #set in PUPSTATE.
  22. #variables created at bootup by init script in initrd...
  23. . /etc/rc.d/PUPSTATE
  24. #v4.02 common functions...
  25. . /etc/rc.d/functions4puppy4
  26. if [ "$SILENT" != "true" ];then #100108
  27. /usr/lib/gtkdialog/box_splash -close never -text "$(gettext 'Please wait, probing hardware...')" &
  28. YSPID=$!
  29. fi
  30. ALL_MODULES="`cat /lib/modules/${KERNVER}/modules.dep | cut -f 1 -d ':' | rev | cut -f 1 -d '/' | cut -f 2 -d '.' | rev | tr '-' '_'`" #110816
  31. echo "$ALL_MODULES" > /tmp/pupscan_all_modules #110816
  32. MODITEMS=""
  33. for ONEMOD in `lsmod | grep -v '^Module ' | cut -f 1 -d ' ' | tr '\n' ' '`
  34. do
  35. MODITEMS="$MODITEMS<item>$ONEMOD</item>"
  36. done
  37. #v4.02 all mods now present...
  38. PCIMODINFO="`cat /lib/modules/$KERNVER/modules.alias | tr -s " " | grep '^alias pci:' | sed -e 's/alias pci:v/0x/' \
  39. -e 's/^0x\*/0xffffffff/' \
  40. -e 's/d\(0000....\)sv[^ ]*/ 0x\1/' \
  41. -e 's/d\*sv[^ ]*/ 0xffffffff/' \
  42. | tr [A-F] [a-f]`"
  43. [ -s /etc/udev/rules.d/??-dialup-modem.rules ] && RULEMODINFO="`cat /etc/udev/rules.d/??-dialup-modem.rules | tr -s " " | grep '^ATTR{vendor}==' | sed -e 's/ATTR{vendor}==\"0x\(....\)\",/0x0000\1/' \
  44. -e 's/ATTR{device}==\"0x\([^\"]*\)\",.*RUN[^ ]*/0x0000\1/' \
  45. -e 's/0x0000[^ ]*\[.*\][^ ]*/0xffffffff/' \
  46. -e 's/\"$//'`" || RULEMODINFO=""
  47. [ "$RULEMODINFO" != "" ] && PCIMODINFO="$RULEMODINFO
  48. $PCIMODINFO"
  49. echo -n "" > /tmp/chipnummod.txt
  50. #100108 puppy builds now have the full pci.ids file...
  51. if [ ! -e /usr/share/pci.ids ];then
  52. #this is the old code...
  53. if [ "`which scanpci`" = "" ];then
  54. echo "$(gettext 'PCI scan utility scanpci not available. This must be a
  55. cutdown Puppy (scanpci is part of the Xorg package).
  56. Simplified information only is displayed here:')
  57. " >> /tmp/chipnummod.txt
  58. elspci -l >> /tmp/chipnummod.txt
  59. else
  60. scanpci |
  61. while read ONELINE
  62. do
  63. VENDOR="`echo -n "$ONELINE" | grep '^pci' | grep -o 'vendor .*' | cut -f 2 -d ' ' | cut -f 2 -d 'x'`"
  64. CHIPNO="`echo -n "$ONELINE" | grep '^pci' | grep -o 'device .*' | cut -f 2 -d ' ' | cut -f 2 -d 'x'`"
  65. if [ "$VENDOR" ];then
  66. read NEXTLINE
  67. CHIPDESC="`echo -n "$NEXTLINE" | cut -f 2 -d '[' | cut -f 2 -d ']'`"
  68. LVENDOR="0x0000$VENDOR"
  69. LCHIPNO="0x0000$CHIPNO"
  70. APATTERN="$LVENDOR $LCHIPNO"
  71. FNDMOD="`echo "$PCIMODINFO" | grep "$APATTERN" | tail -n 1`" #v425
  72. MODULE="unknown"
  73. [ ! "$FNDMOD" = "" ] && MODULE="`echo -n "$FNDMOD" | cut -f 3 -d " "`" #v425
  74. if [ "$MODULE" = "unknown" ];then
  75. #find out if it is a usb module...
  76. UPATTERN=" ${VENDOR}:${CHIPNO} "
  77. [ ! "`elspci -l | grep -i "$UPATTERN" | grep '0C0300'`" = "" ] && MODULE="uhci-hcd"
  78. [ ! "`elspci -l | grep -i "$UPATTERN" | grep '0C0310'`" = "" ] && MODULE="ohci-hcd"
  79. [ ! "`elspci -l | grep -i "$UPATTERN" | grep '0C0320'`" = "" ] && MODULE="ehci-hcd"
  80. fi
  81. echo "DESCRIPTION: $CHIPDESC" >> /tmp/chipnummod.txt
  82. if [ "`echo "$MODULE" | tr '-' '_' | grep -x -f /tmp/pupscan_all_modules`" != "" ];then #110816
  83. echo "VENDOR: $VENDOR DEVICE: $CHIPNO KERNEL MODULE: $MODULE" >> /tmp/chipnummod.txt
  84. else
  85. echo "VENDOR: $VENDOR DEVICE: $CHIPNO KERNEL DRIVER (builtin): $MODULE" >> /tmp/chipnummod.txt
  86. fi
  87. echo >> /tmp/chipnummod.txt
  88. fi
  89. done
  90. fi
  91. else
  92. FIRSTSET=true #110816 rerwin: improve spacing.
  93. lspci -nn -k | tr '|' ' ' | tr -s ' ' | tr '\t' '|' | grep -v 'Subsystem: ' |
  94. while read ONELINE
  95. do
  96. if [ "`echo "$ONELINE" | cut -c 1`" != "|" ];then
  97. [ $FIRSTSET = true ] || echo >> /tmp/chipnummod.txt #110816 rerwin
  98. DESCRIPTION="DESCRIPTION: `echo -n "${ONELINE}" | cut -f 2-99 -d ' ' | rev | cut -f 2-9 -d '[' | rev | sed -e 's% \[.*\]:%:%'`"
  99. echo "$DESCRIPTION" >> /tmp/chipnummod.txt
  100. CHIPNUMS="VENDOR: `echo -n "$ONELINE" | rev | cut -f 1 -d '[' | cut -f 2 -d ']' | rev | sed -e 's%:% DEVICE: %'`"
  101. echo "$CHIPNUMS" >> /tmp/chipnummod.txt
  102. FIRSTSET=false #110816 rerwin
  103. else
  104. MODULE="`echo "$ONELINE" | rev | cut -f 1 -d ':' | cut -f 1 -d ' ' | rev`"
  105. if [ "`echo "$MODULE" | tr '-' '_' | grep -x -f /tmp/pupscan_all_modules`" != "" ];then #110816
  106. KMODULE="KERNEL MODULE: ${MODULE}"
  107. else
  108. KMODULE="KERNEL DRIVER (builtin): ${MODULE}"
  109. fi
  110. echo "$KMODULE" >> /tmp/chipnummod.txt
  111. #echo >> /tmp/chipnummod.txt
  112. fi
  113. done
  114. fi
  115. [ ! -s /tmp/chipnummod.txt ] && echo "No PCI interfaces" > /tmp/chipnummod.txt #v3.01
  116. # <action>/tmp/formatfunc.sh 30</action>
  117. #v2.17 usb devices...
  118. USBSECTION=""
  119. echo -n "" > /tmp/usbchipnummod.txt
  120. #130326 3.5+ kernel no longer supports /proc/bus/usb, use script usb-devices...
  121. USBDEVICES=""
  122. [ -e /proc/bus/usb ] && USBDEVICES="`cat /proc/bus/usb/devices`"
  123. [ ! "$USBDEVICES" ] && [ "`which usb-devices`" != "" ] && USBDEVICES="`usb-devices`" #usb-devices is script in usbutils pkg.
  124. if [ "$USBDEVICES" ];then
  125. #v4.02...
  126. USBMODINFO="`cat /lib/modules/$KERNVER/modules.alias | tr -s " " | grep '^alias usb:' | sed -e 's/alias usb:v/0x/' -e 's/^0x\*/0xffff/' -e 's/p\(....\)d[^ ]*/ 0x\1/' -e 's/p\*d[^ ]*/ 0xffff/' | tr [A-F] [a-f]`"
  127. #...returns module-name vendor-id product-id
  128. USBNUMS="`echo "$USBDEVICES" | grep '^P: ' | tr -s ' ' | cut -f 2-3 -d ' ' | tr ' ' '|' | tr [A-Z] [a-z] | tr '\n' ' '`"
  129. for ONENUM in $USBNUMS
  130. do
  131. VENDOR="`echo -n "$ONENUM" | cut -f 1 -d '|' | cut -f 2 -d '='`"
  132. PRODUCT="`echo -n "$ONENUM" | cut -f 2 -d '|' | cut -f 2 -d '='`"
  133. ONEUSB="0x${VENDOR} 0x${PRODUCT}"
  134. [ "$ONEUSB" = "0x0000 0x0000" ] && continue
  135. YESPARA=no
  136. USBMODULE=""
  137. rm -f /tmp/usbmodulexxx
  138. echo -n "" > /tmp/usbdevdescr
  139. echo "$USBDEVICES" | tr -s ' ' |
  140. while read ONELINE
  141. do
  142. zPATTERN="Vendor=${VENDOR} ProdID=${PRODUCT}"
  143. [ "`echo -n "$ONELINE" | grep "$zPATTERN"`" != "" ] && YESPARA=yes
  144. if [ "$YESPARA" = "yes" ];then
  145. xDRIVER="`echo -n "$ONELINE" | grep '^I:' | grep -o ' Driver=.*' | cut -f 2 -d '='`"
  146. [ "$xDRIVER" != "" ] && echo -n "$xDRIVER" > /tmp/usbmodulexxx
  147. xDESCR="`echo -n "$ONELINE" | grep '^S:' | cut -f 2-20 -d ' '`"
  148. [ "$xDESCR" != "" ] && echo "$xDESCR" >> /tmp/usbdevdescr
  149. [ "$ONELINE" = "" ] && break
  150. fi
  151. done
  152. [ ! -s /tmp/usbdevdescr ] && [ "`grep ' ' /tmp/usbmodulexxx`" != "" ] && echo "Product=`cat /tmp/usbmodulexxx`" > /tmp/usbdevdescr && rm /tmp/usbmodulexxx #v425
  153. [ -f /tmp/usbmodulexxx ] && USBMODULE="`cat /tmp/usbmodulexxx`"
  154. [ "$USBMODULE" = "" ] && USBMODULE="`echo "$USBMODINFO" | grep "$ONEUSB" | cut -f 3 -d ' ' | tail -n 1`" #v425
  155. cat /tmp/usbdevdescr >> /tmp/usbchipnummod.txt
  156. if [ "`echo "$USBMODULE" | tr '-' '_' | grep -x -f /tmp/pupscan_all_modules`" != "" ];then #110816
  157. echo "VendorID=$VENDOR ProductID=$PRODUCT KERNEL-MODULE=$USBMODULE" >> /tmp/usbchipnummod.txt
  158. else
  159. echo "VendorID=$VENDOR ProductID=$PRODUCT KERNEL-DRIVER(builtin)=$USBMODULE" >> /tmp/usbchipnummod.txt
  160. fi
  161. echo >> /tmp/usbchipnummod.txt
  162. done
  163. [ ! -s /tmp/usbchipnummod.txt ] && echo "No plugged-in USB devices" > /tmp/usbchipnummod.txt #v3.01
  164. USBSECTION='
  165. <hseparator></hseparator>
  166. <hbox border-width="7" space-expand="true" space-fill="true">
  167. <text xalign="0" use-markup="true" space-expand="true" space-fill="true"><label>"'$(gettext '<b>USB devices</b>
  168. USB interfaces are part of the PCI interfaces, but to find information about any plugged-in USB devices, click this button.')'"</label></text>
  169. <text space-expand="false" space-fill="false"><label>""</label></text>
  170. <vbox space-expand="false" space-fill="false">
  171. <button>
  172. '"`/usr/lib/gtkdialog/xml_button-icon plug_usb.svg big`"'
  173. <action>cp -f /tmp/usbchipnummod.txt /tmp/hwproberesult.txt</action>
  174. <action>refresh:INFO</action>
  175. </button>
  176. </vbox>
  177. </hbox>'
  178. fi
  179. PupScan='
  180. <window title="'$(gettext 'Puppy hardware-interfaces information')'" icon-name="gtk-preferences">
  181. <vbox>
  182. <vbox space-expand="false" space-fill="false">
  183. <frame>
  184. '"`/usr/lib/gtkdialog/xml_info fixed hardware_detect.svg 60 " " "<b>$(gettext "Find information about your hardware")</b>"`"'
  185. <vbox border-width="7" space-expand="false" space-fill="false">
  186. <hbox space-expand="true" space-fill="true">
  187. <text xalign="0" use-markup="true" space-expand="true" space-fill="true"><label>"'$(gettext '<b>Kernel modules</b>
  188. At bootup, Puppy examines the hardware interfaces to determine what kernel drivers (modules) to load, and does so. Click this button for information on loaded modules.')'"</label></text>
  189. <text space-expand="false" space-fill="false"><label>""</label></text>
  190. <vbox space-expand="false" space-fill="false">
  191. <button>
  192. '"`/usr/lib/gtkdialog/xml_button-icon module.svg big`"'
  193. <action>eval /tmp/hwprobelsmod</action>
  194. <action>refresh:INFO</action>
  195. </button>
  196. </vbox>
  197. </hbox>
  198. <hbox space-expand="true" space-fill="true">
  199. <text xalign="0" use-markup="true" space-expand="true" space-fill="true"><label>"'$(gettext 'More <b>details</b> on each loaded module.')'"</label></text>
  200. <combobox>
  201. <variable>MODCOMBO</variable>
  202. '$MODITEMS'
  203. </combobox>
  204. <text space-expand="false" space-fill="false"><label>""</label></text>
  205. <vbox space-expand="false" space-fill="false">
  206. <button>
  207. '"`/usr/lib/gtkdialog/xml_button-icon module_yes.svg big`"'
  208. <action>eval /tmp/hwprobemodinfo \$MODCOMBO</action>
  209. <action>refresh:INFO</action>
  210. </button>
  211. </vbox>
  212. </hbox>
  213. </vbox>
  214. <hseparator></hseparator>
  215. <hbox border-width="7" space-expand="true" space-fill="true">
  216. <text xalign="0" use-markup="true" space-expand="true" space-fill="true"><label>"'$(gettext '<b>PCI interfaces</b>
  217. Most of the hardware interfaces inside a PC are 'PCI' devices. Click this button for a scan of all the PCI interfaces.')'"</label></text>
  218. <text space-expand="false" space-fill="false"><label>""</label></text>
  219. <vbox space-expand="false" space-fill="false">
  220. <button>
  221. '"`/usr/lib/gtkdialog/xml_button-icon card_pci.svg big`"'
  222. <action>cp -f /tmp/chipnummod.txt /tmp/hwproberesult.txt</action>
  223. <action>refresh:INFO</action>
  224. </button>
  225. </vbox>
  226. </hbox>
  227. '${USBSECTION}'
  228. </frame>
  229. </vbox>
  230. <vbox space-expand="true" space-fill="true">
  231. <edit space-expand="true" space-fill="true">
  232. <variable>INFO</variable>
  233. <input file>/tmp/hwproberesult.txt</input>
  234. </edit>
  235. </vbox>
  236. <hbox space-expand="false" space-fill="false">
  237. <button>
  238. '"`/usr/lib/gtkdialog/xml_button-icon quit`"'
  239. <label>'$(gettext 'Quit')'</label>
  240. <action type="exit">EXIT_NOW</action>
  241. </button>
  242. </hbox>
  243. </vbox>
  244. </window>'
  245. rm -f /tmp/hwproberesult.txt #v425 erase stale info
  246. if [ "`which scanpci`" = "" ];then
  247. echo 'echo "This must be a cutdown Puppy that does not have the scanpci utility
  248. (which is part of the Xorg package). So, cannot give a detailed
  249. report on the PCI bus. Instead can display this summary only. The
  250. most useful information here is the vendor:chip numbers (column-3):
  251. " >/tmp/hwproberesult.txt
  252. lspci -n >>/tmp/hwproberesult.txt' >/tmp/hwprobescanpci
  253. else
  254. echo 'scanpci >/tmp/hwproberesult.txt' >/tmp/hwprobescanpci
  255. fi
  256. chmod 755 /tmp/hwprobescanpci
  257. echo 'lsmod >/tmp/hwproberesult.txt' >/tmp/hwprobelsmod
  258. chmod 755 /tmp/hwprobelsmod
  259. echo 'modinfo $1 > /tmp/hwproberesult.txt 2>&1' >/tmp/hwprobemodinfo
  260. chmod 755 /tmp/hwprobemodinfo
  261. #v3.98 improved...
  262. #130331 change Mono 12 to Mono 10...
  263. echo 'style "specialmono"
  264. {
  265. font_name="Mono 10"
  266. }
  267. class "GtkText*" style "specialmono"' > /tmp/gtkrc_mono
  268. export GTK2_RC_FILES=/tmp/gtkrc_mono:/root/.gtkrc-2.0
  269. [ "$SILENT" != "true" ] && kill $YSPID #100108
  270. if [ $SILENT != true ]; then
  271. . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
  272. RETSTRING="`echo "$PupScan" | gtkdialog --stdin`"
  273. fi
  274. ###END###