home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / hplj1000 < prev    next >
Encoding:
Text File  |  2007-03-27  |  3.9 KB  |  185 lines

  1. #!/bin/sh
  2.  
  3. #    hplj1000:
  4. #    hplj1005:
  5. #    hplj1020:
  6. #
  7. #    Hotplug script for HP1000/1005 USB laser printers.  The model number
  8. #    that this script deals with is determined from the script name.
  9. #
  10. #    Used to download firmware automatically into the printer when it
  11. #    is powered up or plugged into the USB port.
  12. #
  13. #    Also, run this script once with the magic argument "install-usermap"
  14. #    to create the proper entry in the /etc/hotplug/usb.usermap file.
  15. #
  16. #    The inspiration fo this script is from:
  17. #        Oscar Santacreu. Alicante-Spain (2002)
  18. #        Mike Morgan (2004)
  19. #
  20.  
  21. # udev calls us twice on FC4! Just want /dev/usb/lp<N>
  22. case "$DEVNAME" in
  23. /dev/usb/usb*)    exit;;
  24. esac
  25.  
  26. PROGNAME="$0"
  27.  
  28. #
  29. # Set $DEV to, e.g. /dev/usb/lp0, to force the device you want
  30. # Else, leave it null to automatically detect the device
  31. #
  32. DEV=/dev/usb/lp0
  33. DEV=""
  34.  
  35. #
  36. # Directory to find downloadable HP firmware files sihpMMMM.dl
  37. #
  38. FWDIR=/usr/share/foo2zjs/firmware
  39.  
  40. #
  41. # Program used to determine USB id information
  42. #
  43. USBID=/usr/bin/usb_printerid
  44.  
  45. #
  46. #    Figure out how to log our messages
  47. #
  48. if [ -t 1 ]; then
  49.     # Running from a tty...
  50.     log() {
  51.     echo "$PROGNAME: $@"
  52.     }
  53. elif [ -x /usr/bin/logger ]; then
  54.     # Have logger...
  55.     log() {
  56.     logger -t "$PROGNAME" -- "$@"
  57.     }
  58. else
  59.     # No logger...
  60.     log() {
  61.     echo "$PROGNAME: $@" >> /var/log/messages
  62.     }
  63. fi
  64.  
  65. #
  66. #    Figure out the model number from the name of this script
  67. #
  68. case "$0" in
  69. *1000)
  70.     MODEL=1000
  71.     USB1=0x03f0    #Vendor
  72.     USB2=0x0517    #Model
  73.     ;;
  74. *1005)
  75.     MODEL=1005
  76.     USB1=0x03f0    #Vendor
  77.     USB2=0x1317    #Model
  78.     ;;
  79. *1018)
  80.     MODEL=1018
  81.     USB1=0x03f0 #Vendor
  82.     USB2=0x4117 #Model
  83.     ;;
  84. *1020)
  85.     MODEL=1020
  86.     USB1=0x03f0 #Vendor
  87.     USB2=0x2b17 #Model
  88.     ;;
  89. *)
  90.     log "Only HP LaserJet 1000, 1005, 1018, and 1020 are supported"
  91.     exit
  92.     ;;
  93. esac
  94.  
  95. #
  96. #    The special command line argument "install-usermap" will install
  97. #    the proper entry into the /etc/hotplug/usb.usermap file
  98. #
  99. case "$1" in
  100. install-usermap)
  101.     if [ "$USB2" != "" ]; then
  102.     if [ -w /etc/hotplug/usb.usermap ]; then
  103.         USERMAP=/etc/hotplug/usb.usermap
  104.     elif [ -d /etc/hotplug/usb/ ]; then
  105.         USERMAP=/etc/hotplug/usb/foo2zjs.usermap
  106.         if [ ! -s $USERMAP ]; then
  107.             echo > $USERMAP
  108.         fi
  109.     else
  110.         log "No /etc/hotplug usermap!"
  111.         exit
  112.     fi
  113.     ex - $USERMAP <<-EOF
  114.     g/^hplj$MODEL/d
  115.     \$a
  116.     hplj$MODEL 0x0003 $USB1 $USB2 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
  117.     .
  118.     w
  119.     q
  120.     EOF
  121.     else
  122.     log "I don't know the USB info for this model yet.  Please run"
  123.     log "usb_printerid on the usb device and send the output to:"
  124.     log "rick.richardson@comcast.net"
  125.     fi
  126.     exit
  127.     ;;
  128. esac
  129.  
  130. #
  131. #    Procedure to load a single device with firmware
  132. #
  133. load1() {
  134.     _dev="$1"
  135.     fw="$FWDIR/sihp$MODEL.dl"
  136.     if [ ! -f "$fw" ]; then
  137.     log "Missing HP LaserJet $MODEL firmware file $fw"
  138.     log "...read foo2zjs installation instructions and run ./getweb $MODEL"
  139.     return 1
  140.     fi
  141.  
  142.     log "loading HP LaserJet $MODEL firmware $fw to $_dev ..."
  143.     # There is a timeout problem with udev and FC4, so spin it off.
  144.     (
  145.     if cat $fw > $_dev; then
  146.         log "... download successful."
  147.     else
  148.         log "... download failed."
  149.     fi
  150.     ) &
  151.     return 0
  152. }
  153.  
  154. #
  155. #    OK, now download firmware to any printers that need it
  156. #
  157. if [ "$DEV" != "" ]; then
  158.     #
  159.     # force downloading to a specific device
  160.     #
  161.     load1 "$DEV"
  162. elif [ -x $USBID ]; then
  163.     #
  164.     # Sniff around for printers that need a firmware download
  165.     #
  166.     usblps=`find /dev/usb -name lp*`" "`find /dev -name usblp*`
  167.     for dev in $usblps; do
  168.     status=`$USBID $dev 2>/dev/null | grep -y "hp LaserJet $MODEL"`
  169.     if [ "$status" != "" ]; then
  170.         # This is a LaserJet 100x
  171.         chmod 0666 $dev
  172.         status=`$USBID $dev | grep 'FWVER'`
  173.         if [ "$status" = "" ]; then
  174.         # Firmware is not yet loaded
  175.         load1 "$dev"
  176.         else
  177.         log "HP LaserJet $MODEL firmware already loaded into $dev"
  178.         fi
  179.     fi
  180.     done
  181. else
  182.     log "HP LaserJet $MODEL firmware was not downloaded..."
  183.     log "...couldn't find $USBID and DEV is not set"
  184. fi
  185.