wait4usb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. #this is called from 'init', runs as parallel process.
  3. #110710 rewritten for kernel with hid and usb drivers builtin, and without my usb-storage patch.
  4. #110713 have put my usb-storage patch back in to kernel (2.6.39-3).
  5. #120330 mmc drives may be slow to become ready, so add them in here.
  6. mount -t usbfs none /proc/bus/usb
  7. #sleep 1
  8. USBSTORAGES=0 ; CNTUSB=0
  9. while [ $USBSTORAGES -eq 0 ];do
  10. sleep 1
  11. echo -n "." > /dev/console
  12. CNTUSB=$(($CNTUSB+1))
  13. [ $CNTUSB -gt 5 ] && break
  14. #v412 bug, ubuntu kernel, got duplicate 'device found at 2', need 'sort -u'...
  15. USBSTORAGES=`/bin/dmesg | grep "usb-storage: device found at" | sort -u | wc -l`
  16. [ $USBSTORAGES -eq 0 ] && break
  17. AVAILABLEUSBSTORAGES=`/bin/dmesg | grep "usb-storage: device scan complete" | wc -l`
  18. [ $USBSTORAGES -ne $AVAILABLEUSBSTORAGES ] && USBSTORAGES=0
  19. done
  20. #i want this to work with kernel that does not have my usb-storage patch, feedback is that 3 secs is enough...
  21. while [ $CNTUSB -lt 3 ];do
  22. sleep 1
  23. CNTUSB=$(($CNTUSB+1))
  24. echo -en "\\033[1;33m.\\033[0;39m" >/dev/console #yellow dot
  25. done
  26. #wait for usb partitions to become available...
  27. #entries in /sys/block show up, but ex /sys/block/sda/sda1 takes a bit longer...
  28. #note, if usb card-reader plugged in but no cards inserted, this will timeout...
  29. #note, will also timeout if usb optical drive (sr), but ok, they need extra time...
  30. ALLUSBDRVS="`find /sys/block -maxdepth 1 -name 'sd*' -o -name 'sr*' | xargs -l readlink 2>/dev/null | grep '/usb[0-9]' | rev | cut -f 1 -d '/' | rev | tr '\n' ' '`"
  31. [ "$ALLUSBDRVS" = " " ] && ALLUSBDRVS=""
  32. for ONEDRV in $ALLUSBDRVS
  33. do
  34. while [ ! -e /sys/block/${ONEDRV}/${ONEDRV}1 ];do
  35. sleep 1
  36. echo -en "\\033[1;31m.\\033[0;39m" >/dev/console #red dot
  37. CNTUSB=$(($CNTUSB+1))
  38. [ $CNTUSB -gt 6 ] && break
  39. done
  40. #force update of /proc/partitions...
  41. dd if=/dev/${ONEDRV} of=/dev/null bs=512 count=1 >/dev/null 2>&1
  42. done
  43. #120330 probe for mmc drives...
  44. MMCDRVS=""
  45. if [ "`grep '^mmc' /tmp/ALLDRVS0`" = "" ];then #find out if already available.
  46. [ "`lsmod | grep '^mmc'`" != "" ] && MMCDRVS="`find /sys/block -maxdepth 1 -name 'mmc*' | tr '\n' ' '`"
  47. [ "$MMCDRVS" = " " ] && MMCDRVS=""
  48. fi
  49. echo -n "$ALLUSBDRVS" > /tmp/flag-usb-ready
  50. [ "$MMCDRVS" ] && echo -n " ${MMCDRVS}" >> /tmp/flag-usb-ready
  51. ###end###