Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for printer / cups sharing #73

Closed
sandrokeil opened this issue Sep 1, 2018 · 7 comments
Closed

Support for printer / cups sharing #73

sandrokeil opened this issue Sep 1, 2018 · 7 comments

Comments

@sandrokeil
Copy link
Contributor

Would be nice if there is a flag to share the printer from host system. I've tried it by sharing of USB device but I guess the printer must be installed in Docker container. Do you have any idea if it is possible to share some directories/services like GPU/audio to be able to print documents e.g. from a Libre Office Docker container?

To determine the USB device (e.g. 04a9:10a5) you have to find out the printer id with lsusb (Arch Linux), then you can use this script to get all related devices. I guess hidraw is not needed for printer, but for other USB devices.

#!/usr/bin/env bash
USB_ID='04a9:10a5'
USB_NAME='Canon'
 
if lsusb -d $USB_ID > /dev/null; then
  BUS=$(lsusb -d $USB_ID | cut -d' ' -f 2)
  DEVICE=$(lsusb -d $USB_ID | cut -d' ' -f 4 | tr -d ':')
  DOCKER_DEVICE="--device=/dev/bus/usb/$BUS/$DEVICE "

  while read line _; do
    if cat /sys/class/hidraw/$(basename $line)/device/uevent | grep "${USB_NAME}" > /dev/null; then
      DOCKER_DEVICE="${DOCKER_DEVICE} --device=$line"
    fi
  done <<< "$(ls /dev/hidraw*)"
fi

echo $DOCKER_DEVICE

Maybe this script can be simplified too.

@mviereck
Copy link
Owner

mviereck commented Sep 1, 2018

An interesting idea to share printers with containers.

I assume it will be better to use cups server on host instead of sharing the hardware. Printers can be connected on several different ways to host. Printers on USB are only one case.
cups on host will already be configured for existing printers on USB, parallel port, WLAN or LAN. Also it provides a virtual PDF printer.

I am not familar with cups, but on a first glance it should be possible to access cups on host over network/IP. The container would only need package cups-client (debian) and x11docker could generate and share a config file. (Similar to pulseaudio over TCP setup).

I will look at this, and maybe you can also find out possibilities to use cups. Is cups the default printer server on arch?

@sandrokeil
Copy link
Contributor Author

Is cups the default printer server on arch?

I think so, see Arch Wiki CUPS. Yes, sharing via cups server should be easier than via USB/device. I've configured cups and printer on my host system. I've used cups and system-config-printer package. The Arch Wiki describes also how to use avahi or remote cups server.

@mviereck
Copy link
Owner

mviereck commented Sep 1, 2018

I did a first try sharing cups socket with --sharedir /run/cups/cups.sock. At least the virtual PDF printer was already visible, and also my (currently not connected) HP laser printer. /run/cups contains some more files, but maybe all we have to do is sharing that socket.

A bit confusing:
man lpstat says:

       -H   Shows the server hostname and port.

But it gives me:

$ lpstat -H
/run/cups/cups.sock

That is nice as it shows me which socket to share. But it also may point to a network server and a port that x11docker may have to provide. The manpage does not mention that lpstat -H can show a socket instead of hostname+port.

@sandrokeil
Copy link
Contributor Author

Confirmed 👍 using --sharedir /run/cups/cups.sock shows my not connected printer in libre office. Will try tomorrow to print a page ;-)

@mviereck
Copy link
Owner

mviereck commented Sep 2, 2018

I've added a new option --printer.
Sharing cups socket already works fine.
I still have to check for possible network setups.

$ lpstat -H
/run/cups/cups.sock
$ CUPS_SERVER=localhost lpstat -H
localhost:631
$ CUPS_SERVER=localhost x11docker --printer  # currently fails. IP is translated already.

@sandrokeil
Copy link
Contributor Author

Thanks a lot. Cups socket sharing works for me. 👍

@mviereck
Copy link
Owner

mviereck commented Sep 2, 2018

Sometimes it is easier than it seems. :-) I thought it would be much more complicated.

I also figured out how to configure cups to accept network connections. But I assume that will be a rare edge case. Though, it is supported, too.

@mviereck mviereck closed this as completed Sep 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants