I believe I have found a rather not very pretty solution. Instead of passing the device busid, you pass the entire bus it is on (e.g. if the printer is /002/012 and unplugging it turns it to /002/013, you can pass /dev/bus/usb/002 to the docker container in the Printer argument of the docker setup). However, for some reason unplugging the printer and plugging it back in does change the busid on the unraid host, but on the docker container you end up with the old busid (such as 012) which no longer exists, and the new one (013) does not get created. Here's where the jank comes in: I added a udev rule that runs a script that, similarly to the udev rule itself is copied from /boot/config on boot and is chmoded to 744 by the gofile. The udev rule is as follows:
SUBSYSTEM=="usb", ATTRS{idVendor}=="cafe", ATTRS{idProduct}=="f00b", ATTRS{serial}=="AAAA1234", ACTION=="add", RUN+="/usr/local/bin/printer.sh"
The printer.sh script is as follows:
#!/usr/bin/bash
#Copy LaserJet 1020 firmware to printer, replace lp0 with your own lp name, issue is that it might change on a reboot if you have multiple. If you have just one, you can specify lp* instead.
cat /boot/config/cups/sihp1020.dl > /dev/usb/lp0
#restart the cups docker container to pick up the new /dev/bus/usb/ entry
docker restart cups
then the /boot/config/go code for the above is as such:
cp /boot/config/rules.d/99-usb-rules.rules /etc/udev/rules.d/99-usb-rules.rules
cp /boot/config/cups/printer.sh /usr/local/bin/printer.sh
chmod 644 /etc/udev/rules.d/99-usb-rules.rules
chmod 744 /usr/local/bin/printer.sh
udevadm control --reload-rules
udevadm trigger --attr-match=subsystem=usb
(obviously make sure to copy the rule from /etc/udev/rules.d/99-usb-rules.rules to /boot/config/rules.d/ and /usr/local/bin/printer.sh to /boot/config/cups/, creating the required folders with mkdir, before restarting or they will be lost).
Now the firmware file (sihp1020.dl), or any other foo2zjs printer for that matter, is kind of a pain to get:
- Download the firmware sihp1020.img file (or whichever .img applies for your zjs printer) from https://github.com/koenkooi/foo2zjs (since the original foo2zjs servers are dead)
- Move the .img file to somewhere in your unraid machine host
- Copy the image to the cups container:
- Open a webterminal
- Copy the image to the cups container root as such:
docker cp /mnt/user/data/sihp1020.img cups:/
- Run the arm2hpdl utility provided by foo2zjs inside the cups container with:
docker exec cups arm2hpdl sihp1020.img > sihp1020.dl
You should now have a .dl firmware file in your unraid host (do ls and you you should see it)
- cp that to /boot/config/cups/sihp1020.dl so that it gets run by the script and is persistent across reboots.
Now, every time you plug in your printer or turn it on it should blink a couple times while the firmware is being copied. After that, you should be able to add it to cups. However, there are a few caveats with this process:
Due to the fact that the printer busid changes the printer.sh script restarts the cups container every time, effectively resetting it. However, all your cups configs inside /etc/cups will be safe since they are persistent, just a thing to note.
Again, if anyone has a less jank way of doing this, I am all ears.