Printer Setup: Difference between revisions

From Alpine Linux
(Listed 'hp-setup' as another package not currently supplied; amended styles; python3.4 is not packaged in supported versions - amended to python3; added Todo; added Desktop Environments and See also sections.)
m (explicitly mention eudev for udevadm)
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
First, you'll need CUPS. If you have a Hewlett-Packard printer (HP brand), add the HPLIP package.
First, you'll need [https://en.wikipedia.org/wiki/CUPS CUPS]. If you have a ''Hewlett-Packard'' printer (''HP'' brand), add the [https://en.wikipedia.org/wiki/HP_Linux_Imaging_and_Printing HPLIP] package.
{{cmd|# apk add cups cups-libs cups-pdf cups-client cups-filters hplip hplip-libs}}


Then go to http://localhost:631 with your web browser and follow the steps to "Add Printer". It'll ask you to log in to add a printer. Log in as root, then finish the steps. Once you're done, you should be able to print.
{{cmd|# apk add cups cups-libs cups-pdf cups-client cups-filters hplip}}
 
{{Tip|As with all installation processes, Alpine's [[Alpine_Linux_package_management|package management]] can guide you on the need to pull various packages from other repositories (e.g.''@testing'') other than the enabled ''main'' or ''edge'' repositories throughout this wiki page, as long as these other repos have been [https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management#Repository_pinning pinned].  For example, for Alpine version 3.7.0 on x86_64 systems, '''apk''' would have then guided you to substitute in <code>cups-pdf@testing</code> and <code>hplip@testing</code>.}}
 
Then go to http://localhost:631 with your web browser and follow the steps to "Add Printer". It will ask you to log in to add a printer. Log in as root, then finish the steps. Once you're done, you should be able to print.


If that doesn't work, you may also need to add HPLIP's dependencies separately. There are currently no packages for '''CUPS DDK''', <code>hp-setup</code> or <code>foomatic</code>.
If that doesn't work, you may also need to add HPLIP's dependencies separately. There are currently no packages for '''CUPS DDK''', <code>hp-setup</code> or <code>foomatic</code>.
Line 9: Line 12:


{{Expand|Modifications/sections required e.g. to address container user-case scenarios, etc.}}  
{{Expand|Modifications/sections required e.g. to address container user-case scenarios, etc.}}  
== mdev hacks for USB printers ==
By default USB printer with ''mdev'' would have ownership ''root:root'' and permission ''0660''. As ''cupsd'' would try to open a libusb-based printer as ''lp'' user, it won't have permission to use the device in ''/dev/bus/usb''.
First let's get some info about our USB printer.
# lsusb | grep Printer
Bus 002 Device 011: ID 04b8:0007 Seiko Epson Corp. Printer
Now use ''002'' and ''011'' for next query.
# apk add eudev
# udevadm info -p $(udevadm info -q path -n /dev/bus/usb/002/011)
P: /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1
N: bus/usb/002/011
E: BUSNUM=002
E: DEVNAME=/dev/bus/usb/002/011
E: DEVNUM=011
E: DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1
E: DEVTYPE=usb_device
E: DRIVER=usb
E: MAJOR=189
E: MINOR=138
E: PRODUCT=4b8/7/100
E: SUBSYSTEM=usb
E: TYPE=0/0/0
What is important for us is 'PRODUCT'.
# cat >> /etc/mdev.conf <<EOF
SUBSYSTEM=usb;PRODUCT=4b8/7/100;.* root:lp 660 */lib/mdev/usbdev
EOF
Unplug USB cable and plug again, now USB printer device in ''/dev/bus/usb/'' will have valid ownership and permissions.
# ls -l /dev/bus/usb/002/011
crw-rw---- 1 root lp 189, 138 Apr 14 21:19 /dev/bus/usb/002/011
CUPS will be able now to use libusb to discover local USB printer.


== Desktop Environment ==
== Desktop Environment ==
Additionally, in a desktop environment you could proceed as follows.
Additionally, in a desktop environment you could proceed as follows.


Check whether ''root'' and ''yourusername'' are already members of the <code>lp</code> and <code>lpadmin</code> groups:
Check whether ''root'' and the user's username (''yourusername'') are already members of the <code>lp</code> and <code>lpadmin</code> groups.  Note: ''yourusername'' can be added to the <code>lpadmin</code> group if he/she will administer the CUPS system.
  $ id root
  $ id root
  uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
  uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
  $ id yourusername
  $ id ''yourusername''
  uid=1000(yourusername) gid=1000(yourusername) groups=1000(yourusername),6(disk),10(wheel),18(audio),19(cdrom),20(dialout),27(video),100(users),1001(plugdev)
  uid=1000(yourusername) gid=1000(yourusername) groups=1000(yourusername),6(disk),10(wheel),18(audio),19(cdrom),20(dialout),27(video),100(users),1001(plugdev)


Line 22: Line 66:
  $ sudo adduser root lp
  $ sudo adduser root lp
  $ sudo adduser root lpadmin
  $ sudo adduser root lpadmin
  $ sudo adduser yourusername lp
  $ sudo adduser ''yourusername'' lp
  $ sudo adduser yourusername lpadmin
  $ sudo adduser ''yourusername'' lpadmin


Start and add cupsd service:
Start CUPS ('''cupsd''') and make it persist between boots;  then reboot:
  $ sudo rc-service cupsd start
  $ sudo rc-service cupsd start
  $ sudo rc-update add cupsd
  $ sudo rc-update add cupsd
$ sudo reboot


Credit to ArchWiki's excellent [https://wiki.archlinux.org/index.php/CUPS CUPS] page for guidance with the following basic steps.
Credit to ArchWiki's excellent [https://wiki.archlinux.org/index.php/CUPS CUPS] page for guidance with the following basic steps.
''' Locate your printer '''
With your printer connected and powered on, determine the ''URI'' for your printer.  Depending on whether the connection is via '''usb''' or '''parallel''' ports, the URI will carry a <code>usb://</code> or <code>parallel:/</code> prefix.


With your printer connected and powered on, determine the '''URI''' for your printer.  Depending on whether the connection is via '''usb''' or '''parallel''' ports, the URI will carry a <code>usb://</code> or <code>parallel:/</code> prefix.
  $ lpinfo -v #
  $ lpinfo -v #
  network lpd
  network lpd
Line 47: Line 93:
In the example above, the URI is <code>usb://HP/LaserJet%202200</code>
In the example above, the URI is <code>usb://HP/LaserJet%202200</code>


Now find a .ppd or .ppd.gz '''driver''' for your printer.  You could list all the drivers available by running <code>lpinfo -m</code> and then searching through the results to find a .ppd or .ppd.gz specific to your printer.  A quick solution is to use the <code>--make-and-model</code> flag and the <code>grep</code> function in order to filter the results by plugging in your printer's make, model and model number in this fashion:
''' Find a .ppd or .ppd.gz ''driver''. '''
 
If your printer supports ''IPP Everywhere'' --most recent models do-- see the ''driverless'' command in ''cups-filters'':


  $ lpinfo lpinfo --make-and-model "make_model_names" -m | grep -i printer_model_number
  $ driverless ipp_uri > printer.ppd


=== Tips ===
or just pass ''-m everywhere'' to ''lpadmin''.}}
* Search for the term ''HP'' to find instances of ''Hewlett-Packard''.
 
* You do not need to state the <code>printer_model_number</code> in whole if at all e.g. ''2200'' may be preferable to searching for ''2200M'', etc.}}
Otherwise, you could list all the drivers available by running <code>lpinfo -m</code> and then searching through the results to find a .ppd or .ppd.gz specific to your printer.  A quick solution is to use the <code>--make-and-model</code> flag and the <code>grep</code> function in order to filter the results by plugging in your printer's make, model and series in this fashion:
 
$ lpinfo --make-and-model "''make_and_model_names''" -m | grep -i ''printer_series''
 
{{Tip|
*Search for the term ''HP'' to find instances of ''Hewlett-Packard''.
*You do not need to state the <code>printer_series</code> in whole if at all e.g. ''2200'' may be preferable to searching for ''2200M'', etc.}}


For example, type:
For example, type:
Line 59: Line 113:
  $ lpinfo --make-and-model "HP LaserJet" -m | grep -i 2200
  $ lpinfo --make-and-model "HP LaserJet" -m | grep -i 2200


Out of the results obtained, you might select the following .ppd '''driver''':  
Out of the results obtained, you might select the following .ppd ''driver'':
  drv:///hp/hpcups.drv/hp-laserjet_2200_series.ppd
  drv:///hp/hpcups.drv/hp-laserjet_2200_series.ppd


Line 66: Line 120:
  $ sudo apk add gutenprint gutenprint-doc
  $ sudo apk add gutenprint gutenprint-doc


Create a queue using a '''queue_name''' of your choice.  Your selected printer's name is an obvious choice, but do not employ spaces.  You will also need to be root or use <code>sudo</code> instead, and you will also need to plug in the '''URI''' and the .ppd '''driver''':
''' Configure a queue '''
 
Create a queue using a ''queue_name'' of your choice.  Your selected printer's name is an obvious choice, but do not employ spaces.  You will also need to be root or use <code>sudo</code> instead, and you will also need to plug in the ''URI'' and the .ppd ''driver'':


  # lpadmin -p queue_name -E -v "uri" -m driver
  # lpadmin -p ''queue_name'' -E -v "''uri''" -m ''driver''


With this example, you could set as follows, but there are other solutions.
With this example, you could set as follows, but there are other solutions.
Line 78: Line 134:
  # lpoptions -d HP_LaserJet_2200
  # lpoptions -d HP_LaserJet_2200


Printer settings can typically be set in your GUI application's ''Print'' menu or by examining the CUPS [https://www.cups.org/doc/man-lpoptions.html lpoptions] page.  If you have a single queue, the setting options available (such as page type, duplex, etc.) for your queue can simply be '''listed''' by using the '''-l''' flag.  Asterisks(*) indicate current settings:
Printer settings can typically be set in your GUI application's '''Print''' menu or by examining the CUPS [https://www.cups.org/doc/man-lpoptions.html lpoptions] page.  If you have a single queue, the setting options available (such as page type, duplex, etc.) for your queue can simply be '''listed''' by using the '''-l''' flag.  Asterisks(*) indicate current settings:


  # lpoptions -l
  # lpoptions -l

Revision as of 21:51, 14 April 2020

First, you'll need CUPS. If you have a Hewlett-Packard printer (HP brand), add the HPLIP package.

# apk add cups cups-libs cups-pdf cups-client cups-filters hplip

Tip: As with all installation processes, Alpine's package management can guide you on the need to pull various packages from other repositories (e.g.@testing) other than the enabled main or edge repositories throughout this wiki page, as long as these other repos have been pinned. For example, for Alpine version 3.7.0 on x86_64 systems, apk would have then guided you to substitute in cups-pdf@testing and hplip@testing.

Then go to http://localhost:631 with your web browser and follow the steps to "Add Printer". It will ask you to log in to add a printer. Log in as root, then finish the steps. Once you're done, you should be able to print.

If that doesn't work, you may also need to add HPLIP's dependencies separately. There are currently no packages for CUPS DDK, hp-setup or foomatic.

# apk add libusb ghostscript qt py-qt python3 py-reportlab libjpeg libjpeg-turbo net-snmp


This material needs expanding ...

Modifications/sections required e.g. to address container user-case scenarios, etc.

mdev hacks for USB printers

By default USB printer with mdev would have ownership root:root and permission 0660. As cupsd would try to open a libusb-based printer as lp user, it won't have permission to use the device in /dev/bus/usb.

First let's get some info about our USB printer.

# lsusb | grep Printer
Bus 002 Device 011: ID 04b8:0007 Seiko Epson Corp. Printer

Now use 002 and 011 for next query.

# apk add eudev
# udevadm info -p $(udevadm info -q path -n /dev/bus/usb/002/011)
P: /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1
N: bus/usb/002/011
E: BUSNUM=002
E: DEVNAME=/dev/bus/usb/002/011
E: DEVNUM=011
E: DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1
E: DEVTYPE=usb_device
E: DRIVER=usb
E: MAJOR=189
E: MINOR=138
E: PRODUCT=4b8/7/100
E: SUBSYSTEM=usb
E: TYPE=0/0/0

What is important for us is 'PRODUCT'.

# cat >> /etc/mdev.conf <<EOF
SUBSYSTEM=usb;PRODUCT=4b8/7/100;.* root:lp 660 */lib/mdev/usbdev
EOF

Unplug USB cable and plug again, now USB printer device in /dev/bus/usb/ will have valid ownership and permissions.

# ls -l /dev/bus/usb/002/011
crw-rw---- 1 root lp 189, 138 Apr 14 21:19 /dev/bus/usb/002/011

CUPS will be able now to use libusb to discover local USB printer.


Desktop Environment

Additionally, in a desktop environment you could proceed as follows.

Check whether root and the user's username (yourusername) are already members of the lp and lpadmin groups. Note: yourusername can be added to the lpadmin group if he/she will administer the CUPS system.

$ id root
uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
$ id yourusername
uid=1000(yourusername) gid=1000(yourusername) groups=1000(yourusername),6(disk),10(wheel),18(audio),19(cdrom),20(dialout),27(video),100(users),1001(plugdev)

If not, add them:

$ sudo adduser root lp
$ sudo adduser root lpadmin
$ sudo adduser yourusername lp
$ sudo adduser yourusername lpadmin

Start CUPS (cupsd) and make it persist between boots; then reboot:

$ sudo rc-service cupsd start
$ sudo rc-update add cupsd
$ sudo reboot

Credit to ArchWiki's excellent CUPS page for guidance with the following basic steps. Locate your printer

With your printer connected and powered on, determine the URI for your printer. Depending on whether the connection is via usb or parallel ports, the URI will carry a usb:// or parallel:/ prefix.

$ lpinfo -v #
network lpd
network socket
network beh
file cups-brf:/
direct usb://HP/LaserJet%202200
network ipp
network ipps
network https
network http
direct hp

In the example above, the URI is usb://HP/LaserJet%202200

Find a .ppd or .ppd.gz driver.

If your printer supports IPP Everywhere --most recent models do-- see the driverless command in cups-filters:

$ driverless ipp_uri > printer.ppd

or just pass -m everywhere to lpadmin.}}

Otherwise, you could list all the drivers available by running lpinfo -m and then searching through the results to find a .ppd or .ppd.gz specific to your printer. A quick solution is to use the --make-and-model flag and the grep function in order to filter the results by plugging in your printer's make, model and series in this fashion:

$ lpinfo --make-and-model "make_and_model_names" -m | grep -i printer_series
Tip:
  • Search for the term HP to find instances of Hewlett-Packard.
  • You do not need to state the printer_series in whole if at all e.g. 2200 may be preferable to searching for 2200M, etc.

For example, type:

$ lpinfo --make-and-model "HP LaserJet" -m | grep -i 2200

Out of the results obtained, you might select the following .ppd driver:

drv:///hp/hpcups.drv/hp-laserjet_2200_series.ppd

If required, further drivers can be obtained by installing gutenprint, and running the lpinfo search again. These may not specify .ppd names.

$ sudo apk add gutenprint gutenprint-doc

Configure a queue

Create a queue using a queue_name of your choice. Your selected printer's name is an obvious choice, but do not employ spaces. You will also need to be root or use sudo instead, and you will also need to plug in the URI and the .ppd driver:

# lpadmin -p queue_name -E -v "uri" -m driver

With this example, you could set as follows, but there are other solutions.

# lpadmin -p HP_LaserJet_2200 -E -v "usb://HP/LaserJet%202200" -m drv:///hp/hpcups.drv/hp-laserjet_2200-pcl3.ppd

This printer queue could be set as default:

# lpoptions -d HP_LaserJet_2200

Printer settings can typically be set in your GUI application's Print menu or by examining the CUPS lpoptions page. If you have a single queue, the setting options available (such as page type, duplex, etc.) for your queue can simply be listed by using the -l flag. Asterisks(*) indicate current settings:

# lpoptions -l
PageSize/Media Size: Card3x5 Hagaki Photo4x6 A6 Photo5x7 Card5x8 Oufuku A5 B5 JB5 Executive 16k Letter *A4 ExecutiveJIS FLSA Legal EnvA2 EnvC6 EnvChou4 EnvMonarch EnvDL Env10 EnvChou3 EnvC5 EnvB5 Custom.WIDTHxHEIGHT
Duplex/Double-Sided Printing: DuplexNoTumble DuplexTumble *None
InputSlot/Media Source: *Auto PhotoTray Upper Lower Envelope LargeCapacity Manual MPTray
ColorModel/Output Mode: *Gray
MediaType/Media Type: *Plain
OutputMode/Print Quality: *Normal Draft Best
OptionDuplex/Duplexer Installed: *False True

If there is only one queue, options can be set by simply using -o flags for each setting:

# lpoptions -o PageSize=Legal -o Duplex=DuplexNoTumble

See also