File: hplj1000

package info (click to toggle)
foo2zjs 20050217-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,364 kB
  • ctags: 2,122
  • sloc: ansic: 15,074; xml: 1,751; makefile: 503; sh: 269; perl: 102
file content (153 lines) | stat: -rwxr-xr-x 3,341 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/sh

#	hplj1000:
#	hplj1005:
#
#	Hotplug script for HP1000/1005 USB laser printers.  The model number
#	that this script deals with is determined from the script name.
#
#	Used to download firmware automatically into the printer when it
#	is powered up or plugged into the USB port.
#
#	Also, run this script once with the magic argument "install-usermap"
#	to create the proper entry in the /etc/hotplug/usb.usermap file.
#
#	The inspiration fo this script is from:
#		Oscar Santacreu. Alicante-Spain (2002)
#		Mike Morgan (2004)
#

PROGNAME="$0"

#
# Set $DEV to, e.g. /dev/usb/lp0, to force the device you want
# Else, leave it null to automatically detect the device
#
DEV=/dev/usb/lp0
DEV=""

#
# Directory to find downloadable HP firmware files sihpMMMM.dl
#
FWDIR=/usr/share/foo2zjs/firmware

#
# Program used to determine USB id information
#
USBID=/usr/bin/usb_printerid

#
#	Figure out how to log our messages
#
if [ -t 1 ]; then
    # Running from a tty...
    log() {
	echo "$PROGNAME: $@"
    }
elif [ -x /usr/bin/logger ]; then
    # Have logger...
    log() {
	logger -t "$PROGNAME" -- "$@"
    }
else
    # No logger...
    log() {
	echo "$PROGNAME: $@" >> /var/log/messages
    }
fi

#
#	Figure out the model number from the name of this script
#
case "$0" in
*1000)
    MODEL=1000
    USB1=0x03f0	#Vendor
    USB2=0x0517	#Model
    ;;
*1005)
    MODEL=1005
    USB1=0x03f0	#Vendor
    USB2=0x1317	#Model
    ;;
*)
    log "Only HP LaserJet 1000 and 1005 are supported"
    exit
    ;;
esac

#
#	The special command line argument "install-usermap" will install
#	the proper entry into the /etc/hotplug/usb.usermap file
#
case "$1" in
install-usermap)
    if [ "$USB2" != "" ]; then
	ed - /etc/hotplug/usb.usermap <<-EOF
	g/^hplj$MODEL/d
	\$a
	hplj$MODEL 0x0003 $USB1 $USB2 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
	.
	w
	q
	EOF
    else
	log "I don't know the USB info for this model yet.  Please run"
	log "usb_printerid on the usb device and send the output to:"
	log "rickr@mn.rr.com"
    fi
    exit
    ;;
esac
 
#
#	Procedure to load a single device with firmware
#
load1() {
    _dev="$1"
    fw="$FWDIR/sihp$MODEL.dl"
    if [ ! -f "$fw" ]; then
	log "Missing HP LaserJet $MODEL firmware file $fw"
	log "...read foo2zjs installation instructions and run ./getweb $MODEL"
	return 1
    fi

    log "loading HP LaserJet $MODEL firmware $fw to $_dev ..."
    if cat $fw > $_dev; then
	log "... download successful."
    else
	log "... download failed."
    fi
    return 0
}

#
#	OK, now download firmware to any printers that need it
#
if [ "$DEV" != "" ]; then
    #
    # force downloading to a specific device
    #
    load1 "$DEV"
elif [ -x $USBID ]; then
    #
    # Sniff around for printers that need a firmware download
    #
    usblps=`find /dev/usb -name lp*`" "`find /dev -name usblp*`
    for dev in $usblps; do
	status=`$USBID $dev 2>/dev/null | grep "hp LaserJet $MODEL"`
	if [ "$status" != "" ]; then
	    # This is a LaserJet 100x
	    status=`$USBID $dev | grep 'FWVER'`
	    if [ "$status" = "" ]; then
		# Firmware is not yet loaded
		load1 "$dev"
	    else
		log "HP LaserJet $MODEL firmware already loaded into $dev"
	    fi
	fi
    done
else
    log "HP LaserJet $MODEL firmware was not downloaded..."
    log "...couldn't find /usr/bin/usb_printerid and DEV is not set"
fi